summaryrefslogtreecommitdiff
path: root/compiler/mir-onnx-importer/Op/Pad.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/mir-onnx-importer/Op/Pad.cpp')
-rw-r--r--compiler/mir-onnx-importer/Op/Pad.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/compiler/mir-onnx-importer/Op/Pad.cpp b/compiler/mir-onnx-importer/Op/Pad.cpp
new file mode 100644
index 000000000..c3d3a6860
--- /dev/null
+++ b/compiler/mir-onnx-importer/Op/Pad.cpp
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "Pad.h"
+
+#include "ONNXHelpers.h"
+
+#include "mir/ops/PadOp.h"
+
+namespace mir_onnx
+{
+
+std::vector<mir::Operation::Output *>
+PadNodeConverter::convert(const onnx::NodeProto &onnx_node,
+ const std::vector<mir::Operation::Output *> &inputs,
+ mir::Graph *graph) const
+{
+ bool found;
+ float value;
+ std::tie(found, value) = getFloatAttribute(onnx_node, "value");
+ assert(found);
+ auto padsAtt = findAttribute(onnx_node, "pads");
+ assert(padsAtt);
+ auto modeAtt = findAttribute(onnx_node, "mode");
+ assert(modeAtt);
+ auto mode = modeAtt->s();
+ const mir::Scalar scalar(reinterpret_cast<const char *>(&value), mir::DTYPE::FLOAT32,
+ sizeof(float));
+ assert(padsAtt->ints_size() > 0);
+ int axis_size = padsAtt->ints_size() / 2;
+ std::vector<std::pair<int32_t, int32_t>> vec(axis_size);
+ auto *data = padsAtt->ints().data();
+ for (int i = 0; i < axis_size; i++)
+ {
+ auto pair = std::make_pair(data[i], data[axis_size + i]);
+ vec[i] = pair;
+ }
+ auto result =
+ createOp<mir::ops::PadOp>(graph, inputs[0], inputs[0]->getShape().rank(), vec, scalar);
+ return {result->getOutput(0)};
+}
+
+} // namespace mir_onnx