Skip to content

Commit

Permalink
[ETHOSN] Add support for default Ethos-N78 configuration.
Browse files Browse the repository at this point in the history
Note: 'ETHOSN_VARIANT_CONFIG' must be set to test against Ethos-N78 and this adds support for one configuration of Ethos-N78 in TVM.
  • Loading branch information
tristan-arm committed Nov 27, 2020
1 parent 093629c commit 864dca4
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 5 deletions.
18 changes: 15 additions & 3 deletions src/relay/backend/contrib/ethosn/capabilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
/*!
* \file src/relay/backend/contrib/ethosn/capabilities.h
* \brief The Ethos-N processor series has four variants, the Ethos-N37, Ethos-N57, Ethos-N77
* and the Ethos-N78. This release of the integration supports the first three variants.
* and the Ethos-N78. This release of the integration supports the first three variants and
* the default configuration of the fourth variant.
* Configuration information for each variant is stored as a blob in this file. These blobs
* are passed into the Ethos-N support library, which in turn uses them to optimize the
* generated command-stream appropriately for the specified variant.
Expand All @@ -38,13 +39,14 @@ namespace relay {
namespace contrib {
namespace ethosn {

/* Ethos-N variants (N77, N57 and N37)
/* Ethos-N variants (N77, N57, N37 and N78)
* variant[0] - N77
* variant[1] - N57
* variant[2] - N37
* variant[4] - N78
*/
#if _ETHOSN_API_VERSION_ == 2008
static std::vector<char> variants[3] = {
static std::vector<char> variants[4] = {
{
0x03, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x10, 0x00,
Expand Down Expand Up @@ -74,6 +76,16 @@ static std::vector<char> variants[3] = {
0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00,
0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
},
{
0x03, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x02, 0x00,
0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00,
0x10, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00,
0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
}};
#else
static std::vector<char> variants[3] = {
Expand Down
4 changes: 3 additions & 1 deletion src/relay/backend/contrib/ethosn/codegen_ethosn.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ struct EthosnCompilerConfigNode : public tvm::AttrsNode<EthosnCompilerConfigNode

TVM_DECLARE_ATTRS(EthosnCompilerConfigNode, "ext.attrs.EthosnCompilerConfigNode") {
TVM_ATTR_FIELD(variant)
.describe("0 for Ethos-N77, 1 for Ethos-N57, 2 for Ethos-N37. See Ethos-N documentation.")
.describe(
"0 for Ethos-N77, 1 for Ethos-N57, 2 for Ethos-N37,"
" 3 for Ethos-N78. See Ethos-N documentation.")
.set_default(0);
TVM_ATTR_FIELD(strategy0).set_default(true);
TVM_ATTR_FIELD(strategy1).set_default(true);
Expand Down
9 changes: 8 additions & 1 deletion tests/python/contrib/test_ethosn/infrastructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def build(mod, params, npu=True, expected_host_ops=0, npu_partitions=1):
"""
relay.backend.compile_engine.get().clear()
with tvm.transform.PassContext(
opt_level=3, config={"relay.ext.ethos-n.options": {"variant": 0}}
opt_level=3, config={"relay.ext.ethos-n.options": {"variant": get_ethosn_variant()}}
):
with tvm.target.Target("llvm"):
if npu:
Expand Down Expand Up @@ -321,3 +321,10 @@ def get_conv2d_qnn_params(input_zp, input_sc, kernel_zp, kernel_sc, kernel_h, ke

def get_ethosn_api_version():
return tvm.get_global_func("relay.ethos-n.api.version")()


def get_ethosn_variant():
ethosn_variant_config = os.getenv("ETHOSN_VARIANT_CONFIG")
if ethosn_variant_config is not None:
return 3
return 0
8 changes: 8 additions & 0 deletions tests/python/contrib/test_ethosn/test_networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ def test_mobilenet_v1():
_compile_hash = {"81637c89339201a07dc96e3b5dbf836a"}
if tei.get_ethosn_api_version() == 2008:
_compile_hash = {"47e216d8ab2bf491708ccf5620bc0d02"}
if tei.get_ethosn_variant() == 3:
_compile_hash = {"2436f523e263f66a063cef902f2f43d7"}
_test_image_network(
model_url="https://storage.googleapis.com/download.tensorflow.org/"
"models/mobilenet_v1_2018_08_02/mobilenet_v1_1.0_224_quant.tgz",
Expand All @@ -147,6 +149,8 @@ def test_inception_v3():
_compile_hash = {"de0e175af610ebd45ccb03d170dc9664"}
if tei.get_ethosn_api_version() == 2008:
_compile_hash = {"8c9d75659cd7bc9ff6dd6d490d28f9b2"}
if tei.get_ethosn_variant() == 3:
_compile_hash = {"cdd4d7f6453d722ea73224ff9d6a115a"}
_test_image_network(
model_url="https://storage.googleapis.com/download.tensorflow.org/"
"models/tflite_11_05_08/inception_v3_quant.tgz",
Expand All @@ -165,6 +169,8 @@ def test_inception_v4():
# codegen, which could come about from either a change in Support Library
# version or a change in the Ethos-N codegen. To update this requires running
# on hardware that isn't available in CI.
if not tei.get_ethosn_variant() == 0:
pytest.skip("Ethos-N78 20.08 does not support inception_v4 in the default configuration.")
_compile_hash = {"06bf6cb56344f3904bcb108e54edfe87"}
if tei.get_ethosn_api_version() == 2008:
_compile_hash = {"798292bfa596ca7c32086396b494b46c"}
Expand All @@ -189,6 +195,8 @@ def test_ssd_mobilenet_v1():
_compile_hash = {"29aec6b184b09454b4323271aadf89b1", "6211d96103880b016baa85e638abddef"}
if tei.get_ethosn_api_version() == 2008:
_compile_hash = {"5999f26e140dee0d7866491997ef78c5", "24e3a690a7e95780052792d5626c85be"}
if tei.get_ethosn_variant() == 3:
_compile_hash = {"da871b3f03a93df69d704ed44584d6cd", "9f52411d301f3cba3f6e4c0f1c558e87"}
_test_image_network(
model_url="https://storage.googleapis.com/download.tensorflow.org/"
"models/tflite/coco_ssd_mobilenet_v1_1.0_quant_2018_06_29.zip",
Expand Down
3 changes: 3 additions & 0 deletions tests/scripts/task_python_integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ TVM_FFI=ctypes python3 -m pytest apps/dso_plugin_module
# TVM_FFI=ctypes sh prepare_and_test_tfop_module.sh

TVM_FFI=ctypes python3 -m pytest tests/python/integration
if python -c "import tvm; from tvm.relay.op.contrib.ethosn import ethosn_available; print(ethosn_available().name)" -eq "SW_ONLY"; then
ETHOSN_VARIANT_CONFIG=ETHOSN78_1TOPS_4PLE_448KSRAM TVM_FFI=ctypes python3 -m pytest tests/python/contrib/test_ethosn
fi
TVM_FFI=ctypes python3 -m pytest tests/python/contrib

TVM_TEST_TARGETS="${TVM_RELAY_TEST_TARGETS:-llvm;cuda}" TVM_FFI=ctypes python3 -m pytest tests/python/relay
Expand Down

0 comments on commit 864dca4

Please sign in to comment.