You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by mo...@apache.org on 2022/01/31 23:10:54 UTC

[tvm] branch main updated: [ETHOSN] Ethos(TM)-N 21.11 update (#10061)

This is an automated email from the ASF dual-hosted git repository.

mousius pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git


The following commit(s) were added to refs/heads/main by this push:
     new c130ea3  [ETHOSN] Ethos(TM)-N 21.11 update (#10061)
c130ea3 is described below

commit c130ea3062b02b4de803392284b4f42b27a79c91
Author: Leo-arm <52...@users.noreply.github.com>
AuthorDate: Mon Jan 31 23:10:29 2022 +0000

    [ETHOSN] Ethos(TM)-N 21.11 update (#10061)
    
    Minor update in inference buffer mapping due to changes in the driver
    library
---
 .../install/ubuntu_install_ethosn_driver_stack.sh  |  2 +-
 .../backend/contrib/ethosn/ethosn_api_version.h    |  6 ++++++
 src/runtime/contrib/ethosn/ethosn_device.cc        | 24 ++++++++++++++++------
 tests/python/contrib/test_ethosn/test_networks.py  | 24 +++++++++++-----------
 4 files changed, 37 insertions(+), 19 deletions(-)

diff --git a/docker/install/ubuntu_install_ethosn_driver_stack.sh b/docker/install/ubuntu_install_ethosn_driver_stack.sh
index a7ea98a..873486e 100755
--- a/docker/install/ubuntu_install_ethosn_driver_stack.sh
+++ b/docker/install/ubuntu_install_ethosn_driver_stack.sh
@@ -22,7 +22,7 @@ set -o pipefail
 
 repo_url="https://github.com/Arm-software/ethos-n-driver-stack"
 repo_dir="ethosn-driver"
-repo_revision="21.08"
+repo_revision="21.11"
 install_path="/opt/arm/$repo_dir"
 
 tmpdir=$(mktemp -d)
diff --git a/src/relay/backend/contrib/ethosn/ethosn_api_version.h b/src/relay/backend/contrib/ethosn/ethosn_api_version.h
index dfc3f4c..7631c29 100644
--- a/src/relay/backend/contrib/ethosn/ethosn_api_version.h
+++ b/src/relay/backend/contrib/ethosn/ethosn_api_version.h
@@ -33,6 +33,11 @@
  * along with associated compatibility measures when no
  * longer necessary.
  */
+
+#if ETHOSN_SUPPORT_LIBRARY_VERSION_MAJOR == 3 && ETHOSN_SUPPORT_LIBRARY_VERSION_MINOR == 0 && \
+    ETHOSN_SUPPORT_LIBRARY_VERSION_PATCH == 0
+#define _ETHOSN_API_VERSION_ 2111
+#else
 #if ETHOSN_SUPPORT_LIBRARY_VERSION_MAJOR == 1 && ETHOSN_SUPPORT_LIBRARY_VERSION_MINOR == 1 && \
     ETHOSN_SUPPORT_LIBRARY_VERSION_PATCH == 0
 #define _ETHOSN_API_VERSION_ 2108
@@ -45,5 +50,6 @@
 #define _ETHOSN_API_VERSION_ ETHOSN_API_VERSION
 #endif
 #endif
+#endif
 
 #endif  // TVM_RELAY_BACKEND_CONTRIB_ETHOSN_ETHOSN_API_VERSION_H_
diff --git a/src/runtime/contrib/ethosn/ethosn_device.cc b/src/runtime/contrib/ethosn/ethosn_device.cc
index 59a9f12..9871703 100644
--- a/src/runtime/contrib/ethosn/ethosn_device.cc
+++ b/src/runtime/contrib/ethosn/ethosn_device.cc
@@ -78,22 +78,34 @@ template <typename T>
 void CopyOutput(dl::Buffer* source_buffers[], std::vector<DLTensor*>* outputs) {
   for (DLTensor* tensor : *outputs) {
     dl::Buffer* source_buffer = source_buffers[0];
-    uint8_t* source_buffer_data = source_buffer->GetMappedBuffer();
-    size_t size = source_buffer->GetSize();
     T* dest_pointer = static_cast<T*>(tensor->data);
+    size_t size = source_buffer->GetSize();
+#if _ETHOSN_API_VERSION_ < 2111
+    uint8_t* source_buffer_data = source_buffer->GetMappedBuffer();
+#else
+    uint8_t* source_buffer_data = source_buffer->Map();
+#endif
     std::copy_backward(source_buffer_data, source_buffer_data + size, dest_pointer + size);
+#if _ETHOSN_API_VERSION_ >= 2111
+    source_buffer->Unmap();
+#else
+#endif
     source_buffers++;
   }
 }
 
 void CreateBuffers(std::vector<std::shared_ptr<dl::Buffer> >* fm,
-                   const std::vector<DLTensor*>& tensors) {
+                   const std::vector<DLTensor*>& tensors, bool input) {
   int index = 0;
   for (auto buffer : tensors) {
     auto* data = static_cast<uint8_t*>(buffer->data);
     // The NPU only needs the size of the tensor * uint8_t.
     auto data_size = static_cast<uint32_t>(GetDataSize(*buffer));
-    (*fm)[index++] = std::make_shared<dl::Buffer>(data, data_size, dl::DataFormat::NHWC);
+    if (input) {
+      (*fm)[index++] = std::make_shared<dl::Buffer>(data, data_size, dl::DataFormat::NHWC);
+    } else {
+      (*fm)[index++] = std::make_shared<dl::Buffer>(data_size, dl::DataFormat::NHWC);
+    }
   }
 }
 
@@ -121,11 +133,11 @@ bool Inference(tvm::runtime::TVMArgs args, dl::Network* npu,
 
   // Set up input buffers
   std::vector<std::shared_ptr<dl::Buffer> > ifm(inputs.size());
-  CreateBuffers(&ifm, inputs);
+  CreateBuffers(&ifm, inputs, true);
 
   // Set up output buffers
   std::vector<std::shared_ptr<dl::Buffer> > ofm(outputs.size());
-  CreateBuffers(&ofm, outputs);
+  CreateBuffers(&ofm, outputs, false);
 
   // Raw pointers for the inference
   dl::Buffer* ifm_raw[inputs.size()];
diff --git a/tests/python/contrib/test_ethosn/test_networks.py b/tests/python/contrib/test_ethosn/test_networks.py
index fe1c4d9..f79b1f4 100644
--- a/tests/python/contrib/test_ethosn/test_networks.py
+++ b/tests/python/contrib/test_ethosn/test_networks.py
@@ -123,9 +123,9 @@ def test_mobilenet_v1():
     # 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.
-    _compile_hash = {"0433d3c3947a067b36f0228bdb5f1838"}
-    if tei.get_ethosn_variant() == "Ethos-N78_1TOPS_2PLE_RATIO":
-        _compile_hash = {"393a19dfb980345cdd3bbeddbc36424d"}
+    _compile_hash = {"393a19dfb980345cdd3bbeddbc36424d"}
+    if tei.get_ethosn_api_version() == 2111:
+        _compile_hash = {"5d1c6a6bd4df8963866cc90405bf92dd"}
     if tei.get_ethosn_api_version() == 2102:
         _compile_hash = {"46ccafc840633633aca441645e41b444"}
         if tei.get_ethosn_variant() == "Ethos-N78_1TOPS_2PLE_RATIO":
@@ -174,9 +174,9 @@ def test_inception_v3():
     # 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.
-    _compile_hash = {"46ccafc840633633aca441645e41b444"}
-    if tei.get_ethosn_variant() == "Ethos-N78_1TOPS_2PLE_RATIO":
-        _compile_hash = {"2c7ff5487e1a21e62b3b42eec624fed4"}
+    _compile_hash = {"2c7ff5487e1a21e62b3b42eec624fed4"}
+    if tei.get_ethosn_api_version() == 2111:
+        _compile_hash = {"e6abe33a7bc4a4170da53eefa6577bba"}
     if tei.get_ethosn_api_version() == 2102:
         _compile_hash = {"43dc2097127eb224c0191b1a15f8acca"}
         if tei.get_ethosn_variant() == "Ethos-N78_1TOPS_2PLE_RATIO":
@@ -200,9 +200,9 @@ 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.
-    _compile_hash = {"fab6c2297502f95d33079c6ce1a737f9"}
-    if tei.get_ethosn_variant() == "Ethos-N78_1TOPS_2PLE_RATIO":
-        _compile_hash = {"4245dbd02e1432dc261a67fc8e632a00"}
+    _compile_hash = {"4245dbd02e1432dc261a67fc8e632a00"}
+    if tei.get_ethosn_api_version() == 2111:
+        _compile_hash = {"42e43c323ed8202f7b720ba9029bbcb7"}
     if tei.get_ethosn_api_version() == 2102:
         _compile_hash = {"fab6c2297502f95d33079c6ce1a737f9"}
         if tei.get_ethosn_variant() == "Ethos-N78_1TOPS_2PLE_RATIO":
@@ -226,9 +226,9 @@ def test_ssd_mobilenet_v1():
     # 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.
-    _compile_hash = {"2345cf5d6c0013bad7c76dcccee9d862", "7795b6c67178da9d1f9b98063bad75b1"}
-    if tei.get_ethosn_variant() == "Ethos-N78_1TOPS_2PLE_RATIO":
-        _compile_hash = {"5ee8ed6af9a7f31fc14957b51a8e7423", "e6a91ccc47ba4c6b4614fcd676bd726f"}
+    _compile_hash = {"5ee8ed6af9a7f31fc14957b51a8e7423", "e6a91ccc47ba4c6b4614fcd676bd726f"}
+    if tei.get_ethosn_api_version() == 2111:
+        _compile_hash = {"afb68ca8f452d1f4a674b457b5e30f59", "a37f900601b9493bd142e8aed16205e5"}
     if tei.get_ethosn_api_version() == 2102:
         _compile_hash = {"7795b6c67178da9d1f9b98063bad75b1", "10826406ae724e52f360a06c35ced09d"}
         if tei.get_ethosn_variant() == "Ethos-N78_1TOPS_2PLE_RATIO":