ONE - On-device Neural Engine
Loading...
Searching...
No Matches
CircleVariable.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 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
20#include <luci/Log.h>
21
22#include <cassert>
23#include <ostream>
24#include <string>
25#include <vector>
26
27namespace
28{
29
30std::ostream &operator<<(std::ostream &os, const luci::VectorWrapper<int32_t> &vect)
31{
32 uint32_t seq = 0;
33 for (const auto &v : vect)
34 {
35 if (seq)
36 os << ", ";
37 os << v;
38 seq++;
39 }
40 return os;
41}
42
43} // namespace
44
45namespace luci
46{
47
49{
50 LOGGER(l);
51
52 auto graph = context->graph();
53 auto reader = context->reader();
54 const auto tensors = reader->tensors();
55 const auto variable_tensor = tensors[tensor_index];
56 assert(variable_tensor != nullptr);
57
58 if (not variable_tensor->is_variable())
59 {
60 // not a variable
61 return nullptr;
62 }
63 {
64 // check if there is no buffer as we don't support this for now
65 // TODO use buffer when this is enabled in Kernel
66 assert(reader->buffers()[variable_tensor->buffer()] != nullptr);
67 assert(reader->buffers()[variable_tensor->buffer()]->data() == nullptr);
68 }
69
70 auto variable_node = graph->nodes()->create<CircleVariable>();
71 copy_tensor_attributes(variable_tensor, variable_node);
72 variable_node->shape_status(luci::ShapeStatus::VALID);
73
74 INFO(l) << "[luci] NodeFinder variable node(" << tensor_index << ") -> " << variable_node << " "
75 << wrap(variable_tensor->shape()) << std::endl;
76
77 return variable_node;
78}
79
80} // namespace luci
#define LOGGER(name)
Definition Log.h:65
#define INFO(name)
Definition Log.h:68
std::ostream & operator<<(std::ostream &os, const circledump::ModelEx &model)
Definition Dump.cpp:467
CircleTensors tensors() const
Virtual CircleVariable in Circle for 'variable' Tensor.
Class to store context to build loco graph IR from TensorFlow.
Wrapper to use flatbuffers::Vector pointer as std::vector entity.
void copy_tensor_attributes(const circle::Tensor *tensor, CircleNode *node)
Copy common tensor attributes such as name, type, etc. to node.
CircleVariable * create_circlevariable(GraphBuilderContext *context, int32_t tensor_index)
VectorWrapper< T > wrap(const flatbuffers::Vector< T > *vec)