#include "caffe2_op_creator.h"
#include "caffe2_proto_helper.h"
+#include "mir/ops/AddOp.h"
#include "mir/ops/BatchNormOp.h"
#include "mir/ops/CappedReluOp.h"
#include "mir/ops/ConcatOp.h"
#include "mir/ops/Conv2DOp.h"
#include "mir/ops/DepthwiseConv2DOp.h"
#include "mir/ops/DropoutOp.h"
-#include "mir/ops/ElementwiseOp.h"
#include "mir/ops/FullyConnectedOp.h"
#include "mir/ops/InputOp.h"
+#include "mir/ops/MulOp.h"
#include "mir/ops/PoolOp.h"
#include "mir/ops/ReluOp.h"
#include "mir/ops/ReshapeOp.h"
return transpose->getOutput(0);
}
-mir::Operation::Output *Caffe2OpCreator::createAdd(const std::string &name,
- mir::Operation::Output *arg1,
- mir::Operation::Output *arg2)
-{
- std::vector<mir::Operation::Output *> inputs{arg1, arg2};
- auto op = createOp<ops::ElementwiseOp>(name, inputs, ops::ElementwiseOp::OpType::add);
- return op->getOutput(0);
-}
-
-mir::Operation::Output *Caffe2OpCreator::createMul(const std::string &name,
- mir::Operation::Output *arg1,
- mir::Operation::Output *arg2)
-{
- std::vector<mir::Operation::Output *> inputs{arg1, arg2};
- auto op = createOp<ops::ElementwiseOp>(name, inputs, ops::ElementwiseOp::OpType::mul);
- return op->getOutput(0);
-}
-
//
// Check functions
//
if (getSingleArgument(op, "broadcast", 0) != 0)
{
// FIXME This only works when 'axis' == 1 and the second input is 1-D.
- std::vector<mir::Operation::Output *> transposed_inputs{convertCaffeToMIR(inputs[0]),
- inputs[1]};
- auto result = createOp<ops::ElementwiseOp>("Elementwise_Add", transposed_inputs,
- ops::ElementwiseOp::OpType::add);
+ auto result = createOp<ops::AddOp>("", convertCaffeToMIR(inputs[0]), inputs[1])->getOutput(0);
- return {convertMIRToCaffe(result->getOutput(0))};
+ return {convertMIRToCaffe(result)};
}
- auto result =
- createOp<ops::ElementwiseOp>("Elementwise_Add", inputs, ops::ElementwiseOp::OpType::add);
- return {result->getOutput(0)};
+ auto result = createOp<ops::AddOp>("", inputs[0], inputs[1])->getOutput(0);
+ return {result};
}
std::vector<mir::Operation::Output *>
Caffe2OpCreator::convertAveragePool(const std::vector<mir::Operation::Output *> &inputs,
if (op.input_size() > 2)
{
- result = createAdd("Bias_Add", result, inputs[2]);
+ result = createOp<ops::AddOp>("", result, inputs[2])->getOutput(0);
}
return {convertMIRToCaffe(result)};
auto reshape = createOp<ops::ReshapeOp>("Reshape", inputs[0], shape)->getOutput(0);
auto weights = createOp<ops::ConstantOp>("Constant", weights_tensor)->getOutput(0);
auto result = createOp<ops::FullyConnectedOp>("Fully_Connected", reshape, weights)->getOutput(0);
- result = createAdd("Bias_Add", result, inputs[2]);
+ result = createOp<ops::AddOp>("", result, inputs[2])->getOutput(0);
return {result};
}
if (getSingleArgument(op, "broadcast", 0) != 0)
{
// FIXME This only works when `axis` == 1 and the second input is 1-D.
- std::vector<mir::Operation::Output *> transposed_inputs{convertCaffeToMIR(inputs[0]),
- inputs[1]};
- auto result = createOp<ops::ElementwiseOp>("Elementwise_Mul", transposed_inputs,
- ops::ElementwiseOp::OpType::mul);
+ auto result = createOp<ops::MulOp>("", convertCaffeToMIR(inputs[0]), inputs[1])->getOutput(0);
- return {convertMIRToCaffe(result->getOutput(0))};
+ return {convertMIRToCaffe(result)};
}
- auto result =
- createOp<ops::ElementwiseOp>("Elementwise_Mul", inputs, ops::ElementwiseOp::OpType::mul);
- return {result->getOutput(0)};
+ auto result = createOp<ops::MulOp>("", inputs[0], inputs[1])->getOutput(0);
+ return {result};
}
std::vector<mir::Operation::Output *>
bias_data.at(idx) *= -1;
auto mean = createOp<ops::ConstantOp>("Constant", mean_tensor)->getOutput(0);
- auto result = createAdd("Bias_Add", convertCaffeToMIR(inputs[0]), mean);
+ auto result = createOp<ops::AddOp>("", convertCaffeToMIR(inputs[0]), mean)->getOutput(0);
// res2 = res1 * scale / (var + epsilon)
Tensor<float> multiplier(scale_tensor);
for (auto &idx : ShapeRange(scale_tensor.getShape()))
multiplier.at(idx) /= std::sqrt(*reinterpret_cast<float *>(var_tensor.at(idx)) + eps);
auto scale = createOp<ops::ConstantOp>("Constant", scale_tensor)->getOutput(0);
- result = createMul("Scale", result, scale);
+ result = createOp<ops::MulOp>("", result, scale)->getOutput(0);
// overall_res = res2 + bias
auto bias = createOp<ops::ConstantOp>("Constant", bias_tensor)->getOutput(0);
- result = createAdd("Bias_Add", result, bias);
+ result = createOp<ops::AddOp>("", result, bias)->getOutput(0);
return {convertMIRToCaffe(result)};
}
std::vector<mir::Operation::Output *>
Caffe2OpCreator::convertSum(const std::vector<mir::Operation::Output *> &inputs)
{
- const auto &input_shape = inputs[0]->getShape();
- for (auto &in : inputs)
- assert(input_shape == in->getShape() && "All Sum inputs must have same shape");
-
- auto op =
- createOp<ops::ElementwiseOp>("Elementwise_Add", inputs, ops::ElementwiseOp::OpType::add);
- return {op->getOutput(0)};
+ auto result = createOp<ops::AddOp>("", inputs[0], inputs[1])->getOutput(0);
+ for (int i = 2; i < static_cast<int>(inputs.size()); ++i)
+ {
+ result = createOp<ops::AddOp>("", result, inputs[i])->getOutput(0);
+ }
+ return {result};
}
std::vector<mir::Operation::Output *>