ONE - On-device Neural Engine
Loading...
Searching...
No Matches
ShapeInference.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 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
17#ifndef __ONERT_GRAPH_SHAPE_INFERENCE_H__
18#define __ONERT_GRAPH_SHAPE_INFERENCE_H__
19
20#include "Utils.h"
21
22#include "ir/operation/Concat.h"
23#include "ir/operation/Conv2D.h"
25#include "ir/operation/Pool2D.h"
29#include "ir/Index.h"
30#include "ir/OperationVisitor.h"
31#include "backend/ITensor.h"
33
35{
36
37using Shapes = std::vector<ir::Shape>;
38
39// Define shape calculation for operations. List them in alphabetic order.
40
41ir::Shape inferArgMinMaxShape(const ir::Shape &input_shape, int axis, int rank);
42
43ir::Shape inferBatchMatMulShape(const ir::Shape &lhs_shape, const ir::Shape &rhs_shape,
45
46ir::Shape inferBCQFullyConnectedShape(const ir::Shape &in_shape, const ir::Shape &cluster_shape,
47 const int32_t *cluster_buf);
48
49ir::Shape inferBCQGatherShape(const ir::Shape &indices_shape, const ir::Shape &cluster_shape,
50 const int32_t *cluster_buf, int rank,
52
53ir::Shape inferBroadcastToShape(const ir::Shape shp_shape, const int32_t *shp_buf);
54
56
57ir::Shape inferConv2DShape(const ir::Shape &in_shape, const ir::Shape &ker_shape,
58 const ir::operation::Conv2D::Param &param);
59
60ir::Shape inferDepthwiseConv2DShape(const ir::Shape &in_shape, const ir::Shape &ker_shape,
62
63ir::Shape inferEltwiseShape(const ir::Shape &lhs_shape, const ir::Shape &rhs_shape);
64
65ir::Shape inferExpandDimsShape(const ir::Shape &in_shape, int32_t axis);
66
67template <typename T> ir::Shape inferFillShape(const ir::Shape &fill_shape, const T *shape_buf);
68
69ir::Shape inferFullyConnectedShape(const ir::Shape &in_shape, const ir::Shape &ker_shape,
70 bool keep_num_dims);
71
72ir::Shape inferGatherShape(const ir::Shape &input_shape, const ir::Shape &indices_shape, int axis,
73 int rank);
74
75ir::Shape inferOnehotShape(const ir::Shape &input_shape, const int depth, int axis);
76
77ir::Shape inferPackShape(const ir::Shape &input_shape, int axis, int rank, int num);
78
79ir::Shape inferPadShape(const ir::Shape &in_shape, const int32_t *pad_buf, const size_t num_pads);
80
82
83template <typename T> ir::Shape inferRangeShape(T start_val, T limit_val, T delta_val);
84
85ir::Shape inferReshapeShape(const ir::Shape &input_shape, const int32_t *shape_buf,
86 const int32_t shape_num_elements);
87
88ir::Shape inferReduceShape(const ir::Shape &input_shape, const std::vector<int> &axes,
89 bool keep_dims);
90
91template <float *> ir::Shape inferRangeShape(float *start_val, float *limit_val, float *delta_val);
92
93template <typename T> ir::Shape inferRangeShape(T start_val, T limit_val, T delta_val);
94
95ir::Shape inferResizeBilinearShape(const ir::Shape &in_shape, const int32_t output_height,
96 const int32_t output_width);
97
98ir::Shape inferSelectShape(const ir::Shape &input_cond_shape, const ir::Shape &input_true_shape,
99 const ir::Shape &input_false_shape);
100
101template <typename T>
102ir::Shape inferSliceShape(const ir::Shape &input_shape, const T *begins_buf, const T *sizes_buf);
103
104ir::Shape inferSpaceToBatchNDShape(const ir::Shape &input_shape, const ir::Shape &block_shape_shape,
105 const ir::Shape &padding_shape, const int32_t *block_shape_buf,
106 const int32_t *padding_buf);
107
108ir::Shape inferSplitShape(const ir::Shape input_shape, int axis_value, int num_splits);
109
111
113{
115 int32_t start_indices[5];
117 int32_t stop_indices[5];
119 int32_t strides[5];
120
121 int16_t begin_mask;
123 int16_t end_mask;
126};
127
128template <typename T>
129StridedSliceParams buildStridedSliceParams(const T *begin, const T *end, const T *strides,
130 const uint32_t begin_mask, const uint32_t end_mask,
131 const uint32_t shrink_axis_mask, const uint8_t rank);
132
133ir::Shape inferStridedSliceShape(const ir::Shape &input_shape, const StridedSliceParams &op_params,
134 uint32_t rank);
135
136ir::Shape inferTileShape(const ir::Shape &in_shape, const int32_t *multiplier_buf,
137 const int32_t multiplier_size);
138
139ir::Shape inferTransposeShape(const ir::Shape &in_shape, const int32_t *perm_buf,
140 const int32_t rank);
141
142ir::Shape inferUnpackShape(const ir::Shape &input_shape, int axis, int rank);
143
144} // namespace onert::shape_inference
145
146#endif // __ONERT_GRAPH_SHAPE_INFERENCE_H__
ir::Shape inferFillShape(const ir::Shape &fill_shape, const T *shape_buf)
ir::Shape inferExpandDimsShape(const ir::Shape &in_shape, int32_t axis)
ir::Shape inferReduceShape(const ir::Shape &input_shape, const std::vector< int > &axes, bool keep_dims)
ir::Shape inferSelectShape(const ir::Shape &input_cond_shape, const ir::Shape &input_true_shape, const ir::Shape &input_false_shape)
ir::Shape inferBCQGatherShape(const ir::Shape &indices_shape, const ir::Shape &cluster_shape, const int32_t *cluster_buf, int rank, const ir::operation::BCQGather::Param &param)
ir::Shape inferSpaceToBatchNDShape(const ir::Shape &input_shape, const ir::Shape &block_shape_shape, const ir::Shape &padding_shape, const int32_t *block_shape_buf, const int32_t *padding_buf)
ir::Shape inferGatherShape(const ir::Shape &input_shape, const ir::Shape &indices_shape, int axis, int rank)
ir::Shape inferPackShape(const ir::Shape &input_shape, int axis, int rank, int num)
std::vector< ir::Shape > Shapes
ir::Shape inferEltwiseShape(const ir::Shape &lhs_shape, const ir::Shape &rhs_shape)
ir::Shape inferConcatShape(const Shapes &in_shapes, const ir::operation::Concat::Param &param)
ir::Shape inferReshapeShape(const ir::Shape &input_shape, const int32_t *shape_buf, const int32_t shape_num_elements)
ir::Shape inferDepthwiseConv2DShape(const ir::Shape &in_shape, const ir::Shape &ker_shape, const ir::operation::DepthwiseConv2D::Param &param)
ir::Shape inferUnpackShape(const ir::Shape &input_shape, int axis, int rank)
ir::Shape inferResizeBilinearShape(const ir::Shape &in_shape, const int32_t output_height, const int32_t output_width)
ir::Shape inferPadShape(const ir::Shape &in_shape, const int32_t *pad_buf, const size_t num_pads)
ir::Shape inferSliceShape(const ir::Shape &input_shape, const T *begins_buf, const T *sizes_buf)
ir::Shape inferRangeShape(T start_val, T limit_val, T delta_val)
ir::Shape inferTileShape(const ir::Shape &in_shape, const int32_t *multiplier_buf, const int32_t multiplier_size)
ir::Shape inferSplitShape(const ir::Shape input_shape, int axis_value, int num_splits)
ir::Shape inferBroadcastToShape(const ir::Shape shp_shape, const int32_t *shp_buf)
ir::Shape inferFullyConnectedShape(const ir::Shape &in_shape, const ir::Shape &ker_shape, bool keep_num_dims)
ir::Shape inferPoolShape(const ir::Shape &in_shape, const ir::operation::Pool2D::Param &param)
ir::Shape inferArgMinMaxShape(const ir::Shape &input_shape, int axis, int rank)
ir::Shape inferTransposeShape(const ir::Shape &in_shape, const int32_t *perm_buf, const int32_t rank)
ir::Shape inferBatchMatMulShape(const ir::Shape &lhs_shape, const ir::Shape &rhs_shape, const ir::operation::BatchMatMul::Param &param)
ir::Shape inferOnehotShape(const ir::Shape &input_shape, const int depth, int axis)
StridedSliceParams buildStridedSliceParams(const T *begin, const T *end, const T *strides, const uint32_t begin_mask, const uint32_t end_mask, const uint32_t shrink_axis_mask, const uint8_t rank)
ir::Shape inferBCQFullyConnectedShape(const ir::Shape &in_shape, const ir::Shape &cluster_shape, const int32_t *cluster_buf)
ir::Shape inferStridedSliceShape(const ir::Shape &input_shape, const StridedSliceParams &op_params, uint32_t rank)
ir::Shape inferConv2DShape(const ir::Shape &in_shape, const ir::Shape &ker_shape, const ir::operation::Conv2D::Param &param)
ir::Shape inferSqueezeShape(const ir::Shape &in_shape, const ir::operation::Squeeze::Param &param)
int32_t begin[5]
Definition Slice.cpp:33