ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Utils.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
3
*
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
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
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.
15
*/
16
22
#ifndef __ONERT_UTIL_UTILS_H__
23
#define __ONERT_UTIL_UTILS_H__
24
25
#include "
ir/Coordinates.h
"
26
#include "ir/Shape.h"
27
28
template
<
size_t
rest>
struct
ForEachDimension
29
{
30
template
<
typename
L>
31
static
void
unroll
(
const
onert::ir::Shape
&shape,
onert::ir::Coordinates
&
coords
,
32
L lambda_function)
33
{
34
if
(
static_cast<
int
>
(rest) > shape.rank())
35
{
36
ForEachDimension<rest - 1>::unroll
(shape,
coords
, lambda_function);
37
return
;
38
}
39
40
const
auto
axis = shape.rank() - rest;
41
const
auto
&d = shape.dim(axis);
42
43
for
(
auto
v = 0; v < d; v++)
44
{
45
coords
.set(axis, v);
46
ForEachDimension<rest - 1>::unroll
(shape,
coords
, lambda_function);
47
}
48
}
49
};
50
51
template
<>
struct
ForEachDimension
<0>
52
{
53
template
<
typename
L>
54
static
void
unroll
(
const
onert::ir::Shape
&,
onert::ir::Coordinates
&
coords
, L lambda_function)
55
{
56
lambda_function(
coords
);
57
}
58
};
59
60
template
<
typename
L>
inline
void
ShapeLoop
(
const
onert::ir::Shape
&shape, L lambda_function)
61
{
62
int32_t rank = shape.rank();
63
assert(rank > 0);
64
for
(int32_t i = 0; i < rank; ++i)
65
{
66
assert(shape.dim(i) > 0);
67
}
68
69
onert::ir::Coordinates
coords
;
70
if
(rank == 0)
71
{
72
coords
.
set
(0, 0);
73
}
74
// TODO Change 6 to onert::ir::Shape::kMaxRank if onert::ir::Shape::kMaxRank is modified as a
75
// constant expression
76
ForEachDimension<6>::unroll
(shape,
coords
, lambda_function);
77
}
78
#endif
// __ONERT_UTIL_UTILS_H__
Coordinates.h
coords
Array< CornerBox > coords
Definition
DetectionPostProcessLayer.cc:54
onert::ir::Coordinates
Class to represent position(offset) of tensor. Assume that the front is higher dimensional....
Definition
Coordinates.h:37
onert::ir::Coordinates::set
void set(size_t dimension, int32_t coordinate)
Set the coordinate of one of the coordinates.
Definition
Coordinates.h:79
onert::ir::operation::Shape
Definition
Shape.h:32
ShapeLoop
void ShapeLoop(const onert::ir::Shape &shape, L lambda_function)
Definition
Utils.h:60
ForEachDimension< 0 >::unroll
static void unroll(const onert::ir::Shape &, onert::ir::Coordinates &coords, L lambda_function)
Definition
Utils.h:54
ForEachDimension
Definition
Utils.h:29
ForEachDimension::unroll
static void unroll(const onert::ir::Shape &shape, onert::ir::Coordinates &coords, L lambda_function)
Definition
Utils.h:31
runtime
onert
core
include
util
Utils.h
Generated by
1.9.8