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 * @brief This file contains utility macro
22 #ifndef __ONERT_UTIL_UTILS_H__
23 #define __ONERT_UTIL_UTILS_H__
25 #include "ir/Coordinates.h"
28 #define UNUSED_RELEASE(a) (void)(a)
30 template <size_t rest> struct ForEachDimension
33 static void unroll(const onert::ir::Shape &shape, onert::ir::Coordinates &coords,
36 if (static_cast<int>(rest) > shape.rank())
38 ForEachDimension<rest - 1>::unroll(shape, coords, lambda_function);
42 const auto axis = shape.rank() - rest;
43 const auto &d = shape.dim(axis);
45 for (auto v = 0; v < d; v++)
48 ForEachDimension<rest - 1>::unroll(shape, coords, lambda_function);
53 template <> struct ForEachDimension<0>
56 static void unroll(const onert::ir::Shape &shape, onert::ir::Coordinates &coords,
59 UNUSED_RELEASE(shape);
60 lambda_function(coords);
64 template <typename L> inline void ShapeLoop(const onert::ir::Shape &shape, L lambda_function)
66 int32_t rank = shape.rank();
68 for (int32_t i = 0; i < rank; ++i)
70 assert(shape.dim(i) > 0);
73 onert::ir::Coordinates coords;
78 // TODO Change 6 to onert::ir::Shape::kMaxRank if onert::ir::Shape::kMaxRank is modified as a
79 // constant expression
80 ForEachDimension<6>::unroll(shape, coords, lambda_function);
82 #endif // __ONERT_UTIL_UTILS_H__