From bd7f98467addbb17b84a76149b57eba395c596f7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=91=D0=B0=D1=80?= =?utf8?q?=D0=B0=D0=BD=D0=BD=D0=B8=D0=BA=D0=BE=D0=B2/AI=20Tools=20Lab=20/S?= =?utf8?q?RR/Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Sat, 17 Aug 2019 02:49:25 +0900 Subject: [PATCH] [mir] Remove Gemm operation (#6654) `GemmOp` is almost the same operation as `FullyConnectedOp`. Signed-off-by: Sergei Barannikov --- compiler/mir/CMakeLists.txt | 1 - compiler/mir/include/mir/IrDotDumper.h | 1 - compiler/mir/include/mir/OpDefs.h | 1 - compiler/mir/include/mir/Operations.inc | 1 - compiler/mir/include/mir/ops/GemmOp.h | 47 --------------------------------- compiler/mir/src/IrDotDumper.cpp | 9 ------- compiler/mir/src/ops/GemmOp.cpp | 41 ---------------------------- 7 files changed, 101 deletions(-) delete mode 100644 compiler/mir/include/mir/ops/GemmOp.h delete mode 100644 compiler/mir/src/ops/GemmOp.cpp diff --git a/compiler/mir/CMakeLists.txt b/compiler/mir/CMakeLists.txt index fd1809f..2711d4a 100644 --- a/compiler/mir/CMakeLists.txt +++ b/compiler/mir/CMakeLists.txt @@ -6,7 +6,6 @@ set(MIR_SOURCES src/ops/DepthwiseConv2DOp.cpp src/ops/FullyConnectedOp.cpp src/ops/GatherOp.cpp - src/ops/GemmOp.cpp src/ops/PadOp.cpp src/ops/PoolOp.cpp src/ops/SqueezeOp.cpp diff --git a/compiler/mir/include/mir/IrDotDumper.h b/compiler/mir/include/mir/IrDotDumper.h index 0a09ffa..c029981 100644 --- a/compiler/mir/include/mir/IrDotDumper.h +++ b/compiler/mir/include/mir/IrDotDumper.h @@ -40,7 +40,6 @@ public: void visit(ops::EluOp &op) override; void visit(ops::FullyConnectedOp &op) override; void visit(ops::GatherOp &op) override; - void visit(ops::GemmOp &op) override; void visit(ops::InputOp &op) override; void visit(ops::LeakyReluOp &op) override; void visit(ops::OutputOp &op) override; diff --git a/compiler/mir/include/mir/OpDefs.h b/compiler/mir/include/mir/OpDefs.h index 57e2f8d..3040d24 100644 --- a/compiler/mir/include/mir/OpDefs.h +++ b/compiler/mir/include/mir/OpDefs.h @@ -30,7 +30,6 @@ #include "mir/ops/EluOp.h" #include "mir/ops/FullyConnectedOp.h" #include "mir/ops/GatherOp.h" -#include "mir/ops/GemmOp.h" #include "mir/ops/InputOp.h" #include "mir/ops/LeakyReluOp.h" #include "mir/ops/MaxOp.h" diff --git a/compiler/mir/include/mir/Operations.inc b/compiler/mir/include/mir/Operations.inc index 736b14c..3a6b98e 100644 --- a/compiler/mir/include/mir/Operations.inc +++ b/compiler/mir/include/mir/Operations.inc @@ -30,7 +30,6 @@ HANDLE_OP(dropout, DropoutOp) HANDLE_OP(ELU, EluOp) HANDLE_OP(fullyConnected, FullyConnectedOp) HANDLE_OP(gather, GatherOp) -HANDLE_OP(gemmOp, GemmOp) HANDLE_OP(input, InputOp) HANDLE_OP(leakyReLU, LeakyReluOp) HANDLE_OP(max, MaxOp) diff --git a/compiler/mir/include/mir/ops/GemmOp.h b/compiler/mir/include/mir/ops/GemmOp.h deleted file mode 100644 index 837eae9..0000000 --- a/compiler/mir/include/mir/ops/GemmOp.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2018 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_OPS_GEMM_OP_H_ -#define _MIR_OPS_GEMM_OP_H_ - -#include "mir/Operation.h" -#include "mir/TensorVariant.h" - -namespace mir -{ -namespace ops -{ - -class GemmOp : public Operation -{ -public: - GemmOp(Output *a, Output *b, Output *c) : Operation(Type::gemmOp, {a, b, c}) - { - inferOutputShapes(); - } - - Operation *copyWithInputs(const std::vector &inputs) override - { - return new GemmOp(inputs[0], inputs[1], inputs[2]); - } - -private: - void inferOutputShapes(); -}; -} // namespace ops -} // namespace mir - -#endif //_MIR_OPS_GEMM_OP_H_ diff --git a/compiler/mir/src/IrDotDumper.cpp b/compiler/mir/src/IrDotDumper.cpp index 6185cc7..df0220e 100644 --- a/compiler/mir/src/IrDotDumper.cpp +++ b/compiler/mir/src/IrDotDumper.cpp @@ -101,15 +101,6 @@ void IrDotDumper::visit(ops::FullyConnectedOp &op) _dot_builder.updateWithOp(&op, nodeInfo); } -void IrDotDumper::visit(ops::GemmOp &op) -{ - auto nodeInfo = DotIrNodeInfo() - .withType("Gemm", op.getName()) - .withInShapes(getInputShapes(op)) - .withOutShapes(getOutputShapes(op)); - _dot_builder.updateWithOp(&op, nodeInfo); -} - void IrDotDumper::visit(ops::SoftmaxOp &op) { auto nodeInfo = DotIrNodeInfo() diff --git a/compiler/mir/src/ops/GemmOp.cpp b/compiler/mir/src/ops/GemmOp.cpp deleted file mode 100644 index 1dc9617..0000000 --- a/compiler/mir/src/ops/GemmOp.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2018 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 "mir/ops/GemmOp.h" - -namespace mir -{ -namespace ops -{ - -void GemmOp::inferOutputShapes() -{ - auto shape_a = getInputShape(0); - auto shape_b = getInputShape(1); - assert((shape_a.rank() == shape_b.rank()) && (shape_a.rank() == 2)); - assert(shape_a.dim(1) == shape_b.dim(0) && "Multiplicable"); - - Shape mult_a_b({shape_a.dim(0), shape_b.dim(1)}); - - auto shape_c = getInputShape(2); - assert((mult_a_b == shape_c) || (((shape_c.rank() == 1)) && (mult_a_b.dim(0) == 1) && - (mult_a_b.dim(1) == shape_c.dim(0)))); - - setOutputShape(0, mult_a_b); -} - -} // namespace ops -} // namespace mir -- 2.7.4