Imported Upstream version 1.12.0
[platform/core/ml/nnfw.git] / compiler / luci / service / include / luci / Service / ShapeDescription.h
1 /*
2  * Copyright (c) 2020 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 __LUCI_SHAPE_DESCRIPTION_H__
18 #define __LUCI_SHAPE_DESCRIPTION_H__
19
20 #include <loco/IR/PermutingCodec.h>
21 #include <loco/IR/NodeShape.h>
22
23 #include <luci/IR/CircleNodes.h>
24
25 #include <cstdint>
26 #include <vector>
27
28 namespace luci
29 {
30
31 struct ShapeDescription
32 {
33   std::vector<int32_t> _dims;
34   bool _rank_known;
35 };
36
37 // TODO remove these when CircleDialect is fully functioal
38 ShapeDescription to_shape_description(const luci::CircleNode *node);
39 ShapeDescription to_shape_description(const loco::TensorShape &shape);
40 ShapeDescription to_shape_description(const loco::FeatureShape &shape);
41 ShapeDescription to_shape_description(const loco::FilterShape &shape);
42 ShapeDescription to_shape_description(const loco::BiasShape &shape);
43 ShapeDescription to_shape_description(const loco::MatrixShape &shape);
44 ShapeDescription to_shape_description(const loco::NodeShape &shape);
45
46 template <typename Permutation> inline bool isNHWC(Permutation *perm);
47
48 template <> inline bool isNHWC(loco::Permutation<loco::Domain::Feature> *perm)
49 {
50   return perm->axis(loco::FeatureAxis::Count) == 0 && perm->axis(loco::FeatureAxis::Height) == 1 &&
51          perm->axis(loco::FeatureAxis::Width) == 2 && perm->axis(loco::FeatureAxis::Depth) == 3;
52 }
53
54 template <> inline bool isNHWC(loco::Permutation<loco::Domain::Filter> *perm)
55 {
56   return perm->axis(loco::FilterAxis::Count) == 0 && perm->axis(loco::FilterAxis::Height) == 1 &&
57          perm->axis(loco::FilterAxis::Width) == 2 && perm->axis(loco::FilterAxis::Depth) == 3;
58 }
59
60 } // namespace luci
61
62 #endif // __LUCI_SHAPE_DESCRIPTION_H__