ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Input.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 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#include "Input.h"
18#include "Convert.h"
19
21
22#include <cassert>
23
24using namespace nncc::core::ADT;
25
28
29namespace caffeimport
30{
31
32void InputBuilder::build(const ::caffe::LayerParameter &layer, GraphBuilderContext *context) const
33{
34 coco::Module *module = context->module();
35 std::map<std::string, tensor::Shape> &shape_ctx = context->shape_ctx();
36 std::map<std::string, coco::Bag *> &bag_ctx = context->bag_ctx();
37
38 assert(layer.has_input_param());
39 const auto &param = layer.input_param();
40
41 for (uint32_t n = 0; n < layer.top_size(); ++n)
42 {
43 const auto &name = layer.top(n);
44 const auto shape = as_tensor_shape(param.shape(n));
45
46 auto bag = module->entity()->bag()->create(num_elements(shape));
47 auto input = module->entity()->input()->create(shape);
48
49 input->bag(bag);
50 input->name(name);
51 input->reorder<LexicalLayout>();
52
53 module->input()->insert(input);
54
55 bag_ctx[name] = bag;
56 shape_ctx[name] = shape;
57 }
58}
59
60} // namespace caffeimport
ShapeContext & shape_ctx()
Definition Context.h:97
void build(const ::caffe::LayerParameter &layer, GraphBuilderContext *context) const override
Definition Input.cpp:32
Top-level element of coco IR which represents a neural network.
Definition Module.h:34
tensor::Shape as_tensor_shape(const ::caffe::BlobShape &blob_shape)
Definition Convert.cpp:24
uint64_t num_elements(const Shape &)
Definition Shape.cpp:51