ONE - On-device Neural Engine
Loading...
Searching...
No Matches
CircleCustom.cpp
Go to the documentation of this file.
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
18
19#include <loco.h>
20
21namespace luci
22{
23
25{
26 // DO NOTHING
27 return true;
28}
29
30CircleNode *CircleCustomGraphBuilder::build_node(const BuildNodeArgs &bna) const
31{
32 uint32_t input_count = bna.op.inputs.size();
33 uint32_t output_count = bna.op.outputs.size();
34
35 auto *node = bna.context->graph()->nodes()->create<CircleCustom>(input_count, output_count);
36
37 for (uint32_t idx = 0; idx < input_count; ++idx)
38 {
39 node->inputs(idx, bna.input_nodes[idx]);
40 }
41
42 const auto opcodes = bna.context->reader()->opcodes();
43 const uint32_t opcode_index = bna.op.opcode_index;
44 const auto opcode = opcodes[opcode_index];
45 assert(opcode != nullptr);
46
47 node->custom_options(
48 std::vector<uint8_t>{bna.op.custom_options.begin(), bna.op.custom_options.end()});
49 assert(opcode->custom_code() != nullptr);
50 node->custom_code(opcode->custom_code()->c_str());
51
52 // NOTE Operator version of custom is always 1
53
54 return node;
55}
56
57CircleNode *CircleCustomGraphBuilder::build_out(const BuildOutArgs &boa) const
58{
59 auto *nodeout = boa.node->graph()->nodes()->create<CircleCustomOut>();
60
61 nodeout->input(boa.node);
62 nodeout->index(boa.index);
63
64 return nodeout;
65}
66
67} // namespace luci
NodeContext * nodes(void)
Definition Graph.h:218
Graph * graph(void)
Definition Node.h:70
Derived * create(Args &&...args)
Definition NodePool.h:37
bool validate(const ValidateArgs &args) const final
CUSTOM in Circle.
Node * inputs(uint32_t index) const