2 * Copyright (c) 2018 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 defines ARMComputeAxis class and utility functions to support mapping
21 * between arm compute axis and NNAPI axis
27 * @brief Class to represent arm compute axis
33 * @brief Construct a new ARMComputeAxis object
35 ARMComputeAxis() = default;
39 * @brief Construct a new ARMComputeAxis object
40 * @param[in] value Raw axis number
42 explicit ARMComputeAxis(uint32_t value) : _value{value}
49 * @brief Get raw axis number
50 * @return Raw axis number
52 uint32_t value(void) const { return _value; }
59 * @brief Convert T/F Lite / NNAPI axis (based on ...NHWC) to arm compute axis (WHCN...)
60 * @param[in] rank Rank of shape
61 * @param[in] axis Axis to map
62 * @return ARMComputeAxis including arm compute axis info
64 inline ARMComputeAxis ToARMComputeAxis(uint32_t rank, uint32_t axis)
67 const ARMComputeAxis reversed{(rank - axis) - 1};
75 if (0 == reversed.value())
77 return ARMComputeAxis{2};
80 if (1 == reversed.value())
82 return ARMComputeAxis{0};
85 if (2 == reversed.value())
87 return ARMComputeAxis{1};
97 * @brief Covert bitmask info from NNAPI axis to arm compute axis
98 * @param[in] in Bitmask data
99 * @param[in] numOfBits Used bits (rank)
100 * @return Coverted bitmask
102 template <typename T> inline T ReorderBits(T in, size_t numOfBits)
104 assert(numOfBits > 0);
106 for (int32_t i = numOfBits - 1; i >= 0; --i)
108 const uint32_t toShift = numOfBits - ToARMComputeAxis(numOfBits, i).value() - 1;
109 out += ((in & 1) << toShift);
115 #endif // __SWIZZLE_H__