ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Shape.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 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 "Shape.h"
18
19#include "ONNXHelpers.h"
20
21#include "mir/TensorVariant.h"
22
23#include "mir/ops/ConstantOp.h"
24
25namespace mir_onnx
26{
27
28void convertShapeV1(const onnx::NodeProto &onnx_node, ConverterContext *context)
29{
30 std::vector<mir::Operation::Output *> inputs = context->getNodeInputs(onnx_node);
31 mir::Graph *graph = context->getGraph();
32 const auto &input_shape = inputs[0]->getShape();
33 int size = input_shape.rank();
35 std::vector<int64_t> data(static_cast<std::size_t>(size));
36 for (int i = 0; i < size; i++)
37 {
38 data[i] = input_shape.dim(i);
39 }
40 mir::TensorVariant tensor({mir::DataType::INT64, output_shape}, data.data());
41 auto result = createOp<mir::ops::ConstantOp>(graph, tensor)->getOutput(0);
42
43 context->setNodeOutputs(onnx_node, {result});
44}
45
46} // namespace mir_onnx
void setNodeOutputs(const onnx::NodeProto &onnx_node, const std::vector< mir::Operation::Output * > &outputs)
std::vector< mir::Operation::Output * > getNodeInputs(const onnx::NodeProto &onnx_node) const
const luci_interpreter::RuntimeShape output_shape
void convertShapeV1(const onnx::NodeProto &onnx_node, ConverterContext *context)
Definition Shape.cpp:28
int32_t size[5]
Definition Slice.cpp:35