2 * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 * @ingroup COM_AI_RUNTIME
20 * @brief This file contains utils for arm compute library
22 #ifndef __ARM_COMPUTE_MISC_UTILS_H__
23 #define __ARM_COMPUTE_MISC_UTILS_H__
27 #include <arm_compute/runtime/CL/CLTensor.h>
29 #include <arm_compute/core/Coordinates.h>
30 #include <arm_compute/core/TensorInfo.h>
31 #include <arm_compute/core/TensorShape.h>
32 #include <arm_compute/core/Types.h>
34 // TODO : It should be extracted to independent module.
44 * @brief Check if this runtime runs on GPU or NEON
45 * @return @c true if GPU mode, otherwise @c false
50 #define CAST_CL(tensor) static_cast<::arm_compute::CLTensor *>(tensor)
54 #define CAST_NE(tensor) static_cast<::arm_compute::Tensor *>(tensor)
58 * @brief Generate arm compute permutation vector from runtime permutation vector
59 * @param[in] rank Rank number supported upto 4
60 * @param[in] runtime_pv Integer array for runtime permutation vector
61 * @return Permutation vector of arm compute
63 arm_compute::PermutationVector getARMComputePermutationVector(uint32_t rank,
64 const int32_t *runtime_pv);
67 * @brief Set value to arm compute tensor with casting
68 * @param[in] value Value to set
69 * @param[out] to Target tensor of arm compute
70 * @param[in] id Position of element
73 template <typename FromT>
74 void copyCast(const FromT value, arm_compute::ITensor *to, const arm_compute::Coordinates &id)
76 switch (to->info()->data_type())
78 case arm_compute::DataType::F32:
80 *reinterpret_cast<float *>(to->ptr_to_element(id)) = static_cast<float>(value);
83 case arm_compute::DataType::S32:
85 *reinterpret_cast<int32_t *>(to->ptr_to_element(id)) = static_cast<int32_t>(value);
88 case arm_compute::DataType::U32:
90 *reinterpret_cast<uint32_t *>(to->ptr_to_element(id)) = static_cast<uint32_t>(value);
93 case arm_compute::DataType::QASYMM8:
95 float realValue = static_cast<float>(value);
96 // NOTE We haven't known the policy of rounding for quantization.
97 // So this is set to a temporary value.
98 *(to->ptr_to_element(id)) = quantize_qasymm8(realValue, to->info()->quantization_info(),
99 arm_compute::RoundingPolicy::TO_ZERO);
103 throw std::runtime_error("Not supported, yet");
110 } // namespace arm_compute
112 #endif // __ARM_COMPUTE_MISC_UTILS_H__