Fix axis calculation of TensorSource from reversing to using ToARMComputeAxis (#2481)
author장지섭/동작제어Lab(SR)/Engineer/삼성전자 <jiseob.jang@samsung.com>
Wed, 29 Aug 2018 01:33:33 +0000 (10:33 +0900)
committer박세희/동작제어Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Wed, 29 Aug 2018 01:33:33 +0000 (10:33 +0900)
This commit Fix axis calculation of TensorSource from reversing to using ToARMComputeAxis.

Supported tensor rank of TensorSource:
1D ~ 3D : reversing
more than 4D : ...NHWC -> WHCN...

Signed-off-by: jiseob.jang <jiseob.jang@samsung.com>
runtimes/pure_arm_compute/src/internal/TensorSource.h

index ab5b8f2..b42efa5 100644 (file)
@@ -5,9 +5,11 @@
 #include <util/tensor/IndexIterator.h>
 
 #include "internal/Source.h"
+#include "internal/Swizzle.h"
 #include "internal/nnapi/tensor/Reader.h"
 #include "internal/arm_compute/tensor/View.h"
 
+// NOTE TensorSource is much slower than specialized Source(s)
 template <typename T> class TensorSource final : public Source
 {
 public:
@@ -24,11 +26,15 @@ public:
     ::internal::arm_compute::tensor::View<T> into{&tensor};
 
     ::nnfw::util::tensor::iterate(_shape) << [&](const nnfw::util::tensor::Index &index_nnapi) {
-      const auto value = from.at(index_nnapi);
+      const auto rank = index_nnapi.rank();
+      nnfw::util::tensor::Index index_ACL(rank);
 
-      nnfw::util::tensor::Index index_ACL = nnfw::util::tensor::copy_reverse(index_nnapi);
+      for (uint32_t axis = 0; axis < rank; ++axis)
+      {
+        index_ACL.at(ToARMComputeAxis(rank, axis).value()) = index_nnapi.at(axis);
+      }
 
-      into.at(index_ACL) = value;
+      into.at(index_ACL) = from.at(index_nnapi);
     };
   }