949cce5353d0e194881ba9a1ed9645e0c574f4b2
[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 <cstdint>
24 #include <vector>
25
26 namespace luci
27 {
28
29 struct ShapeDescription
30 {
31   std::vector<int32_t> _dims;
32   bool _rank_known;
33 };
34
35 // TODO remove these when CircleDialect is fully functioal
36 ShapeDescription to_shape_description(const loco::TensorShape &shape);
37 ShapeDescription to_shape_description(const loco::FeatureShape &shape);
38 ShapeDescription to_shape_description(const loco::FilterShape &shape);
39 ShapeDescription to_shape_description(const loco::BiasShape &shape);
40 ShapeDescription to_shape_description(const loco::MatrixShape &shape);
41 ShapeDescription to_shape_description(const loco::NodeShape &shape);
42
43 template <typename Permutation> inline bool isNHWC(Permutation *perm);
44
45 template <> inline bool isNHWC(loco::Permutation<loco::Domain::Feature> *perm)
46 {
47   return perm->axis(loco::FeatureAxis::Count) == 0 && perm->axis(loco::FeatureAxis::Height) == 1 &&
48          perm->axis(loco::FeatureAxis::Width) == 2 && perm->axis(loco::FeatureAxis::Depth) == 3;
49 }
50
51 template <> inline bool isNHWC(loco::Permutation<loco::Domain::Filter> *perm)
52 {
53   return perm->axis(loco::FilterAxis::Count) == 0 && perm->axis(loco::FilterAxis::Height) == 1 &&
54          perm->axis(loco::FilterAxis::Width) == 2 && perm->axis(loco::FilterAxis::Depth) == 3;
55 }
56
57 } // namespace luci
58
59 #endif // __LUCI_SHAPE_DESCRIPTION_H__