ONE - On-device Neural Engine
Loading...
Searching...
No Matches
CircleUnpack.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
21
22#include <luci/UserSettings.h>
23#include <luci/Log.h>
24
25#include <loco.h>
26#include <oops/UserExn.h>
27
28namespace luci
29{
30
32{
33 LOGGER(l);
34
35 auto settings = luci::UserSettings::settings();
36
37 const auto &inputs = args.op.inputs;
38 const auto &outputs = args.op.outputs;
39 const auto *options = args.op.builtin_options.AsUnpackOptions();
40
41 if (inputs.size() != 1)
42 return false;
43
44 // NOTE real models may have mismatch
45 if (static_cast<int32_t>(outputs.size()) != options->num)
46 {
48 {
49 const auto tensors = args.reader.tensors();
50 const auto output_tensor = tensors[outputs[0]];
51 auto name = tensor_name(output_tensor);
52 WARN(l) << "Warning: import Unpack(" << name << ") 'num' is not same as outputs used";
53 }
54 else
55 return false;
56 }
57
58 if (options->num < 0)
59 return false;
60
61 const auto tensors = args.reader.tensors();
62 const auto tensor = tensors.at(inputs.at(0));
63 assert(tensor != nullptr);
64 const auto shape = wrap(tensor->shape());
65 auto shape_size = static_cast<int32_t>(shape.size());
66 if (shape_size > 0)
67 {
68 // NOTE for unknown shape, shape_size is 0
69 if (options->axis < -shape_size || options->axis >= shape_size)
70 return false;
71 }
72
73 return true;
74}
75
92CircleNode *CircleUnpackGraphBuilder::build_node(const BuildNodeArgs &bna) const
93{
94 auto node = bna.context->graph()->nodes()->create<CircleUnpack>();
95
96 node->value(bna.input_nodes[0]);
97
98 const auto *options = bna.op.builtin_options.AsUnpackOptions();
99 node->num(options->num);
100 node->axis(options->axis);
101
102 return node;
103}
104
105CircleNode *CircleUnpackGraphBuilder::build_out(const BuildOutArgs &boa) const
106{
107 auto *nodeout = boa.node->graph()->nodes()->create<CircleUnpackOut>();
108
109 nodeout->input(boa.node);
110 nodeout->index(boa.index);
111
112 return nodeout;
113}
114
115} // namespace luci
#define LOGGER(name)
Definition Log.h:65
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
UNPACK in Circle.
loco::Node * value(void) const
#define WARN(name)
Definition Log.h:70
const char * tensor_name(const circle::Tensor *tensor)
VectorWrapper< T > wrap(const flatbuffers::Vector< T > *vec)
static UserSettings * settings()