[mir-onnx-importer] Import comparison operations from ONNX format (#9339)
authorGusev Dmitry/AI Tools Lab /SRR/Engineer/Samsung Electronics <d.gusev@partner.samsung.com>
Tue, 3 Dec 2019 16:21:48 +0000 (19:21 +0300)
committerAlexander Efimov/AI Tools Lab /SRR/Engineer/Samsung Electronics <a.efimov@samsung.com>
Tue, 3 Dec 2019 16:21:48 +0000 (19:21 +0300)
Operation Greater, Less, Equal were added.

Signed-off-by: Dmitry Gusev <d.gusev@partner.samsung.com>
compiler/mir-onnx-importer/CMakeLists.txt
compiler/mir-onnx-importer/ONNXOpRegistration.h
compiler/mir-onnx-importer/Op/Equal.cpp [new file with mode: 0644]
compiler/mir-onnx-importer/Op/Equal.h [new file with mode: 0644]
compiler/mir-onnx-importer/Op/Greater.cpp [new file with mode: 0644]
compiler/mir-onnx-importer/Op/Greater.h [new file with mode: 0644]
compiler/mir-onnx-importer/Op/Less.cpp [new file with mode: 0644]
compiler/mir-onnx-importer/Op/Less.h [new file with mode: 0644]

index a6f2dda..21b2592 100644 (file)
@@ -45,14 +45,20 @@ set(MIR_ONNX_IMPORTER_SOURCES
         Op/ConvTranspose.h
         Op/Dropout.cpp
         Op/Dropout.h
+        Op/Equal.cpp
+        Op/Equal.h
         Op/Flatten.cpp
         Op/Flatten.h
         Op/Gather.cpp
         Op/Gather.h
+        Op/Greater.cpp
+        Op/Greater.h
         Op/Gemm.cpp
         Op/Gemm.h
         Op/Identity.cpp
         Op/Identity.h
+        Op/Less.cpp
+        Op/Less.h
         Op/MatMul.cpp
         Op/MatMul.h
         Op/GlobalAveragePool.cpp
index 2014fbc..7868162 100644 (file)
 #include "Op/Conv.h"
 #include "Op/ConvTranspose.h"
 #include "Op/Dropout.h"
+#include "Op/Equal.h"
 #include "Op/Flatten.h"
 #include "Op/Gather.h"
+#include "Op/Greater.h"
 #include "Op/Gemm.h"
 #include "Op/GlobalAveragePool.h"
 #include "Op/Identity.h"
+#include "Op/Less.h"
 #include "Op/MatMul.h"
 #include "Op/Max.h"
 #include "Op/MaxPool.h"
@@ -67,12 +70,15 @@ inline void registerSupportedOps()
   registry.registerConverter("Conv", stdex::make_unique<ConvNodeConverter>());
   registry.registerConverter("ConvTranspose", stdex::make_unique<ConvTransposeNodeConverter>());
   registry.registerConverter("Dropout", stdex::make_unique<DropoutNodeConverter>());
+  registry.registerConverter("Equal", stdex::make_unique<EqualNodeConverter>());
   registry.registerConverter("Flatten", stdex::make_unique<FlattenNodeConverter>());
   registry.registerConverter("Gather", stdex::make_unique<GatherNodeConverter>());
+  registry.registerConverter("Greater", stdex::make_unique<GreaterNodeConverter>());
   registry.registerConverter("Gemm", stdex::make_unique<GemmNodeConverter>());
   registry.registerConverter("GlobalAveragePool",
                              stdex::make_unique<GlobalAveragePoolNodeConverter>());
   registry.registerConverter("Identity", stdex::make_unique<IdentityNodeConverter>());
+  registry.registerConverter("Less", stdex::make_unique<LessNodeConverter>());
   registry.registerConverter("MatMul", stdex::make_unique<MatMulNodeConverter>());
   registry.registerConverter("Max", stdex::make_unique<MaxNodeConverter>());
   registry.registerConverter("MaxPool", stdex::make_unique<MaxPoolNodeConverter>());
diff --git a/compiler/mir-onnx-importer/Op/Equal.cpp b/compiler/mir-onnx-importer/Op/Equal.cpp
new file mode 100644 (file)
index 0000000..26f2b0e
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * 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 "Equal.h"
+
+#include "ONNXHelpers.h"
+#include "AttributeHelpers.h"
+
+#include "mir/ops/EqualOp.h"
+
+namespace mir_onnx
+{
+
+void EqualNodeConverter::convert(const onnx::NodeProto &onnx_node, ConverterContext *context) const
+{
+  std::vector<mir::Operation::Output *> inputs = context->getNodeInputs(onnx_node);
+  mir::Graph *graph = context->getGraph();
+
+  auto result = createOp<mir::ops::EqualOp>(graph, inputs[0], inputs[1])->getOutput(0);
+
+  context->setNodeOutputs(onnx_node, {result});
+}
+
+} // namespace mir_onnx
diff --git a/compiler/mir-onnx-importer/Op/Equal.h b/compiler/mir-onnx-importer/Op/Equal.h
new file mode 100644 (file)
index 0000000..eacd706
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * 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.
+ */
+
+#ifndef MIR_ONNX_OP_EQUAL_H
+#define MIR_ONNX_OP_EQUAL_H
+
+#include "ONNXNodeConverterRegistry.h"
+
+namespace mir_onnx
+{
+
+class EqualNodeConverter : public NodeConverter
+{
+public:
+  void convert(const onnx::NodeProto &onnx_node, ConverterContext *context) const override;
+};
+
+} // namespace mir_onnx
+
+#endif // MIR_ONNX_OP_EQUAL_H
diff --git a/compiler/mir-onnx-importer/Op/Greater.cpp b/compiler/mir-onnx-importer/Op/Greater.cpp
new file mode 100644 (file)
index 0000000..710fa24
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * 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 "Greater.h"
+
+#include "ONNXHelpers.h"
+#include "AttributeHelpers.h"
+
+#include "mir/ops/GreaterOp.h"
+
+namespace mir_onnx
+{
+
+void GreaterNodeConverter::convert(const onnx::NodeProto &onnx_node,
+                                   ConverterContext *context) const
+{
+  std::vector<mir::Operation::Output *> inputs = context->getNodeInputs(onnx_node);
+  mir::Graph *graph = context->getGraph();
+
+  auto result = createOp<mir::ops::GreaterOp>(graph, inputs[0], inputs[1])->getOutput(0);
+
+  context->setNodeOutputs(onnx_node, {result});
+}
+
+} // namespace mir_onnx
diff --git a/compiler/mir-onnx-importer/Op/Greater.h b/compiler/mir-onnx-importer/Op/Greater.h
new file mode 100644 (file)
index 0000000..191d620
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * 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.
+ */
+
+#ifndef MIR_ONNX_OP_GREATER_H
+#define MIR_ONNX_OP_GREATER_H
+
+#include "ONNXNodeConverterRegistry.h"
+
+namespace mir_onnx
+{
+
+class GreaterNodeConverter : public NodeConverter
+{
+public:
+  void convert(const onnx::NodeProto &onnx_node, ConverterContext *context) const override;
+};
+
+} // namespace mir_onnx
+
+#endif // MIR_ONNX_OP_GREATER_H
diff --git a/compiler/mir-onnx-importer/Op/Less.cpp b/compiler/mir-onnx-importer/Op/Less.cpp
new file mode 100644 (file)
index 0000000..2ca5aa4
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * 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 "Less.h"
+
+#include "ONNXHelpers.h"
+#include "AttributeHelpers.h"
+
+#include "mir/ops/LessOp.h"
+
+namespace mir_onnx
+{
+
+void LessNodeConverter::convert(const onnx::NodeProto &onnx_node, ConverterContext *context) const
+{
+  std::vector<mir::Operation::Output *> inputs = context->getNodeInputs(onnx_node);
+  mir::Graph *graph = context->getGraph();
+
+  auto result = createOp<mir::ops::LessOp>(graph, inputs[0], inputs[1])->getOutput(0);
+
+  context->setNodeOutputs(onnx_node, {result});
+}
+
+} // namespace mir_onnx
diff --git a/compiler/mir-onnx-importer/Op/Less.h b/compiler/mir-onnx-importer/Op/Less.h
new file mode 100644 (file)
index 0000000..17ec5d1
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * 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.
+ */
+
+#ifndef MIR_ONNX_OP_LESS_H
+#define MIR_ONNX_OP_LESS_H
+
+#include "ONNXNodeConverterRegistry.h"
+
+namespace mir_onnx
+{
+
+class LessNodeConverter : public NodeConverter
+{
+public:
+  void convert(const onnx::NodeProto &onnx_node, ConverterContext *context) const override;
+};
+
+} // namespace mir_onnx
+
+#endif // MIR_ONNX_OP_LESS_H