const auto ofm_index{node.getOutputs().at(0)};
const auto ifm_index{node.getInputs().at(model::operation::MaxPool2DNode::Input::INPUT)};
- const auto kh_index{node.param().kh_index};
- const auto kw_index{node.param().kw_index};
-
- const auto vstride_index{node.param().vstride_index};
- const auto hstride_index{node.param().hstride_index};
-
const auto ofm_shape = _ctx.at(ofm_index).shape().asFeature();
const auto ifm_shape = _ctx.at(ifm_index).shape().asFeature();
- const int32_t kh = _ctx.at(kh_index).asScalar<int32_t>();
- const int32_t kw = _ctx.at(kw_index).asScalar<int32_t>();
-
- const int32_t vstride = _ctx.at(vstride_index).asScalar<int32_t>();
- const int32_t hstride = _ctx.at(hstride_index).asScalar<int32_t>();
-
// Construct operation parameters
struct Param
{
param.ofm_index = ofm_index;
param.ifm_index = ifm_index;
- param.kh = kh;
- param.kw = kw;
-
- param.stride.vertical = vstride;
- param.stride.horizontal = hstride;
-
+ param.kh = node.param().kh;
+ param.kw = node.param().kw;
+ param.stride = node.param().stride;
param.padding = neurun::util::calculatePadding(node.param().padding, ifm_shape, ofm_shape,
- param.stride, kw, kh);
+ param.stride, param.kw, param.kh);
param.activation = node.param().activation;
VERBOSE(MaxPool2D) << "IFM_H: " << ifm_shape.H << std::endl;
VERBOSE(MaxPool2D) << "IFM_W: " << ifm_shape.W << std::endl;
VERBOSE(MaxPool2D) << "OFM_H: " << ofm_shape.H << std::endl;
VERBOSE(MaxPool2D) << "OFM_W: " << ofm_shape.W << std::endl;
- VERBOSE(MaxPool2D) << "KER_H: " << kh << std::endl;
- VERBOSE(MaxPool2D) << "KER_W: " << kw << std::endl;
- VERBOSE(MaxPool2D) << "STRIDE_H: " << vstride << std::endl;
- VERBOSE(MaxPool2D) << "STRIDE_W: " << hstride << std::endl;
+ VERBOSE(MaxPool2D) << "KER_H: " << param.kh << std::endl;
+ VERBOSE(MaxPool2D) << "KER_W: " << param.kw << std::endl;
+ VERBOSE(MaxPool2D) << "STRIDE_H: " << param.stride.vertical << std::endl;
+ VERBOSE(MaxPool2D) << "STRIDE_W: " << param.stride.horizontal << std::endl;
VERBOSE(MaxPool2D) << "PAD(T): " << param.padding.top << std::endl;
VERBOSE(MaxPool2D) << "PAD(B): " << param.padding.bottom << std::endl;
VERBOSE(MaxPool2D) << "PAD(L): " << param.padding.left << std::endl;
const auto ofm_index{node.getOutputs().at(0)};
const auto ifm_index{node.getInputs().at(model::operation::MaxPool2DNode::Input::INPUT)};
- const auto kh_index{node.param().kh_index};
- const auto kw_index{node.param().kw_index};
-
- const auto vstride_index{node.param().vstride_index};
- const auto hstride_index{node.param().hstride_index};
-
const auto ofm_shape = _ctx.at(ofm_index).shape().asFeature();
const auto ifm_shape = _ctx.at(ifm_index).shape().asFeature();
- const int32_t kh = _ctx.at(kh_index).asScalar<int32_t>();
- const int32_t kw = _ctx.at(kw_index).asScalar<int32_t>();
-
- const int32_t vstride = _ctx.at(vstride_index).asScalar<int32_t>();
- const int32_t hstride = _ctx.at(hstride_index).asScalar<int32_t>();
-
// Construct operation parameters
struct Param
{
param.ofm_index = ofm_index;
param.ifm_index = ifm_index;
- param.kh = kh;
- param.kw = kw;
-
- param.stride.vertical = vstride;
- param.stride.horizontal = hstride;
-
+ param.kh = node.param().kh;
+ param.kw = node.param().kw;
+ param.stride = node.param().stride;
param.padding = neurun::util::calculatePadding(node.param().padding, ifm_shape, ofm_shape,
- param.stride, kw, kh);
+ param.stride, param.kw, param.kh);
param.activation = node.param().activation;
VERBOSE(MaxPool2D) << "IFM_H: " << ifm_shape.H << std::endl;
VERBOSE(MaxPool2D) << "IFM_W: " << ifm_shape.W << std::endl;
VERBOSE(MaxPool2D) << "OFM_H: " << ofm_shape.H << std::endl;
VERBOSE(MaxPool2D) << "OFM_W: " << ofm_shape.W << std::endl;
- VERBOSE(MaxPool2D) << "KER_H: " << kh << std::endl;
- VERBOSE(MaxPool2D) << "KER_W: " << kw << std::endl;
- VERBOSE(MaxPool2D) << "STRIDE_H: " << vstride << std::endl;
- VERBOSE(MaxPool2D) << "STRIDE_W: " << hstride << std::endl;
+ VERBOSE(MaxPool2D) << "KER_H: " << param.kh << std::endl;
+ VERBOSE(MaxPool2D) << "KER_W: " << param.kw << std::endl;
+ VERBOSE(MaxPool2D) << "STRIDE_H: " << param.stride.vertical << std::endl;
+ VERBOSE(MaxPool2D) << "STRIDE_W: " << param.stride.horizontal << std::endl;
VERBOSE(MaxPool2D) << "PAD(T): " << param.padding.top << std::endl;
VERBOSE(MaxPool2D) << "PAD(B): " << param.padding.bottom << std::endl;
VERBOSE(MaxPool2D) << "PAD(L): " << param.padding.left << std::endl;
const auto ofm_index{node.getOutputs().at(0)};
const auto ifm_index{node.getInputs().at(model::operation::MaxPool2DNode::Input::INPUT)};
- const auto kh_index{node.param().kh_index};
- const auto kw_index{node.param().kw_index};
-
- const auto vstride_index{node.param().vstride_index};
- const auto hstride_index{node.param().hstride_index};
-
- const int32_t kh = _ctx.at(kh_index).asScalar<int32_t>();
- const int32_t kw = _ctx.at(kw_index).asScalar<int32_t>();
-
- const int32_t vstride = _ctx.at(vstride_index).asScalar<int32_t>();
- const int32_t hstride = _ctx.at(hstride_index).asScalar<int32_t>();
+ const auto ifm_shape = _ctx.at(ifm_index).shape().asFeature();
+ const auto ofm_shape = _ctx.at(ofm_index).shape().asFeature();
// Construct operation parameters
struct Param
param.ofm_index = ofm_index;
param.ifm_index = ifm_index;
- param.kh = kh;
- param.kw = kw;
+ param.kh = node.param().kh;
+ param.kw = node.param().kw;
param.ofm_shape = ::neurun::backend::cpu::kernel::getShape(_ctx.at(ofm_index));
param.ifm_shape = ::neurun::backend::cpu::kernel::getShape(_ctx.at(ifm_index));
- param.stride.vertical = vstride;
- param.stride.horizontal = hstride;
-
- const auto ifm_shape = _ctx.at(ifm_index).shape().asFeature();
- const auto ofm_shape = _ctx.at(ofm_index).shape().asFeature();
+ param.stride = node.param().stride;
param.padding = neurun::util::calculatePadding(node.param().padding, ifm_shape, ofm_shape,
- param.stride, kw, kh);
+ param.stride, param.kw, param.kh);
param.activation = node.param().activation;
auto tensors = _tensor_builder;
struct Param
{
- OperandIndex kw_index;
- OperandIndex kh_index;
+ uint32_t kw;
+ uint32_t kh;
Stride stride;
- // hstride_index and vtride_index will be deprecated
- OperandIndex hstride_index;
- OperandIndex vstride_index;
-
Padding padding;
Activation activation;
};
return stride;
}
+uint32_t getUint32Scalar(Operands &operands, const OperandIndex index)
+{
+ auto int32_value = operands.at(index).asScalar<int32_t>();
+ if (int32_value < 0)
+ {
+ throw std::runtime_error{"Cannot handle negative value"};
+ }
+
+ return static_cast<uint32_t>(int32_value);
+}
+
} // namespace
OperationFactory &OperationFactory::instance()
// 6 -> FuseCode (activation) Index
const auto padding_index = OperandIndex{init_param.inputs[1]};
+ const auto hstride_index = OperandIndex{init_param.inputs[2]};
+ const auto vstride_index = OperandIndex{init_param.inputs[3]};
+ const auto kw_index = OperandIndex{init_param.inputs[4]};
+ const auto kh_index = OperandIndex{init_param.inputs[5]};
const auto activation_index = OperandIndex{init_param.inputs[6]};
param.padding.type =
NNAPIConvert::getPaddingType(operands.at(padding_index).asScalar<PaddingCode>());
-
- param.hstride_index = OperandIndex{init_param.inputs[2]};
- param.vstride_index = OperandIndex{init_param.inputs[3]};
-
- param.kw_index = OperandIndex{init_param.inputs[4]};
- param.kh_index = OperandIndex{init_param.inputs[5]};
+ param.stride = makeStride(operands, hstride_index, vstride_index);
+ param.kw = getUint32Scalar(operands, kw_index);
+ param.kh = operands.at(kh_index).asScalar<uint32_t>();
param.activation =
NNAPIConvert::getFusedActivation(operands.at(activation_index).asScalar<FuseCode>());
}
const auto padding_right_index = OperandIndex{init_param.inputs[2]};
const auto padding_top_index = OperandIndex{init_param.inputs[3]};
const auto padding_bottom_index = OperandIndex{init_param.inputs[4]};
+ const auto hstride_index = OperandIndex{init_param.inputs[5]};
+ const auto vstride_index = OperandIndex{init_param.inputs[6]};
+ const auto kw_index = OperandIndex{init_param.inputs[7]};
+ const auto kh_index = OperandIndex{init_param.inputs[8]};
const auto activation_index = OperandIndex{init_param.inputs[9]};
param.padding.type = PaddingType::EXPLICIT;
param.padding.param = makeExplicitPadding(operands, padding_left_index, padding_right_index,
padding_top_index, padding_bottom_index);
- param.hstride_index = OperandIndex{init_param.inputs[5]};
- param.vstride_index = OperandIndex{init_param.inputs[6]};
-
- param.kw_index = OperandIndex{init_param.inputs[7]};
- param.kh_index = OperandIndex{init_param.inputs[8]};
+ param.stride = makeStride(operands, hstride_index, vstride_index);
+ param.kw = getUint32Scalar(operands, kw_index);
+ param.kh = getUint32Scalar(operands, kh_index);
param.activation =
NNAPIConvert::getFusedActivation(operands.at(activation_index).asScalar<FuseCode>());
}