Switch to new binary elementwise operations.
Signed-off-by: Sergei Barannikov <s.barannikov@samsung.com>
#include "mir/ShapeRange.h"
#include "mir/ops/TransposeOp.h"
-#include "mir/ops/ElementwiseOp.h"
#include "onnx/onnx.pb.h"
->getOutput(0);
}
-inline mir::Operation::Output *createAdd(mir::Graph *graph, mir::Operation::Output *arg1,
- mir::Operation::Output *arg2)
-{
- std::vector<mir::Operation::Output *> inputs{arg1, arg2};
- return graph->create<mir::ops::ElementwiseOp>("", inputs, mir::ops::ElementwiseOp::OpType::add)
- ->getOutput(0);
-}
-
-inline mir::Operation::Output *createMul(mir::Graph *graph, mir::Operation::Output *arg1,
- mir::Operation::Output *arg2)
-{
- std::vector<mir::Operation::Output *> inputs{arg1, arg2};
- return graph->create<mir::ops::ElementwiseOp>("", inputs, mir::ops::ElementwiseOp::OpType::mul)
- ->getOutput(0);
-}
-
} // namespace mir_onnx
#endif // __MIR_ONNX_HELPERS_H__
#include "ONNXHelpers.h"
-#include "mir/ops/ElementwiseOp.h"
+#include "mir/ops/AddOp.h"
namespace mir_onnx
{
const std::vector<mir::Operation::Output *> &inputs,
mir::Graph *graph) const
{
- auto result =
- createOp<mir::ops::ElementwiseOp>(graph, inputs, mir::ops::ElementwiseOp::OpType::add);
- return {result->getOutput(0)};
+ auto result = createOp<mir::ops::AddOp>(graph, inputs[0], inputs[1])->getOutput(0);
+ return {result};
}
} // namespace mir_onnx
#include "mir/ShapeRange.h"
#include "mir/Tensor.h"
+#include "mir/ops/AddOp.h"
#include "mir/ops/ConstantOp.h"
+#include "mir/ops/MulOp.h"
#include <cmath>
auto data = convertONNXToMIR(graph, inputs[0]);
auto mean = createOp<mir::ops::ConstantOp>(graph, mean_tensor)->getOutput(0);
- auto result = createAdd(graph, data, mean);
+ auto result = createOp<mir::ops::AddOp>(graph, data, mean)->getOutput(0);
// res2 = res1 * scale / (var + epsilon)
mir::Tensor<float> multiplier(scale_tensor);
for (auto &idx : mir::ShapeRange(scale_tensor.getShape()))
multiplier.at(idx) /= std::sqrt(var_accessor.at(idx) + epsilon);
auto scale = createOp<mir::ops::ConstantOp>(graph, scale_tensor)->getOutput(0);
- result = createMul(graph, result, scale);
+ result = createOp<mir::ops::MulOp>(graph, result, scale)->getOutput(0);
// overall_res = res2 + bias
auto bias = createOp<mir::ops::ConstantOp>(graph, bias_tensor)->getOutput(0);
- result = createAdd(graph, result, bias);
+ result = createOp<mir::ops::AddOp>(graph, result, bias)->getOutput(0);
return {convertMIRToONNX(graph, result)};
}
#include "mir/TensorUtil.h"
+#include "mir/ops/AddOp.h"
#include "mir/ops/ConstantOp.h"
#include "mir/ops/Conv2DOp.h"
#include "mir/ops/DepthwiseConv2DOp.h"
-#include "mir/ops/ElementwiseOp.h"
namespace mir_onnx
{
if (inputs.size() > 2)
{
- result = createAdd(graph, result, inputs[2]);
+ result = createOp<mir::ops::AddOp>(graph, result, inputs[2])->getOutput(0);
}
return {convertMIRToONNX(graph, result)};
#include "mir/ops/ConstantOp.h"
#include "mir/ops/GemmOp.h"
+#include "mir/ops/MulOp.h"
#include "mir/ops/ReshapeOp.h"
#include "mir/ops/TransposeOp.h"
{
auto alpha_tensor = createScalarTensor(alpha_val, input_a->getShape());
auto alpha = createOp<mir::ops::ConstantOp>(graph, alpha_tensor)->getOutput(0);
- input_a = createMul(graph, input_a, alpha);
+ input_a = createOp<mir::ops::MulOp>(graph, input_a, alpha)->getOutput(0);
}
// 2. Prepare input matrix B
}
auto beta = createOp<mir::ops::ConstantOp>(graph, beta_tensor)->getOutput(0);
std::vector<mir::Operation::Output *> mul_inputs = {beta, input_c};
- auto c_mult = createMul(graph, beta, input_c);
+ auto c_mult = createOp<mir::ops::MulOp>(graph, beta, input_c)->getOutput(0);
assert(c_mult->getShape() == mult_a_b);
auto result = createOp<mir::ops::GemmOp>(graph, input_a, input_b, c_mult);
return {result->getOutput(0)};
#include "ONNXHelpers.h"
-#include "mir/ops/ElementwiseOp.h"
+#include "mir/ops/MaxOp.h"
namespace mir_onnx
{
const std::vector<mir::Operation::Output *> &inputs,
mir::Graph *graph) const
{
- auto result =
- createOp<mir::ops::ElementwiseOp>(graph, inputs, mir::ops::ElementwiseOp::OpType::max);
- return {result->getOutput(0)};
+ auto result = createOp<mir::ops::MaxOp>(graph, inputs[0], inputs[1])->getOutput(0);
+ return {result};
}
} // namespace mir_onnx
#include "ONNXHelpers.h"
-#include "mir/ops/ElementwiseOp.h"
+#include "mir/ops/MulOp.h"
namespace mir_onnx
{
const std::vector<mir::Operation::Output *> &inputs,
mir::Graph *graph) const
{
- auto result =
- createOp<mir::ops::ElementwiseOp>(graph, inputs, mir::ops::ElementwiseOp::OpType::mul);
- return {result->getOutput(0)};
+ auto result = createOp<mir::ops::MulOp>(graph, inputs[0], inputs[1])->getOutput(0);
+ return {result};
}
} // namespace mir_onnx
#include "ONNXHelpers.h"
+#include "mir/ops/MulOp.h"
#include "mir/ops/ConstantOp.h"
namespace mir_onnx
const auto &shape = inputs[0]->getShape();
auto scale_tensor = createScalarTensor(scale_val, shape);
auto scale = createOp<mir::ops::ConstantOp>(graph, scale_tensor)->getOutput(0);
- auto result = createMul(graph, inputs[0], scale);
+ auto result = createOp<mir::ops::MulOp>(graph, inputs[0], scale)->getOutput(0);
return {result};
}
#include "ONNXHelpers.h"
-#include "mir/ops/ElementwiseOp.h"
+#include "mir/ops/AddOp.h"
namespace mir_onnx
{
const std::vector<mir::Operation::Output *> &inputs,
mir::Graph *graph) const
{
- auto result =
- createOp<mir::ops::ElementwiseOp>(graph, inputs, mir::ops::ElementwiseOp::OpType::add);
- return {result->getOutput(0)};
+ assert(inputs.size() >= 1);
+
+ auto result = inputs[0];
+ for (int i = 1; i < static_cast<int>(inputs.size()); ++i)
+ {
+ result = createOp<mir::ops::AddOp>(graph, result, inputs[i])->getOutput(0);
+ }
+
+ return {result};
}
} // namespace mir_onnx