You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2021/06/22 09:34:56 UTC
[GitHub] [tvm] tristan-arm opened a new pull request #8300: [ETHOSN] Add support for non-default ethos-n78 configurations
tristan-arm opened a new pull request #8300:
URL: https://github.com/apache/tvm/pull/8300
- Updated tvmc with new ethos-n78 composite target.
- Added additional n78 specific ethos-n configuration options.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] tristan-arm commented on pull request #8300: [ETHOSN] Add support for non-default ethos-n78 configurations
Posted by GitBox <gi...@apache.org>.
tristan-arm commented on pull request #8300:
URL: https://github.com/apache/tvm/pull/8300#issuecomment-865826020
cc @leandron @Leo-arm @u99127 @mbaret
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] Leo-arm commented on a change in pull request #8300: [ETHOSN] Add support for non-default ethos-n78 configurations
Posted by GitBox <gi...@apache.org>.
Leo-arm commented on a change in pull request #8300:
URL: https://github.com/apache/tvm/pull/8300#discussion_r683282927
##########
File path: python/tvm/relay/op/contrib/ethosn.py
##########
@@ -61,6 +61,53 @@ def partition_for_ethosn(mod, params=None, **opts):
-------
ret : annotated and partitioned module.
"""
+ if opts:
+ tops = opts.get("tops", None)
+ ple_ratio = opts.get("ple_ratio", None)
+ sram_size = opts.get("sram_size", None)
+ if tops or ple_ratio or sram_size:
+ raise ValueError(
+ "Setting tops, ple_ratio or sram_size has no effect when targeting Ethos-N77"
+ )
+
+ if params:
+ mod["main"] = bind_params_by_name(mod["main"], params)
+
+ seq = tvm.transform.Sequential(
+ [
+ transform.InferType(),
+ transform.MergeComposite(pattern_table()),
+ transform.AnnotateTarget("ethos-n"),
+ transform.MergeCompilerRegions(),
+ transform.PartitionGraph(),
+ ]
+ )
+
+ return seq(mod), None
+
+
+def partition_for_ethosn78(mod, params=None, **opts):
+ """Partition the graph greedily offloading supported
+ operators to Arm Ethos-N NPU.
+
+ Parameters
+ ----------
+ mod : Module
+ The module to run passes on.
+ params : Optional[Dict[str, NDArray]]
+ Constant input parameters.
+
+ Returns
+ -------
+ ret : annotated and partitioned module.
Review comment:
And a config
##########
File path: tests/python/contrib/test_ethosn/test_partition_params.py
##########
@@ -0,0 +1,104 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Ethos-N partition parameter tests"""
+
Review comment:
Missing file comment
##########
File path: tests/python/driver/tvmc/test_compiler.py
##########
@@ -308,6 +308,26 @@ def test_compile_tflite_module_with_external_codegen(tflite_mobilenet_v1_1_quant
assert os.path.exists(dumps_path)
+@pytest.mark.skipif(
+ not ethosn_available(),
+ reason="--target=ethos-n78 is not available. TVM built with 'USE_ETHOSN OFF'",
+)
+def test_compile_tflite_module_with_external_codegen_ethos_n78(tflite_mobilenet_v1_1_quant):
+ pytest.importorskip("tflite")
+ tvmc_model = tvmc.load(tflite_mobilenet_v1_1_quant)
+ tvmc_package = tvmc.compile(
+ tvmc_model, target="ethos-n78 -variant=Ethos-N78, llvm", dump_code="relay"
Review comment:
Is the double spec not what we wanted to avoid?
##########
File path: tests/python/driver/tvmc/test_tvmc_common.py
##########
@@ -241,6 +241,11 @@ def test_target_two_tvm_targets():
assert 0 == len(extra_targets)
+def test_target_from_cli__error_no_tvm_target_ethos_n78():
+ with pytest.raises(TVMCException):
+ _ = tvmc.common.target_from_cli("ethos-n78")
Review comment:
Why is this not valid? This would get the default config, I would have thought.
##########
File path: tests/python/contrib/test_ethosn/test_partition_params.py
##########
@@ -0,0 +1,104 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Ethos-N partition parameter tests"""
+
+import pytest
+import tvm
+from tvm import relay
+import numpy as np
+
+from tvm.relay.op.contrib.ethosn import partition_for_ethosn77
+from tvm.relay.op.contrib.ethosn import partition_for_ethosn78
+
+fp32 = "float32"
Review comment:
This looks strange. If the tests pass when offloading float32, then I would submit that the tests are broken because we only offload uint8. Am I missing something?
##########
File path: tests/cpp/ethosn_test.cc
##########
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
Review comment:
Missing file comment.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] tristan-arm closed pull request #8300: [ETHOSN] Add support for non-default ethos-n78 configurations
Posted by GitBox <gi...@apache.org>.
tristan-arm closed pull request #8300:
URL: https://github.com/apache/tvm/pull/8300
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] tristan-arm commented on a change in pull request #8300: [ETHOSN] Add support for non-default ethos-n78 configurations
Posted by GitBox <gi...@apache.org>.
tristan-arm commented on a change in pull request #8300:
URL: https://github.com/apache/tvm/pull/8300#discussion_r691188594
##########
File path: tests/python/contrib/test_ethosn/test_partition_params.py
##########
@@ -0,0 +1,104 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Ethos-N partition parameter tests"""
+
+import pytest
+import tvm
+from tvm import relay
+import numpy as np
+
+from tvm.relay.op.contrib.ethosn import partition_for_ethosn77
+from tvm.relay.op.contrib.ethosn import partition_for_ethosn78
+
+fp32 = "float32"
+
+
+def test_ethosn78_partition_no_error():
+ a = relay.var("a", shape=[2, 7, 8, 8], dtype=fp32)
+ w = relay.const(np.random.uniform(-10, 10, (8, 7, 3, 3)).astype(fp32))
+ res = relay.nn.conv2d(a, w, kernel_size=(3, 3), padding=(1, 1), channels=8, out_dtype=fp32)
+ b = relay.var("b", shape=[8], dtype=fp32)
+ res = relay.nn.bias_add(res, b, axis=1)
+
+ mod = tvm.IRModule.from_expr(res)
Review comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] tristan-arm commented on a change in pull request #8300: [ETHOSN] Add support for non-default ethos-n78 configurations
Posted by GitBox <gi...@apache.org>.
tristan-arm commented on a change in pull request #8300:
URL: https://github.com/apache/tvm/pull/8300#discussion_r691187911
##########
File path: python/tvm/relay/op/contrib/ethosn.py
##########
@@ -61,6 +61,53 @@ def partition_for_ethosn(mod, params=None, **opts):
-------
ret : annotated and partitioned module.
"""
+ if opts:
+ tops = opts.get("tops", None)
+ ple_ratio = opts.get("ple_ratio", None)
+ sram_size = opts.get("sram_size", None)
+ if tops or ple_ratio or sram_size:
+ raise ValueError(
+ "Setting tops, ple_ratio or sram_size has no effect when targeting Ethos-N77"
+ )
+
+ if params:
+ mod["main"] = bind_params_by_name(mod["main"], params)
+
+ seq = tvm.transform.Sequential(
+ [
+ transform.InferType(),
+ transform.MergeComposite(pattern_table()),
+ transform.AnnotateTarget("ethos-n"),
+ transform.MergeCompilerRegions(),
+ transform.PartitionGraph(),
+ ]
+ )
+
+ return seq(mod), None
+
+
+def partition_for_ethosn78(mod, params=None, **opts):
+ """Partition the graph greedily offloading supported
+ operators to Arm Ethos-N NPU.
+
+ Parameters
+ ----------
+ mod : Module
+ The module to run passes on.
+ params : Optional[Dict[str, NDArray]]
+ Constant input parameters.
+
+ Returns
+ -------
+ ret : annotated and partitioned module.
+ """
+ config = opts
Review comment:
Fixed now.
##########
File path: python/tvm/driver/tvmc/composite_target.py
##########
@@ -23,7 +23,8 @@
import tvm.contrib.target.vitis_ai # pylint: disable=unused-import
from tvm.relay.op.contrib.arm_compute_lib import partition_for_arm_compute_lib
-from tvm.relay.op.contrib.ethosn import partition_for_ethosn
+from tvm.relay.op.contrib.ethosn import partition_for_ethosn77
+from tvm.relay.op.contrib.ethosn import partition_for_ethosn78
Review comment:
Fixed now.
##########
File path: src/relay/backend/contrib/ethosn/ethosn_utils.h
##########
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * \file src/relay/backend/contrib/ethosn/ethosn_utils.h
+ * \brief Ethos-N utility functions.
+ */
+
+#ifndef TVM_RELAY_BACKEND_CONTRIB_ETHOSN_ETHOSN_UTILS_H_
+#define TVM_RELAY_BACKEND_CONTRIB_ETHOSN_ETHOSN_UTILS_H_
Review comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] tristan-arm commented on a change in pull request #8300: [ETHOSN] Add support for non-default ethos-n78 configurations
Posted by GitBox <gi...@apache.org>.
tristan-arm commented on a change in pull request #8300:
URL: https://github.com/apache/tvm/pull/8300#discussion_r691192470
##########
File path: tests/python/contrib/test_ethosn/test_partition_params.py
##########
@@ -0,0 +1,104 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Ethos-N partition parameter tests"""
+
+import pytest
+import tvm
+from tvm import relay
+import numpy as np
+
+from tvm.relay.op.contrib.ethosn import partition_for_ethosn77
+from tvm.relay.op.contrib.ethosn import partition_for_ethosn78
+
+fp32 = "float32"
Review comment:
Removed now.
##########
File path: python/tvm/relay/op/contrib/arm_compute_lib.py
##########
@@ -69,7 +69,7 @@ def partition_for_arm_compute_lib(mod, params=None, **opts):
]
)
- return seq(mod)
+ return seq(mod), None
Review comment:
Done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] Mousius commented on a change in pull request #8300: [ETHOSN] Add support for non-default ethos-n78 configurations
Posted by GitBox <gi...@apache.org>.
Mousius commented on a change in pull request #8300:
URL: https://github.com/apache/tvm/pull/8300#discussion_r683274348
##########
File path: python/tvm/relay/op/contrib/ethosn.py
##########
@@ -61,6 +61,53 @@ def partition_for_ethosn(mod, params=None, **opts):
-------
ret : annotated and partitioned module.
"""
+ if opts:
+ tops = opts.get("tops", None)
+ ple_ratio = opts.get("ple_ratio", None)
+ sram_size = opts.get("sram_size", None)
+ if tops or ple_ratio or sram_size:
+ raise ValueError(
+ "Setting tops, ple_ratio or sram_size has no effect when targeting Ethos-N77"
+ )
+
+ if params:
+ mod["main"] = bind_params_by_name(mod["main"], params)
+
+ seq = tvm.transform.Sequential(
+ [
+ transform.InferType(),
+ transform.MergeComposite(pattern_table()),
+ transform.AnnotateTarget("ethos-n"),
+ transform.MergeCompilerRegions(),
+ transform.PartitionGraph(),
+ ]
+ )
+
+ return seq(mod), None
+
+
+def partition_for_ethosn78(mod, params=None, **opts):
+ """Partition the graph greedily offloading supported
+ operators to Arm Ethos-N NPU.
+
+ Parameters
+ ----------
+ mod : Module
+ The module to run passes on.
+ params : Optional[Dict[str, NDArray]]
+ Constant input parameters.
+
+ Returns
+ -------
+ ret : annotated and partitioned module.
+ """
+ config = opts
Review comment:
`config = opts or {}`
##########
File path: python/tvm/driver/tvmc/composite_target.py
##########
@@ -23,7 +23,8 @@
import tvm.contrib.target.vitis_ai # pylint: disable=unused-import
from tvm.relay.op.contrib.arm_compute_lib import partition_for_arm_compute_lib
-from tvm.relay.op.contrib.ethosn import partition_for_ethosn
+from tvm.relay.op.contrib.ethosn import partition_for_ethosn77
+from tvm.relay.op.contrib.ethosn import partition_for_ethosn78
Review comment:
These can be combined into one import:
`from tvm.relay.op.contrib.ethosn import partition_for_ethosn77, partition_for_ethosn78`
##########
File path: python/tvm/relay/op/contrib/ethosn.py
##########
@@ -61,6 +61,53 @@ def partition_for_ethosn(mod, params=None, **opts):
-------
ret : annotated and partitioned module.
"""
+ if opts:
+ tops = opts.get("tops", None)
+ ple_ratio = opts.get("ple_ratio", None)
+ sram_size = opts.get("sram_size", None)
+ if tops or ple_ratio or sram_size:
+ raise ValueError(
+ "Setting tops, ple_ratio or sram_size has no effect when targeting Ethos-N77"
+ )
+
+ if params:
+ mod["main"] = bind_params_by_name(mod["main"], params)
+
+ seq = tvm.transform.Sequential(
+ [
+ transform.InferType(),
+ transform.MergeComposite(pattern_table()),
+ transform.AnnotateTarget("ethos-n"),
+ transform.MergeCompilerRegions(),
+ transform.PartitionGraph(),
+ ]
+ )
+
+ return seq(mod), None
+
+
+def partition_for_ethosn78(mod, params=None, **opts):
+ """Partition the graph greedily offloading supported
+ operators to Arm Ethos-N NPU.
+
+ Parameters
+ ----------
+ mod : Module
+ The module to run passes on.
+ params : Optional[Dict[str, NDArray]]
+ Constant input parameters.
+
+ Returns
+ -------
+ ret : annotated and partitioned module.
+ """
+ config = opts
+ if not config:
+ config = {}
+
+ if config.get("variant", "").lower() != "ethos-n78":
Review comment:
This can be simplified to just `config["variant"] = "Ethos-N78"`
##########
File path: tests/python/contrib/test_ethosn/test_partition_params.py
##########
@@ -0,0 +1,104 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Ethos-N partition parameter tests"""
+
+import pytest
+import tvm
+from tvm import relay
+import numpy as np
+
+from tvm.relay.op.contrib.ethosn import partition_for_ethosn77
+from tvm.relay.op.contrib.ethosn import partition_for_ethosn78
+
+fp32 = "float32"
+
+
+def test_ethosn78_partition_no_error():
+ a = relay.var("a", shape=[2, 7, 8, 8], dtype=fp32)
+ w = relay.const(np.random.uniform(-10, 10, (8, 7, 3, 3)).astype(fp32))
+ res = relay.nn.conv2d(a, w, kernel_size=(3, 3), padding=(1, 1), channels=8, out_dtype=fp32)
+ b = relay.var("b", shape=[8], dtype=fp32)
+ res = relay.nn.bias_add(res, b, axis=1)
+
+ mod = tvm.IRModule.from_expr(res)
Review comment:
This looks like the same module repeated in the various tests, it'd be worth wrapping this in a `pytest.fixture`, such as:
```
@pytest.fixture
def simple_mod():
a = relay.var("a", shape=[2, 7, 8, 8], dtype=fp32)
w = relay.const(np.random.uniform(-10, 10, (8, 7, 3, 3)).astype(fp32))
res = relay.nn.conv2d(a, w, kernel_size=(3, 3), padding=(1, 1), channels=8, out_dtype=fp32)
b = relay.var("b", shape=[8], dtype=fp32)
res = relay.nn.bias_add(res, b, axis=1)
return tvm.IRModule.from_expr(res)
def test_ethosn78_partition_no_error(simple_mod):
opts = {"variant": "Ethos-N78"}
partition_for_ethosn78(simple_mod, **opts)
```
##########
File path: src/relay/backend/contrib/ethosn/codegen_ethosn.h
##########
@@ -227,7 +227,9 @@ NetworkWithIDs ConstructNetwork(const IRModule& mod, const GlobalVar& var, const
/*! \brief Attributes to store the compiler options for Ethos-N */
struct EthosnCompilerConfigNode : public tvm::AttrsNode<EthosnCompilerConfigNode> {
String variant;
- int sram_size_bytes;
+ String sram_size;
Review comment:
Why can't these be numeric types?
##########
File path: src/relay/backend/contrib/ethosn/ethosn_utils.h
##########
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * \file src/relay/backend/contrib/ethosn/ethosn_utils.h
+ * \brief Ethos-N utility functions.
+ */
+
+#ifndef TVM_RELAY_BACKEND_CONTRIB_ETHOSN_ETHOSN_UTILS_H_
+#define TVM_RELAY_BACKEND_CONTRIB_ETHOSN_ETHOSN_UTILS_H_
Review comment:
As this file only includes variant specific logic, I'd suggest `ethosn_variant.h` instead
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] Mousius commented on a change in pull request #8300: [ETHOSN] Add support for non-default ethos-n78 configurations
Posted by GitBox <gi...@apache.org>.
Mousius commented on a change in pull request #8300:
URL: https://github.com/apache/tvm/pull/8300#discussion_r691257639
##########
File path: python/tvm/relay/op/contrib/arm_compute_lib.py
##########
@@ -69,7 +69,7 @@ def partition_for_arm_compute_lib(mod, params=None, **opts):
]
)
- return seq(mod)
+ return seq(mod), None
Review comment:
It appears TVM uses the Numpy-esque docstrings where multiple return values are documented as lists rather than a combined value https://github.com/apache/tvm/blob/main/python/tvm/relay/build_module.py#L140-L150, could you match this style?
##########
File path: src/relay/backend/contrib/ethosn/codegen_ethosn.h
##########
@@ -227,7 +227,9 @@ NetworkWithIDs ConstructNetwork(const IRModule& mod, const GlobalVar& var, const
/*! \brief Attributes to store the compiler options for Ethos-N */
struct EthosnCompilerConfigNode : public tvm::AttrsNode<EthosnCompilerConfigNode> {
String variant;
- int sram_size_bytes;
+ String sram_size;
Review comment:
It'd be better to have these typed correctly as they're passed in and then recast to string at the boundary with the driver stack.
##########
File path: python/tvm/relay/op/contrib/ethosn.py
##########
@@ -61,6 +61,53 @@ def partition_for_ethosn(mod, params=None, **opts):
-------
ret : annotated and partitioned module.
"""
+ if opts:
+ tops = opts.get("tops", None)
+ ple_ratio = opts.get("ple_ratio", None)
+ sram_size = opts.get("sram_size", None)
+ if tops or ple_ratio or sram_size:
+ raise ValueError(
+ "Setting tops, ple_ratio or sram_size has no effect when targeting Ethos-N77"
+ )
+
+ if params:
+ mod["main"] = bind_params_by_name(mod["main"], params)
+
+ seq = tvm.transform.Sequential(
+ [
+ transform.InferType(),
+ transform.MergeComposite(pattern_table()),
+ transform.AnnotateTarget("ethos-n"),
+ transform.MergeCompilerRegions(),
+ transform.PartitionGraph(),
+ ]
+ )
+
+ return seq(mod), None
+
+
+def partition_for_ethosn78(mod, params=None, **opts):
+ """Partition the graph greedily offloading supported
+ operators to Arm Ethos-N NPU.
+
+ Parameters
+ ----------
+ mod : Module
+ The module to run passes on.
+ params : Optional[Dict[str, NDArray]]
+ Constant input parameters.
+
+ Returns
+ -------
+ ret : annotated and partitioned module.
Review comment:
I don't think this docstring got updated?
##########
File path: python/tvm/relay/op/contrib/ethosn.py
##########
@@ -61,6 +61,53 @@ def partition_for_ethosn(mod, params=None, **opts):
-------
ret : annotated and partitioned module.
"""
+ if opts:
+ tops = opts.get("tops", None)
+ ple_ratio = opts.get("ple_ratio", None)
+ sram_size = opts.get("sram_size", None)
+ if tops or ple_ratio or sram_size:
+ raise ValueError(
+ "Setting tops, ple_ratio or sram_size has no effect when targeting Ethos-N77"
+ )
+
+ if params:
+ mod["main"] = bind_params_by_name(mod["main"], params)
+
+ seq = tvm.transform.Sequential(
+ [
+ transform.InferType(),
+ transform.MergeComposite(pattern_table()),
+ transform.AnnotateTarget("ethos-n"),
+ transform.MergeCompilerRegions(),
+ transform.PartitionGraph(),
+ ]
+ )
+
+ return seq(mod), None
+
+
+def partition_for_ethosn78(mod, params=None, **opts):
+ """Partition the graph greedily offloading supported
+ operators to Arm Ethos-N NPU.
+
+ Parameters
+ ----------
+ mod : Module
+ The module to run passes on.
+ params : Optional[Dict[str, NDArray]]
+ Constant input parameters.
+
+ Returns
+ -------
+ ret : annotated and partitioned module.
+ """
+ config = opts
+ if not config:
+ config = {}
+
+ if config.get("variant", "").lower() != "ethos-n78":
Review comment:
Apologies, I can clarify what I meant, if we take the scenarios in which this line of code is ran we'll have:
1. Variant isn't set
* Defaults to `""`
* `"" != "Ethos-N78"`
* Sets to `Ethos-N78`
2. Variant is set, but not to `Ethos-N78` (we'll use `woofles`)
* Gets value `"woofles"`
* `"woofles" != "Ethos-N78"`
* Sets to `Ethos-N78`
3. Variant is set, to `Ethos-N78`
* Remains as `Ethos-N78`
So I think in all cases it ends up set to `Ethos-N78`, casing appears to be irrelevant as the final value can be any casing if it lowers to `ethos-n78`. Let me know if I've missed anything here!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] Mousius commented on a change in pull request #8300: [ETHOSN] Add support for non-default ethos-n78 configurations
Posted by GitBox <gi...@apache.org>.
Mousius commented on a change in pull request #8300:
URL: https://github.com/apache/tvm/pull/8300#discussion_r691257639
##########
File path: python/tvm/relay/op/contrib/arm_compute_lib.py
##########
@@ -69,7 +69,7 @@ def partition_for_arm_compute_lib(mod, params=None, **opts):
]
)
- return seq(mod)
+ return seq(mod), None
Review comment:
It appears TVM uses the Numpy-esque docstrings where multiple return values are documented as lists rather than a combined value https://github.com/apache/tvm/blob/main/python/tvm/relay/build_module.py#L140-L150, could you match this style?
##########
File path: src/relay/backend/contrib/ethosn/codegen_ethosn.h
##########
@@ -227,7 +227,9 @@ NetworkWithIDs ConstructNetwork(const IRModule& mod, const GlobalVar& var, const
/*! \brief Attributes to store the compiler options for Ethos-N */
struct EthosnCompilerConfigNode : public tvm::AttrsNode<EthosnCompilerConfigNode> {
String variant;
- int sram_size_bytes;
+ String sram_size;
Review comment:
It'd be better to have these typed correctly as they're passed in and then recast to string at the boundary with the driver stack.
##########
File path: python/tvm/relay/op/contrib/ethosn.py
##########
@@ -61,6 +61,53 @@ def partition_for_ethosn(mod, params=None, **opts):
-------
ret : annotated and partitioned module.
"""
+ if opts:
+ tops = opts.get("tops", None)
+ ple_ratio = opts.get("ple_ratio", None)
+ sram_size = opts.get("sram_size", None)
+ if tops or ple_ratio or sram_size:
+ raise ValueError(
+ "Setting tops, ple_ratio or sram_size has no effect when targeting Ethos-N77"
+ )
+
+ if params:
+ mod["main"] = bind_params_by_name(mod["main"], params)
+
+ seq = tvm.transform.Sequential(
+ [
+ transform.InferType(),
+ transform.MergeComposite(pattern_table()),
+ transform.AnnotateTarget("ethos-n"),
+ transform.MergeCompilerRegions(),
+ transform.PartitionGraph(),
+ ]
+ )
+
+ return seq(mod), None
+
+
+def partition_for_ethosn78(mod, params=None, **opts):
+ """Partition the graph greedily offloading supported
+ operators to Arm Ethos-N NPU.
+
+ Parameters
+ ----------
+ mod : Module
+ The module to run passes on.
+ params : Optional[Dict[str, NDArray]]
+ Constant input parameters.
+
+ Returns
+ -------
+ ret : annotated and partitioned module.
Review comment:
I don't think this docstring got updated?
##########
File path: python/tvm/relay/op/contrib/ethosn.py
##########
@@ -61,6 +61,53 @@ def partition_for_ethosn(mod, params=None, **opts):
-------
ret : annotated and partitioned module.
"""
+ if opts:
+ tops = opts.get("tops", None)
+ ple_ratio = opts.get("ple_ratio", None)
+ sram_size = opts.get("sram_size", None)
+ if tops or ple_ratio or sram_size:
+ raise ValueError(
+ "Setting tops, ple_ratio or sram_size has no effect when targeting Ethos-N77"
+ )
+
+ if params:
+ mod["main"] = bind_params_by_name(mod["main"], params)
+
+ seq = tvm.transform.Sequential(
+ [
+ transform.InferType(),
+ transform.MergeComposite(pattern_table()),
+ transform.AnnotateTarget("ethos-n"),
+ transform.MergeCompilerRegions(),
+ transform.PartitionGraph(),
+ ]
+ )
+
+ return seq(mod), None
+
+
+def partition_for_ethosn78(mod, params=None, **opts):
+ """Partition the graph greedily offloading supported
+ operators to Arm Ethos-N NPU.
+
+ Parameters
+ ----------
+ mod : Module
+ The module to run passes on.
+ params : Optional[Dict[str, NDArray]]
+ Constant input parameters.
+
+ Returns
+ -------
+ ret : annotated and partitioned module.
+ """
+ config = opts
+ if not config:
+ config = {}
+
+ if config.get("variant", "").lower() != "ethos-n78":
Review comment:
Apologies, I can clarify what I meant, if we take the scenarios in which this line of code is ran we'll have:
1. Variant isn't set
* Defaults to `""`
* `"" != "Ethos-N78"`
* Sets to `Ethos-N78`
2. Variant is set, but not to `Ethos-N78` (we'll use `woofles`)
* Gets value `"woofles"`
* `"woofles" != "Ethos-N78"`
* Sets to `Ethos-N78`
3. Variant is set, to `Ethos-N78`
* Remains as `Ethos-N78`
So I think in all cases it ends up set to `Ethos-N78`, casing appears to be irrelevant as the final value can be any casing if it lowers to `ethos-n78`. Let me know if I've missed anything here!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] tristan-arm commented on a change in pull request #8300: [ETHOSN] Add support for non-default ethos-n78 configurations
Posted by GitBox <gi...@apache.org>.
tristan-arm commented on a change in pull request #8300:
URL: https://github.com/apache/tvm/pull/8300#discussion_r691192221
##########
File path: tests/python/driver/tvmc/test_compiler.py
##########
@@ -308,6 +308,26 @@ def test_compile_tflite_module_with_external_codegen(tflite_mobilenet_v1_1_quant
assert os.path.exists(dumps_path)
+@pytest.mark.skipif(
+ not ethosn_available(),
+ reason="--target=ethos-n78 is not available. TVM built with 'USE_ETHOSN OFF'",
+)
+def test_compile_tflite_module_with_external_codegen_ethos_n78(tflite_mobilenet_v1_1_quant):
+ pytest.importorskip("tflite")
+ tvmc_model = tvmc.load(tflite_mobilenet_v1_1_quant)
+ tvmc_package = tvmc.compile(
+ tvmc_model, target="ethos-n78 -variant=Ethos-N78, llvm", dump_code="relay"
Review comment:
Fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] Mousius commented on a change in pull request #8300: [ETHOSN] Add support for non-default ethos-n78 configurations
Posted by GitBox <gi...@apache.org>.
Mousius commented on a change in pull request #8300:
URL: https://github.com/apache/tvm/pull/8300#discussion_r683274348
##########
File path: python/tvm/relay/op/contrib/ethosn.py
##########
@@ -61,6 +61,53 @@ def partition_for_ethosn(mod, params=None, **opts):
-------
ret : annotated and partitioned module.
"""
+ if opts:
+ tops = opts.get("tops", None)
+ ple_ratio = opts.get("ple_ratio", None)
+ sram_size = opts.get("sram_size", None)
+ if tops or ple_ratio or sram_size:
+ raise ValueError(
+ "Setting tops, ple_ratio or sram_size has no effect when targeting Ethos-N77"
+ )
+
+ if params:
+ mod["main"] = bind_params_by_name(mod["main"], params)
+
+ seq = tvm.transform.Sequential(
+ [
+ transform.InferType(),
+ transform.MergeComposite(pattern_table()),
+ transform.AnnotateTarget("ethos-n"),
+ transform.MergeCompilerRegions(),
+ transform.PartitionGraph(),
+ ]
+ )
+
+ return seq(mod), None
+
+
+def partition_for_ethosn78(mod, params=None, **opts):
+ """Partition the graph greedily offloading supported
+ operators to Arm Ethos-N NPU.
+
+ Parameters
+ ----------
+ mod : Module
+ The module to run passes on.
+ params : Optional[Dict[str, NDArray]]
+ Constant input parameters.
+
+ Returns
+ -------
+ ret : annotated and partitioned module.
+ """
+ config = opts
Review comment:
`config = opts or {}`
##########
File path: python/tvm/driver/tvmc/composite_target.py
##########
@@ -23,7 +23,8 @@
import tvm.contrib.target.vitis_ai # pylint: disable=unused-import
from tvm.relay.op.contrib.arm_compute_lib import partition_for_arm_compute_lib
-from tvm.relay.op.contrib.ethosn import partition_for_ethosn
+from tvm.relay.op.contrib.ethosn import partition_for_ethosn77
+from tvm.relay.op.contrib.ethosn import partition_for_ethosn78
Review comment:
These can be combined into one import:
`from tvm.relay.op.contrib.ethosn import partition_for_ethosn77, partition_for_ethosn78`
##########
File path: python/tvm/relay/op/contrib/ethosn.py
##########
@@ -61,6 +61,53 @@ def partition_for_ethosn(mod, params=None, **opts):
-------
ret : annotated and partitioned module.
"""
+ if opts:
+ tops = opts.get("tops", None)
+ ple_ratio = opts.get("ple_ratio", None)
+ sram_size = opts.get("sram_size", None)
+ if tops or ple_ratio or sram_size:
+ raise ValueError(
+ "Setting tops, ple_ratio or sram_size has no effect when targeting Ethos-N77"
+ )
+
+ if params:
+ mod["main"] = bind_params_by_name(mod["main"], params)
+
+ seq = tvm.transform.Sequential(
+ [
+ transform.InferType(),
+ transform.MergeComposite(pattern_table()),
+ transform.AnnotateTarget("ethos-n"),
+ transform.MergeCompilerRegions(),
+ transform.PartitionGraph(),
+ ]
+ )
+
+ return seq(mod), None
+
+
+def partition_for_ethosn78(mod, params=None, **opts):
+ """Partition the graph greedily offloading supported
+ operators to Arm Ethos-N NPU.
+
+ Parameters
+ ----------
+ mod : Module
+ The module to run passes on.
+ params : Optional[Dict[str, NDArray]]
+ Constant input parameters.
+
+ Returns
+ -------
+ ret : annotated and partitioned module.
+ """
+ config = opts
+ if not config:
+ config = {}
+
+ if config.get("variant", "").lower() != "ethos-n78":
Review comment:
This can be simplified to just `config["variant"] = "Ethos-N78"`
##########
File path: tests/python/contrib/test_ethosn/test_partition_params.py
##########
@@ -0,0 +1,104 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Ethos-N partition parameter tests"""
+
+import pytest
+import tvm
+from tvm import relay
+import numpy as np
+
+from tvm.relay.op.contrib.ethosn import partition_for_ethosn77
+from tvm.relay.op.contrib.ethosn import partition_for_ethosn78
+
+fp32 = "float32"
+
+
+def test_ethosn78_partition_no_error():
+ a = relay.var("a", shape=[2, 7, 8, 8], dtype=fp32)
+ w = relay.const(np.random.uniform(-10, 10, (8, 7, 3, 3)).astype(fp32))
+ res = relay.nn.conv2d(a, w, kernel_size=(3, 3), padding=(1, 1), channels=8, out_dtype=fp32)
+ b = relay.var("b", shape=[8], dtype=fp32)
+ res = relay.nn.bias_add(res, b, axis=1)
+
+ mod = tvm.IRModule.from_expr(res)
Review comment:
This looks like the same module repeated in the various tests, it'd be worth wrapping this in a `pytest.fixture`, such as:
```
@pytest.fixture
def simple_mod():
a = relay.var("a", shape=[2, 7, 8, 8], dtype=fp32)
w = relay.const(np.random.uniform(-10, 10, (8, 7, 3, 3)).astype(fp32))
res = relay.nn.conv2d(a, w, kernel_size=(3, 3), padding=(1, 1), channels=8, out_dtype=fp32)
b = relay.var("b", shape=[8], dtype=fp32)
res = relay.nn.bias_add(res, b, axis=1)
return tvm.IRModule.from_expr(res)
def test_ethosn78_partition_no_error(simple_mod):
opts = {"variant": "Ethos-N78"}
partition_for_ethosn78(simple_mod, **opts)
```
##########
File path: src/relay/backend/contrib/ethosn/codegen_ethosn.h
##########
@@ -227,7 +227,9 @@ NetworkWithIDs ConstructNetwork(const IRModule& mod, const GlobalVar& var, const
/*! \brief Attributes to store the compiler options for Ethos-N */
struct EthosnCompilerConfigNode : public tvm::AttrsNode<EthosnCompilerConfigNode> {
String variant;
- int sram_size_bytes;
+ String sram_size;
Review comment:
Why can't these be numeric types?
##########
File path: src/relay/backend/contrib/ethosn/ethosn_utils.h
##########
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * \file src/relay/backend/contrib/ethosn/ethosn_utils.h
+ * \brief Ethos-N utility functions.
+ */
+
+#ifndef TVM_RELAY_BACKEND_CONTRIB_ETHOSN_ETHOSN_UTILS_H_
+#define TVM_RELAY_BACKEND_CONTRIB_ETHOSN_ETHOSN_UTILS_H_
Review comment:
As this file only includes variant specific logic, I'd suggest `ethosn_variant.h` instead
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] tristan-arm commented on a change in pull request #8300: [ETHOSN] Add support for non-default ethos-n78 configurations
Posted by GitBox <gi...@apache.org>.
tristan-arm commented on a change in pull request #8300:
URL: https://github.com/apache/tvm/pull/8300#discussion_r691193919
##########
File path: tests/python/contrib/test_ethosn/test_partition_params.py
##########
@@ -0,0 +1,104 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Ethos-N partition parameter tests"""
Review comment:
I've added no code checking tops or ple_ratio, so those values are not checked here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] tristan-arm commented on a change in pull request #8300: [ETHOSN] Add support for non-default ethos-n78 configurations
Posted by GitBox <gi...@apache.org>.
tristan-arm commented on a change in pull request #8300:
URL: https://github.com/apache/tvm/pull/8300#discussion_r691191848
##########
File path: tests/python/contrib/test_ethosn/test_partition_params.py
##########
@@ -0,0 +1,104 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Ethos-N partition parameter tests"""
+
Review comment:
A file comment is not part of the structure here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] tristan-arm commented on a change in pull request #8300: [ETHOSN] Add support for non-default ethos-n78 configurations
Posted by GitBox <gi...@apache.org>.
tristan-arm commented on a change in pull request #8300:
URL: https://github.com/apache/tvm/pull/8300#discussion_r691187589
##########
File path: python/tvm/relay/op/contrib/ethosn.py
##########
@@ -61,6 +61,53 @@ def partition_for_ethosn(mod, params=None, **opts):
-------
ret : annotated and partitioned module.
"""
+ if opts:
+ tops = opts.get("tops", None)
+ ple_ratio = opts.get("ple_ratio", None)
+ sram_size = opts.get("sram_size", None)
+ if tops or ple_ratio or sram_size:
+ raise ValueError(
+ "Setting tops, ple_ratio or sram_size has no effect when targeting Ethos-N77"
+ )
+
+ if params:
+ mod["main"] = bind_params_by_name(mod["main"], params)
+
+ seq = tvm.transform.Sequential(
+ [
+ transform.InferType(),
+ transform.MergeComposite(pattern_table()),
+ transform.AnnotateTarget("ethos-n"),
+ transform.MergeCompilerRegions(),
+ transform.PartitionGraph(),
+ ]
+ )
+
+ return seq(mod), None
+
+
+def partition_for_ethosn78(mod, params=None, **opts):
+ """Partition the graph greedily offloading supported
+ operators to Arm Ethos-N NPU.
+
+ Parameters
+ ----------
+ mod : Module
+ The module to run passes on.
+ params : Optional[Dict[str, NDArray]]
+ Constant input parameters.
+
+ Returns
+ -------
+ ret : annotated and partitioned module.
+ """
+ config = opts
+ if not config:
+ config = {}
+
+ if config.get("variant", "").lower() != "ethos-n78":
Review comment:
I've used config.get("variant", "") here to handle the variant undefined scenario.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] Mousius commented on a change in pull request #8300: [ETHOSN] Add support for non-default ethos-n78 configurations
Posted by GitBox <gi...@apache.org>.
Mousius commented on a change in pull request #8300:
URL: https://github.com/apache/tvm/pull/8300#discussion_r683381094
##########
File path: tests/python/driver/tvmc/test_tvmc_common.py
##########
@@ -241,6 +241,11 @@ def test_target_two_tvm_targets():
assert 0 == len(extra_targets)
+def test_target_from_cli__error_no_tvm_target_ethos_n78():
+ with pytest.raises(TVMCException):
+ _ = tvmc.common.target_from_cli("ethos-n78")
Review comment:
I believe this is because there's no host target?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] leandron commented on a change in pull request #8300: [ETHOSN] Add support for non-default ethos-n78 configurations
Posted by GitBox <gi...@apache.org>.
leandron commented on a change in pull request #8300:
URL: https://github.com/apache/tvm/pull/8300#discussion_r683366227
##########
File path: python/tvm/relay/op/contrib/arm_compute_lib.py
##########
@@ -69,7 +69,7 @@ def partition_for_arm_compute_lib(mod, params=None, **opts):
]
)
- return seq(mod)
+ return seq(mod), None
Review comment:
With the new return type, please update the docstrings.
This applies to all `partition_for_*` functions.
##########
File path: tests/python/driver/tvmc/test_tvmc_common.py
##########
@@ -241,6 +241,11 @@ def test_target_two_tvm_targets():
assert 0 == len(extra_targets)
+def test_target_from_cli__error_no_tvm_target_ethos_n78():
+ with pytest.raises(TVMCException):
+ _ = tvmc.common.target_from_cli("ethos-n78")
Review comment:
It should fail because `ethos-n78` is not a standalone codegen. It still requires `c` or `llvm` to handle the CPU parts of the codegen.
##########
File path: tests/python/contrib/test_ethosn/test_partition_params.py
##########
@@ -0,0 +1,104 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Ethos-N partition parameter tests"""
Review comment:
It would be good to have tests also exercising parameters such as `tops` and `ple_ratio` when asking for an `ethos-n78` target, so that we can see which errors to expect from the underlying layers of the codegen.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] Leo-arm commented on a change in pull request #8300: [ETHOSN] Add support for non-default ethos-n78 configurations
Posted by GitBox <gi...@apache.org>.
Leo-arm commented on a change in pull request #8300:
URL: https://github.com/apache/tvm/pull/8300#discussion_r692071722
##########
File path: tests/python/contrib/test_ethosn/test_partition_params.py
##########
@@ -0,0 +1,104 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Ethos-N partition parameter tests"""
+
Review comment:
Ack
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] tristan-arm commented on a change in pull request #8300: [ETHOSN] Add support for non-default ethos-n78 configurations
Posted by GitBox <gi...@apache.org>.
tristan-arm commented on a change in pull request #8300:
URL: https://github.com/apache/tvm/pull/8300#discussion_r691187589
##########
File path: python/tvm/relay/op/contrib/ethosn.py
##########
@@ -61,6 +61,53 @@ def partition_for_ethosn(mod, params=None, **opts):
-------
ret : annotated and partitioned module.
"""
+ if opts:
+ tops = opts.get("tops", None)
+ ple_ratio = opts.get("ple_ratio", None)
+ sram_size = opts.get("sram_size", None)
+ if tops or ple_ratio or sram_size:
+ raise ValueError(
+ "Setting tops, ple_ratio or sram_size has no effect when targeting Ethos-N77"
+ )
+
+ if params:
+ mod["main"] = bind_params_by_name(mod["main"], params)
+
+ seq = tvm.transform.Sequential(
+ [
+ transform.InferType(),
+ transform.MergeComposite(pattern_table()),
+ transform.AnnotateTarget("ethos-n"),
+ transform.MergeCompilerRegions(),
+ transform.PartitionGraph(),
+ ]
+ )
+
+ return seq(mod), None
+
+
+def partition_for_ethosn78(mod, params=None, **opts):
+ """Partition the graph greedily offloading supported
+ operators to Arm Ethos-N NPU.
+
+ Parameters
+ ----------
+ mod : Module
+ The module to run passes on.
+ params : Optional[Dict[str, NDArray]]
+ Constant input parameters.
+
+ Returns
+ -------
+ ret : annotated and partitioned module.
+ """
+ config = opts
+ if not config:
+ config = {}
+
+ if config.get("variant", "").lower() != "ethos-n78":
Review comment:
I've used config.get("variant", "") here to handle the variant undefined scenario.
##########
File path: python/tvm/relay/op/contrib/ethosn.py
##########
@@ -61,6 +61,53 @@ def partition_for_ethosn(mod, params=None, **opts):
-------
ret : annotated and partitioned module.
"""
+ if opts:
+ tops = opts.get("tops", None)
+ ple_ratio = opts.get("ple_ratio", None)
+ sram_size = opts.get("sram_size", None)
+ if tops or ple_ratio or sram_size:
+ raise ValueError(
+ "Setting tops, ple_ratio or sram_size has no effect when targeting Ethos-N77"
+ )
+
+ if params:
+ mod["main"] = bind_params_by_name(mod["main"], params)
+
+ seq = tvm.transform.Sequential(
+ [
+ transform.InferType(),
+ transform.MergeComposite(pattern_table()),
+ transform.AnnotateTarget("ethos-n"),
+ transform.MergeCompilerRegions(),
+ transform.PartitionGraph(),
+ ]
+ )
+
+ return seq(mod), None
+
+
+def partition_for_ethosn78(mod, params=None, **opts):
+ """Partition the graph greedily offloading supported
+ operators to Arm Ethos-N NPU.
+
+ Parameters
+ ----------
+ mod : Module
+ The module to run passes on.
+ params : Optional[Dict[str, NDArray]]
+ Constant input parameters.
+
+ Returns
+ -------
+ ret : annotated and partitioned module.
+ """
+ config = opts
Review comment:
Fixed now.
##########
File path: python/tvm/driver/tvmc/composite_target.py
##########
@@ -23,7 +23,8 @@
import tvm.contrib.target.vitis_ai # pylint: disable=unused-import
from tvm.relay.op.contrib.arm_compute_lib import partition_for_arm_compute_lib
-from tvm.relay.op.contrib.ethosn import partition_for_ethosn
+from tvm.relay.op.contrib.ethosn import partition_for_ethosn77
+from tvm.relay.op.contrib.ethosn import partition_for_ethosn78
Review comment:
Fixed now.
##########
File path: src/relay/backend/contrib/ethosn/ethosn_utils.h
##########
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * \file src/relay/backend/contrib/ethosn/ethosn_utils.h
+ * \brief Ethos-N utility functions.
+ */
+
+#ifndef TVM_RELAY_BACKEND_CONTRIB_ETHOSN_ETHOSN_UTILS_H_
+#define TVM_RELAY_BACKEND_CONTRIB_ETHOSN_ETHOSN_UTILS_H_
Review comment:
Done
##########
File path: tests/python/contrib/test_ethosn/test_partition_params.py
##########
@@ -0,0 +1,104 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Ethos-N partition parameter tests"""
+
+import pytest
+import tvm
+from tvm import relay
+import numpy as np
+
+from tvm.relay.op.contrib.ethosn import partition_for_ethosn77
+from tvm.relay.op.contrib.ethosn import partition_for_ethosn78
+
+fp32 = "float32"
+
+
+def test_ethosn78_partition_no_error():
+ a = relay.var("a", shape=[2, 7, 8, 8], dtype=fp32)
+ w = relay.const(np.random.uniform(-10, 10, (8, 7, 3, 3)).astype(fp32))
+ res = relay.nn.conv2d(a, w, kernel_size=(3, 3), padding=(1, 1), channels=8, out_dtype=fp32)
+ b = relay.var("b", shape=[8], dtype=fp32)
+ res = relay.nn.bias_add(res, b, axis=1)
+
+ mod = tvm.IRModule.from_expr(res)
Review comment:
Done
##########
File path: src/relay/backend/contrib/ethosn/codegen_ethosn.h
##########
@@ -227,7 +227,9 @@ NetworkWithIDs ConstructNetwork(const IRModule& mod, const GlobalVar& var, const
/*! \brief Attributes to store the compiler options for Ethos-N */
struct EthosnCompilerConfigNode : public tvm::AttrsNode<EthosnCompilerConfigNode> {
String variant;
- int sram_size_bytes;
+ String sram_size;
Review comment:
Using String type simplifies passing the value to the driver stack.
##########
File path: python/tvm/relay/op/contrib/ethosn.py
##########
@@ -61,6 +61,53 @@ def partition_for_ethosn(mod, params=None, **opts):
-------
ret : annotated and partitioned module.
"""
+ if opts:
+ tops = opts.get("tops", None)
+ ple_ratio = opts.get("ple_ratio", None)
+ sram_size = opts.get("sram_size", None)
+ if tops or ple_ratio or sram_size:
+ raise ValueError(
+ "Setting tops, ple_ratio or sram_size has no effect when targeting Ethos-N77"
+ )
+
+ if params:
+ mod["main"] = bind_params_by_name(mod["main"], params)
+
+ seq = tvm.transform.Sequential(
+ [
+ transform.InferType(),
+ transform.MergeComposite(pattern_table()),
+ transform.AnnotateTarget("ethos-n"),
+ transform.MergeCompilerRegions(),
+ transform.PartitionGraph(),
+ ]
+ )
+
+ return seq(mod), None
+
+
+def partition_for_ethosn78(mod, params=None, **opts):
+ """Partition the graph greedily offloading supported
+ operators to Arm Ethos-N NPU.
+
+ Parameters
+ ----------
+ mod : Module
+ The module to run passes on.
+ params : Optional[Dict[str, NDArray]]
+ Constant input parameters.
+
+ Returns
+ -------
+ ret : annotated and partitioned module.
Review comment:
Fixed
##########
File path: tests/cpp/ethosn_test.cc
##########
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
Review comment:
Fixed
##########
File path: tests/python/contrib/test_ethosn/test_partition_params.py
##########
@@ -0,0 +1,104 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Ethos-N partition parameter tests"""
+
Review comment:
A file comment is not part of the structure here.
##########
File path: tests/python/driver/tvmc/test_compiler.py
##########
@@ -308,6 +308,26 @@ def test_compile_tflite_module_with_external_codegen(tflite_mobilenet_v1_1_quant
assert os.path.exists(dumps_path)
+@pytest.mark.skipif(
+ not ethosn_available(),
+ reason="--target=ethos-n78 is not available. TVM built with 'USE_ETHOSN OFF'",
+)
+def test_compile_tflite_module_with_external_codegen_ethos_n78(tflite_mobilenet_v1_1_quant):
+ pytest.importorskip("tflite")
+ tvmc_model = tvmc.load(tflite_mobilenet_v1_1_quant)
+ tvmc_package = tvmc.compile(
+ tvmc_model, target="ethos-n78 -variant=Ethos-N78, llvm", dump_code="relay"
Review comment:
Fixed
##########
File path: tests/python/contrib/test_ethosn/test_partition_params.py
##########
@@ -0,0 +1,104 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Ethos-N partition parameter tests"""
+
+import pytest
+import tvm
+from tvm import relay
+import numpy as np
+
+from tvm.relay.op.contrib.ethosn import partition_for_ethosn77
+from tvm.relay.op.contrib.ethosn import partition_for_ethosn78
+
+fp32 = "float32"
Review comment:
Removed now.
##########
File path: python/tvm/relay/op/contrib/arm_compute_lib.py
##########
@@ -69,7 +69,7 @@ def partition_for_arm_compute_lib(mod, params=None, **opts):
]
)
- return seq(mod)
+ return seq(mod), None
Review comment:
Done
##########
File path: tests/python/contrib/test_ethosn/test_partition_params.py
##########
@@ -0,0 +1,104 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Ethos-N partition parameter tests"""
Review comment:
I've added no code checking tops or ple_ratio, so those values are not checked here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] tristan-arm commented on a change in pull request #8300: [ETHOSN] Add support for non-default ethos-n78 configurations
Posted by GitBox <gi...@apache.org>.
tristan-arm commented on a change in pull request #8300:
URL: https://github.com/apache/tvm/pull/8300#discussion_r691191108
##########
File path: src/relay/backend/contrib/ethosn/codegen_ethosn.h
##########
@@ -227,7 +227,9 @@ NetworkWithIDs ConstructNetwork(const IRModule& mod, const GlobalVar& var, const
/*! \brief Attributes to store the compiler options for Ethos-N */
struct EthosnCompilerConfigNode : public tvm::AttrsNode<EthosnCompilerConfigNode> {
String variant;
- int sram_size_bytes;
+ String sram_size;
Review comment:
Using String type simplifies passing the value to the driver stack.
##########
File path: python/tvm/relay/op/contrib/ethosn.py
##########
@@ -61,6 +61,53 @@ def partition_for_ethosn(mod, params=None, **opts):
-------
ret : annotated and partitioned module.
"""
+ if opts:
+ tops = opts.get("tops", None)
+ ple_ratio = opts.get("ple_ratio", None)
+ sram_size = opts.get("sram_size", None)
+ if tops or ple_ratio or sram_size:
+ raise ValueError(
+ "Setting tops, ple_ratio or sram_size has no effect when targeting Ethos-N77"
+ )
+
+ if params:
+ mod["main"] = bind_params_by_name(mod["main"], params)
+
+ seq = tvm.transform.Sequential(
+ [
+ transform.InferType(),
+ transform.MergeComposite(pattern_table()),
+ transform.AnnotateTarget("ethos-n"),
+ transform.MergeCompilerRegions(),
+ transform.PartitionGraph(),
+ ]
+ )
+
+ return seq(mod), None
+
+
+def partition_for_ethosn78(mod, params=None, **opts):
+ """Partition the graph greedily offloading supported
+ operators to Arm Ethos-N NPU.
+
+ Parameters
+ ----------
+ mod : Module
+ The module to run passes on.
+ params : Optional[Dict[str, NDArray]]
+ Constant input parameters.
+
+ Returns
+ -------
+ ret : annotated and partitioned module.
Review comment:
Fixed
##########
File path: tests/cpp/ethosn_test.cc
##########
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
Review comment:
Fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org