summaryrefslogtreecommitdiff
path: root/runtimes/pure_arm_compute/src/internal/arm_compute/Cast.h
diff options
context:
space:
mode:
Diffstat (limited to 'runtimes/pure_arm_compute/src/internal/arm_compute/Cast.h')
-rw-r--r--runtimes/pure_arm_compute/src/internal/arm_compute/Cast.h170
1 files changed, 82 insertions, 88 deletions
diff --git a/runtimes/pure_arm_compute/src/internal/arm_compute/Cast.h b/runtimes/pure_arm_compute/src/internal/arm_compute/Cast.h
index e2ceb8fef..42b547feb 100644
--- a/runtimes/pure_arm_compute/src/internal/arm_compute/Cast.h
+++ b/runtimes/pure_arm_compute/src/internal/arm_compute/Cast.h
@@ -14,104 +14,98 @@
* limitations under the License.
*/
+/**
+ * @file Cast.h
+ * @ingroup COM_AI_RUNTIME
+ * @brief This file defines casting functions from internal object to arm compute object
+ */
#ifndef __ARM_COMPUTE_CAST_H__
+#define __ARM_COMPUTE_CAST_H__
+#include <arm_compute/core/Coordinates.h>
+#include <arm_compute/core/TensorInfo.h>
#include <arm_compute/core/TensorShape.h>
+#include <arm_compute/core/Types.h>
-#include "internal/Swizzle.h"
-#include "internal/Model.h"
-
-inline ::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;
-}
-
-inline ::arm_compute::TensorShape asTensorShape(const internal::tflite::operand::Shape &shape,
- bool apply_dim_correction = true)
-{
- const uint32_t rank = shape.rank();
+#include <NeuralNetworks.h>
- ::arm_compute::TensorShape res{};
-
- res.set_num_dimensions(rank);
-
- for (uint32_t axis = 0; axis < rank; ++axis)
- {
- // NOTE In some cases, in incorrect dimensions is required.
- // For example, intput_size is 1 in LSTM. The input-to-input weights([num_units, input_size]) of
- // LSTM is used as the weight of the FullyConnected.
- // The FullyConnected's weight must be greater or equal than 2-dimensions.
- // However, if the dimension correction is applied to input_to_input_weights with input_size
- // equal to 1, it will be changed to 1-D.
- // So input_to_input_weights is not used by the weight of FullyConnected.
- res.set(ToARMComputeAxis(rank, axis).value(), shape.dim(axis), apply_dim_correction);
- }
-
- return res;
-}
+#include "internal/Model.h"
-::arm_compute::DataType asDataType(const int32_t type)
-{
- switch (type)
- {
- case ANEURALNETWORKS_FLOAT32:
- case ANEURALNETWORKS_TENSOR_FLOAT32:
- return ::arm_compute::DataType::F32;
- case ANEURALNETWORKS_INT32:
- case ANEURALNETWORKS_TENSOR_INT32:
- return ::arm_compute::DataType::S32;
- case ANEURALNETWORKS_UINT32:
- return ::arm_compute::DataType::U32;
- case ANEURALNETWORKS_TENSOR_QUANT8_ASYMM:
- return ::arm_compute::DataType::QASYMM8;
- default:
- throw std::runtime_error("Not supported, yet");
- break;
- }
-}
+/**
+ * @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
+* @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
+ * one dimension in arm compute
+ * @return TensorShape object of arm compute
+ */
+::arm_compute::TensorShape asTensorShape(const internal::tflite::operand::Shape &shape,
+ bool apply_dim_correction = true);
-::arm_compute::ActivationLayerInfo asActivationInfo(FuseCode code)
-{
- switch (code)
- {
- case ANEURALNETWORKS_FUSED_NONE:
- return ::arm_compute::ActivationLayerInfo{};
- case ANEURALNETWORKS_FUSED_RELU:
- return ::arm_compute::ActivationLayerInfo{
- ::arm_compute::ActivationLayerInfo::ActivationFunction::RELU};
- case ANEURALNETWORKS_FUSED_RELU1:
- return ::arm_compute::ActivationLayerInfo{
- ::arm_compute::ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 1.0f, -1.0f};
- case ANEURALNETWORKS_FUSED_RELU6:
- return ::arm_compute::ActivationLayerInfo{
- ::arm_compute::ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, 6.0f, 0.0f};
- default:
- throw std::runtime_error("Not supported, yet");
- break;
- }
-}
+/**
+ * @brief Cast from data type enum of NNAPI to arm compute
+ * @param[in] type NNAPI data type
+ * @return Data type of arm compute
+ */
+::arm_compute::DataType asDataType(const int32_t type);
-::arm_compute::QuantizationInfo asQuantizationInfo(const float scale, const int32_t offset)
-{
- return ::arm_compute::QuantizationInfo(scale, offset);
-}
+/**
+ * @brief Cast from NNAPI activation type enum to activation object of arm compute
+ * @param[in] code NNAPI activation type
+ * @return ActivationLayerInfo object of arm compute
+ */
+::arm_compute::ActivationLayerInfo asActivationInfo(FuseCode code);
+/**
+ * @brief Generate quantization info object of arm compute
+ * @param[in] scale Scale of quantization
+ * @param[in] offset Offset of quantization
+ * @return QuantizationInfo object of arm compute
+ */
+::arm_compute::QuantizationInfo asQuantizationInfo(const float scale, const int32_t offset);
+
+/**
+ * @brief Cast from internal tensor info to tensor info object of arm compute
+ * @param[in] shape Tensor shape
+ * @param[in] type Tensor type
+ * @param[in] scale Scale of tensor quantization
+ * @param[in] zeroPoint Zeropoint of tensor quantization
+ * @return TensorInfo object of arm compute
+ */
::arm_compute::TensorInfo asTensorInfo(const ::arm_compute::TensorShape &shape, const int32_t type,
- const float scale = 0.0f, const int32_t zeroPoint = 0)
-{
- return ::arm_compute::TensorInfo(shape, 1, asDataType(type),
- asQuantizationInfo(scale, zeroPoint));
-}
-
+ const float scale = 0.0f, const int32_t zeroPoint = 0);
+
+/**
+ * @brief Set value to arm compute tensor with casting
+ * @param[in] value Value to set
+ * @param[out] to Target tensor of arm compute
+ * @param[in] id Position of element
+ * @return N/A
+ */
template <typename FromT>
void copyCast(const FromT value, ::arm_compute::ITensor *to, const ::arm_compute::Coordinates &id)
{