Utility function to get ACL_PermutationVector from Runtime_PV (#3128)
authorShubham Gupta/System SW /SRI-Bangalore/Engineer/삼성전자 <shub98.gupta@samsung.com>
Wed, 24 Oct 2018 08:31:10 +0000 (14:01 +0530)
committer오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Wed, 24 Oct 2018 08:31:10 +0000 (17:31 +0900)
For issue #3022
This commit adds a function that converts the Permutation vector of the runtime into the Permutation Vector of ACL

Signed-off-by: shubham <shub98.gupta@samsung.com>
runtimes/pure_arm_compute/src/internal/arm_compute/Cast.cc
runtimes/pure_arm_compute/src/internal/arm_compute/Cast.h

index d33de2f..ff2f793 100644 (file)
   return id;
 }
 
+// Restructure runtime_permutationVector to ACL_permutationVector
+::arm_compute::PermutationVector getARMComputePermutationVector(uint32_t rank,
+                                                                const int32_t *runtime_pv)
+{
+  // rank upto 4 is supported
+  assert(rank <= 4);
+  assert(runtime_pv != nullptr);
+
+  int new_pv[4] = {0};
+  ::arm_compute::Coordinates axises = getARMComputeAxises(rank);
+
+  if (rank == 4)
+  {
+    /**
+    axises = {3,1,0,2}
+       NNAPI      PermutationVector
+    N   0               3
+    H   1               1
+    W   2               0
+    C   3               2
+    **/
+    new_pv[0] = axises[runtime_pv[2]];
+    new_pv[1] = axises[runtime_pv[1]];
+    new_pv[2] = axises[runtime_pv[3]];
+    new_pv[3] = axises[runtime_pv[0]];
+  }
+  else
+  {
+    /**
+    mapping/axises = {rank-1 to 0}
+    CHW --------> WHC
+    or
+    WH ----------> HW
+    **/
+    for (int id = 0; id < rank; ++id)
+    {
+      new_pv[id] = axises[runtime_pv[rank - id - 1]];
+    }
+  }
+
+  return ::arm_compute::PermutationVector{new_pv[0], new_pv[1], new_pv[2], new_pv[3]};
+}
+
 ::arm_compute::TensorShape asTensorShape(const internal::tflite::operand::Shape &shape,
                                          bool apply_dim_correction)
 {
index 1cee792..42b547f 100644 (file)
                                                    const ::arm_compute::Coordinates &axises);
 
 /**
+* @brief      Generate arm compute permutation vector from runtime permutation vector
+* @param[in]  rank                 Rank number supported upto 4
+* @param[in]  runtime_pv           Integer array for runtime permutation vector
+* @return     Permutation vector of arm compute
+*/
+::arm_compute::PermutationVector getARMComputePermutationVector(uint32_t rank,
+                                                                const int32_t *runtime_pv);
+/**
  * @brief     Cast from shape of internal to arm compute
  * @param[in] shape                 Internal shape object
  * @param[in] apply_dim_correction  Flag to state whether apply dimension correction after setting