summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author오형석/On-Device Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>2019-04-15 23:44:31 (GMT)
committer박세희/On-Device Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>2019-04-15 23:44:31 (GMT)
commit60a3e226cade5676616649b07231ab48bb9960e4 (patch)
tree19f07a716840ad9c9f8d3f933e647e26ef9bdcf8
parent83d66c0551e0ecf01316b88fc672f8155fdef939 (diff)
downloadnnfw-60a3e226cade5676616649b07231ab48bb9960e4.zip
nnfw-60a3e226cade5676616649b07231ab48bb9960e4.tar.gz
nnfw-60a3e226cade5676616649b07231ab48bb9960e4.tar.bz2
Remove axis conversion in libs/ARMComputeEx (#4992)
Remove axis conversion in libs/ARMComputeEx because conversion should done before configuration Fix axis conversion in pack/unpack acl-cl extend kernel Signed-off-by: Hyeongseok Oh <hseok82.oh@samsung.com>
-rw-r--r--libs/ARMComputeEx/arm_compute/runtime/misc/functions/SimplePackLayer.h4
-rw-r--r--libs/ARMComputeEx/arm_compute/runtime/misc/functions/SimpleUnpackLayer.h4
-rw-r--r--libs/ARMComputeEx/arm_compute/runtime/misc/functions/Utils.h104
-rw-r--r--libs/ARMComputeEx/src/runtime/misc/functions/SimplePackLayer.cpp13
-rw-r--r--libs/ARMComputeEx/src/runtime/misc/functions/SimpleUnpackLayer.cpp11
-rw-r--r--libs/ARMComputeEx/src/runtime/misc/functions/Utils.cpp69
-rw-r--r--runtimes/pure_arm_compute/src/compilation.cc24
7 files changed, 30 insertions, 199 deletions
diff --git a/libs/ARMComputeEx/arm_compute/runtime/misc/functions/SimplePackLayer.h b/libs/ARMComputeEx/arm_compute/runtime/misc/functions/SimplePackLayer.h
index 9df3078..d0682c1 100644
--- a/libs/ARMComputeEx/arm_compute/runtime/misc/functions/SimplePackLayer.h
+++ b/libs/ARMComputeEx/arm_compute/runtime/misc/functions/SimplePackLayer.h
@@ -40,7 +40,7 @@ public:
public:
void configure(const std::vector<arm_compute::ICLTensor *> &input_vector,
- arm_compute::ICLTensor *output, int axis);
+ arm_compute::ICLTensor *output, uint32_t axis);
public:
void run(void) override;
@@ -52,7 +52,7 @@ private:
std::vector<arm_compute::CLReshapeLayer> _cl_reshape_vector;
std::vector<arm_compute::CLPermute> _cl_permute_vector;
arm_compute::ICLTensor *_output;
- int _axis;
+ uint32_t _axis;
};
} // namespace misc
diff --git a/libs/ARMComputeEx/arm_compute/runtime/misc/functions/SimpleUnpackLayer.h b/libs/ARMComputeEx/arm_compute/runtime/misc/functions/SimpleUnpackLayer.h
index f5dd674..62e4dd5 100644
--- a/libs/ARMComputeEx/arm_compute/runtime/misc/functions/SimpleUnpackLayer.h
+++ b/libs/ARMComputeEx/arm_compute/runtime/misc/functions/SimpleUnpackLayer.h
@@ -40,7 +40,7 @@ public:
public:
void configure(arm_compute::ICLTensor *input,
- const std::vector<arm_compute::ICLTensor *> &output_vector, int32_t axis);
+ const std::vector<arm_compute::ICLTensor *> &output_vector, uint32_t axis);
public:
void run(void) override;
@@ -52,7 +52,7 @@ private:
std::vector<arm_compute::CLReshapeLayer> _cl_reshape_vector;
std::vector<arm_compute::CLPermute> _cl_permute_vector;
arm_compute::ICLTensor *_input;
- int32_t _axis;
+ uint32_t _axis;
};
} // namespace misc
diff --git a/libs/ARMComputeEx/arm_compute/runtime/misc/functions/Utils.h b/libs/ARMComputeEx/arm_compute/runtime/misc/functions/Utils.h
index 24c9d0f..53736f5 100644
--- a/libs/ARMComputeEx/arm_compute/runtime/misc/functions/Utils.h
+++ b/libs/ARMComputeEx/arm_compute/runtime/misc/functions/Utils.h
@@ -55,110 +55,6 @@ bool isGpuMode();
#endif
/**
- * @brief Class to represent arm compute axis
- */
-class ARMComputeAxis
-{
-public:
- /**
- * @brief Construct a new ARMComputeAxis object
- */
- ARMComputeAxis() = default;
-
-public:
- /**
- * @brief Construct a new ARMComputeAxis object
- * @param[in] value Raw axis number
- */
- explicit ARMComputeAxis(uint32_t value) : _value{value}
- {
- // DO NOTHING
- }
-
-public:
- /**
- * @brief Get raw axis number
- * @return Raw axis number
- */
- uint32_t value(void) const { return _value; }
-
-private:
- uint32_t _value;
-};
-
-/**
- * @brief Convert T/F Lite / NNAPI axis (based on ...NHWC) to arm compute axis (WHCN...)
- * @param[in] rank Rank of shape
- * @param[in] axis Axis to map
- * @return ARMComputeAxis including arm compute axis info
- */
-inline ARMComputeAxis ToARMComputeAxis(uint32_t rank, uint32_t axis)
-{
- assert(rank > axis);
- const ARMComputeAxis reversed{(rank - axis) - 1};
-
- if (rank < 4)
- {
- return reversed;
- }
-
- // DEPTH
- if (0 == reversed.value())
- {
- return ARMComputeAxis{2};
- }
- // WIDTH
- if (1 == reversed.value())
- {
- return ARMComputeAxis{0};
- }
- // HEIGHT
- if (2 == reversed.value())
- {
- return ARMComputeAxis{1};
- }
-
- // ELSE
- return reversed;
-}
-
-/**
- * @brief Covert bitmask info from NNAPI axis to arm compute axis
- * @param[in] in Bitmask data
- * @param[in] numOfBits Used bits (rank)
- * @return Coverted bitmask
- */
-template <typename T> inline T ReorderBits(T in, size_t numOfBits)
-{
- assert(numOfBits > 0);
- T out = 0;
- for (int32_t i = numOfBits - 1; i >= 0; --i)
- {
- const uint32_t toShift = numOfBits - ToARMComputeAxis(numOfBits, i).value() - 1;
- out += ((in & 1) << toShift);
- in >>= 1;
- }
- return out;
-}
-
-/**
- * @brief Generate arm compute coordinate object from rank
- * @param[in] rank Rank number
- * @return Coordinate object
- */
-arm_compute::Coordinates getARMComputeAxises(uint32_t rank);
-
-/**
- * @brief Generate arm compute coordinate object from runtime coordinate object
- * @param[in] runtime_coord Runtime coordinates object
- * @param[in] axises Coordinates for axises to map runtime-coordinates to
- * arm_compute-coordinates
- * @return Arm_compute coordinate object
- */
-arm_compute::Coordinates asARMComputeCoordinates(const arm_compute::Coordinates &runtime_coord,
- 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
diff --git a/libs/ARMComputeEx/src/runtime/misc/functions/SimplePackLayer.cpp b/libs/ARMComputeEx/src/runtime/misc/functions/SimplePackLayer.cpp
index 218ff58..3599c52 100644
--- a/libs/ARMComputeEx/src/runtime/misc/functions/SimplePackLayer.cpp
+++ b/libs/ARMComputeEx/src/runtime/misc/functions/SimplePackLayer.cpp
@@ -22,7 +22,7 @@ namespace misc
{
void SimplePackLayer::configure(const std::vector<arm_compute::ICLTensor *> &input_vector,
- arm_compute::ICLTensor *output, int32_t axis)
+ arm_compute::ICLTensor *output, uint32_t axis)
{
uint32_t nr_inputs = input_vector.size();
uint32_t output_rank = output->info()->num_dimensions();
@@ -31,20 +31,13 @@ void SimplePackLayer::configure(const std::vector<arm_compute::ICLTensor *> &inp
_cl_permute_vector.resize(nr_inputs);
_output = output;
- // A negative axis implies axis from the end.
- // For example, axis = -1 implies the first axis from the end, i.e. axis = Rank - 1.
- // Similarly, axis = -2 imples second axis from the end, i.e. axis = Rank - 2.
- if (axis < 0)
- {
- axis += output_rank;
- }
- _axis = utils::ToARMComputeAxis(output_rank, axis).value();
+ _axis = axis;
_cl_reshape_vector.resize(nr_inputs);
arm_compute::TensorShape subTensor_shape{};
for (uint32_t i = 0; i < output_rank; i++)
{
- if (i != (uint32_t)_axis)
+ if (i != _axis)
{
subTensor_shape.set(i, _output->info()->tensor_shape()[i]);
}
diff --git a/libs/ARMComputeEx/src/runtime/misc/functions/SimpleUnpackLayer.cpp b/libs/ARMComputeEx/src/runtime/misc/functions/SimpleUnpackLayer.cpp
index ce9e248..c5374cc 100644
--- a/libs/ARMComputeEx/src/runtime/misc/functions/SimpleUnpackLayer.cpp
+++ b/libs/ARMComputeEx/src/runtime/misc/functions/SimpleUnpackLayer.cpp
@@ -23,7 +23,7 @@ namespace misc
void SimpleUnpackLayer::configure(arm_compute::ICLTensor *input,
const std::vector<arm_compute::ICLTensor *> &output_vector,
- int32_t axis)
+ uint32_t axis)
{
uint32_t nr_outputs = output_vector.size();
_cl_permuted_vector.resize(nr_outputs);
@@ -31,18 +31,13 @@ void SimpleUnpackLayer::configure(arm_compute::ICLTensor *input,
uint32_t input_rank = input->info()->num_dimensions();
const arm_compute::PermutationVector pv{2, 0, 1};
_input = input;
- // Negatige axis is supported, -1 implies R-1 axis where R is input rank
- if (axis < 0)
- {
- axis += input_rank;
- }
- _axis = utils::ToARMComputeAxis(input_rank, axis).value();
+ _axis = axis;
_cl_reshape_vector.resize(nr_outputs);
arm_compute::TensorShape subTensor_shape{};
for (uint32_t i = 0; i < input_rank; i++)
{
- if (i != (uint32_t)_axis)
+ if (i != _axis)
{
subTensor_shape.set(i, _input->info()->tensor_shape()[i]);
}
diff --git a/libs/ARMComputeEx/src/runtime/misc/functions/Utils.cpp b/libs/ARMComputeEx/src/runtime/misc/functions/Utils.cpp
index ccf4220..44a4bb9 100644
--- a/libs/ARMComputeEx/src/runtime/misc/functions/Utils.cpp
+++ b/libs/ARMComputeEx/src/runtime/misc/functions/Utils.cpp
@@ -33,75 +33,6 @@ bool isGpuMode()
return true;
}
-arm_compute::Coordinates getARMComputeAxises(uint32_t rank)
-{
- arm_compute::Coordinates res{};
-
- res.set_num_dimensions(rank);
-
- for (uint32_t axis = 0; axis < rank; ++axis)
- {
- res.set(axis, ToARMComputeAxis(rank, axis).value());
- }
-
- return res;
-}
-
-arm_compute::Coordinates asARMComputeCoordinates(const arm_compute::Coordinates &runtime_coord,
- const arm_compute::Coordinates &axises)
-{
- arm_compute::Coordinates id{};
- assert(runtime_coord.num_dimensions() == axises.num_dimensions());
- for (size_t i = 0; i < runtime_coord.num_dimensions(); ++i)
- {
- id.set(axises[i], runtime_coord[i]);
- }
- 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 (uint32_t 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]};
-}
-
} // namespace utils
} // namespace misc
} // namespace arm_compute
diff --git a/runtimes/pure_arm_compute/src/compilation.cc b/runtimes/pure_arm_compute/src/compilation.cc
index ae73840..fd20020 100644
--- a/runtimes/pure_arm_compute/src/compilation.cc
+++ b/runtimes/pure_arm_compute/src/compilation.cc
@@ -5154,6 +5154,13 @@ void Planner::visit(const ::internal::tflite::op::Unpack::Node &node)
int32_t axis =
_ctx.at(::internal::tflite::operand::Index{node.param().axis_index}).asScalar<int32_t>();
+ // Negatige axis is supported, -1 implies R-1 axis where R is input rank
+ if (axis < 0)
+ {
+ axis += input_rank;
+ assert(axis >= 0);
+ }
+ uint32_t axis_uint = ToARMComputeAxis(input_rank, axis).value();
// int32_t num_split =
// _ctx.at(::internal::tflite::operand::Index{node.param().num_split_index}).asScalar<int32_t>();
@@ -5168,14 +5175,14 @@ void Planner::visit(const ::internal::tflite::op::Unpack::Node &node)
{
std::vector<int32_t> ofm_indexes;
int ifm_index;
- int axis;
+ uint32_t axis;
};
if (input_rank == 4)
{
Param param;
param.ifm_index = ifm_index.asInt();
- param.axis = axis;
+ param.axis = axis_uint;
for (const auto &index : node.param().ofm_indexes)
{
param.ofm_indexes.push_back(index);
@@ -5241,19 +5248,28 @@ void Planner::visit(const ::internal::tflite::op::Pack::Node &node)
int32_t axis =
_ctx.at(::internal::tflite::operand::Index{node.param().axis_index}).asScalar<int32_t>();
+ // A negative axis implies axis from the end.
+ // For example, axis = -1 implies the first axis from the end, i.e. axis = Rank - 1.
+ // Similarly, axis = -2 imples second axis from the end, i.e. axis = Rank - 2.
+ if (axis < 0)
+ {
+ axis += output_rank;
+ assert(axis >= 0);
+ }
+ uint32_t axis_uint = ToARMComputeAxis(output_rank, axis).value();
struct Param
{
std::vector<int32_t> ifm_indexes;
int ofm_index;
- int axis;
+ uint32_t axis;
};
if (input_rank == 3)
{
Param param;
param.ofm_index = ofm_index.asInt();
- param.axis = axis;
+ param.axis = axis_uint;
// TODO: Fix this once all permutations are present.
if (param.axis != 0)