2 * Copyright (c) 2023 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.
17 #ifndef __LUCI_PASS_HELPERS_CREATE_CIRCLE_CONST_H__
18 #define __LUCI_PASS_HELPERS_CREATE_CIRCLE_CONST_H__
20 #include <luci/IR/CircleNodes.h>
22 #include "TypeMapper.h"
29 // Create CircleConst filled with a single value
30 // Never return nullptr
31 // TODO Remove dtype from the argument
33 CircleConst *create_const_node(loco::Graph *g, const loco::DataType dtype,
34 const std::vector<uint32_t> &shape, const T value)
36 auto node = g->nodes()->create<CircleConst>();
38 node->rank(shape.size());
41 for (uint32_t i = 0; i < shape.size(); ++i)
43 node->dim(i) = shape.at(i);
46 node->shape_status(ShapeStatus::VALID);
48 node->size<TypeMapper<T>::get()>(size);
49 for (uint32_t i = 0; i < size; i++)
51 node->at<TypeMapper<T>::get()>(i) = value;
57 // Create CircleConst filled with values
58 // Never return nullptr
59 // TODO Remove dtype from the argument
61 luci::CircleConst *create_const_node(loco::Graph *g, const loco::DataType dtype,
62 const std::vector<uint32_t> &shape,
63 const std::vector<T> &values)
65 auto node = g->nodes()->create<luci::CircleConst>();
67 node->rank(shape.size());
70 for (uint32_t i = 0; i < shape.size(); ++i)
72 node->dim(i) = shape.at(i);
75 node->shape_status(luci::ShapeStatus::VALID);
77 node->size<TypeMapper<T>::get()>(size);
78 for (uint32_t i = 0; i < size; i++)
80 node->at<TypeMapper<T>::get()>(i) = values[i];
88 #endif // __LUCI_PASS_HELPERS_CREATE_CIRCLE_CONST_H__