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 internal::nnapi::feature::View class
22 #ifndef __INTERNAL_NNAPI_FEATURE_VIEW_H__
23 #define __INTERNAL_NNAPI_FEATURE_VIEW_H__
25 #include "internal/nnapi/feature/Utils.h"
27 #include "misc/feature/Reader.h"
37 * @brief Class to access feature's element information using index
39 template <typename T> class View final : public nnfw::misc::feature::Reader<T>
43 * @brief Construct a new View object
44 * @param[in] shape Shape of feature
45 * @param[in] ptr Pointer to feature data
46 * @param[in] len Size of feature (byte)
49 // NOTE The parameter len denotes the number of bytes.
50 View(const ::nnfw::misc::feature::Shape &shape, T *ptr, size_t len) : _shape{shape}, _ptr{ptr}
52 assert(shape.N * shape.C * shape.H * shape.W * sizeof(T) == len);
57 * @brief Get shape of feature
58 * @return Shape of feature
60 const nnfw::misc::feature::Shape &shape(void) const { return _shape; }
64 * @brief Get value of element in 3D feature using channel, row, and column index
65 * @param[in] ch Channel index
66 * @param[in] row Row index
67 * @param[in] col Column index
68 * @return Value of element
70 T at(uint32_t ch, uint32_t row, uint32_t col) const override
72 uint32_t index = index_of(_shape, ch, row, col);
78 * @brief Get value of element in 4D feature using batch, channel, row and column index
79 * @param[in] batch Batch index
80 * @param[in] ch Channel index
81 * @param[in] row Row index
82 * @param[in] col Column index
83 * @return Value of element
85 T at(uint32_t batch, uint32_t ch, uint32_t row, uint32_t col) const override
87 uint32_t index = index_of(_shape, batch, ch, row, col);
93 * @brief Get reference of element in 3D feature using channel, row, and column index
94 * @param[in] ch Channel index
95 * @param[in] row Row index
96 * @param[in] col Column index
97 * @return Reference of element
99 T &at(uint32_t ch, uint32_t row, uint32_t col)
101 uint32_t index = index_of(_shape, ch, row, col);
107 * @brief Get reference of element in 4D feature using batch, channel, row and column index
108 * @param[in] batch Batch index
109 * @param[in] ch Channel index
110 * @param[in] row Row index
111 * @param[in] col Column index
112 * @return Reference of element
114 T &at(uint32_t batch, uint32_t ch, uint32_t row, uint32_t col)
116 uint32_t index = index_of(_shape, batch, ch, row, col);
122 nnfw::misc::feature::Shape _shape;
128 } // namespace feature
130 } // namespace internal
132 #endif // __INTERNAL_NNAPI_FEATURE_VIEW_H__