I have a custom operator defined in python. I need to implement this operator in C++. I followed the tutorial from https://mxnet.incubator.apache.org/versions/master/faq/add_op_in_backend.html. However, this tutorial does not provide enough information for me when I write my forward function:
The python code for the forward function is:
def forward(self, is_train, req, in_data, out_data, aux):
bbox_pred = in_data[0]
tile_shape = (bbox_pred.shape[0], self._num_anchors, bbox_pred.shape[2], bbox_pred.shape[3])
bbox_mean = mx.ndarray.tile(self._bbox_mean.as_in_context(bbox_pred.context), reps=tile_shape)
bbox_std = mx.ndarray.tile(self._bbox_std.as_in_context(bbox_pred.context), reps=tile_shape)
bbox_pred = bbox_pred * bbox_std + bbox_mean
self.assign(out_data[0], req[0], bbox_pred)
Currently, I have:
template<typename xpu>
void RpnInvNormalizeOpForward(const nnvm::NodeAttrs& attrs,
const OpContext& ctx,
const std::vector<TBlob>& inputs,
const std::vector<OpReqType>& req,
const std::vector<TBlob>& outputs) {
mshadow::Stream<xpu> *s = ctx.get_stream<xpu>();
const TBlob& in_data = inputs[0];
const TBlob& outdata = outputs[0];
const RpnInvNormalizeParam& param = nnvm::get<RpnInvNormalizeParam>(attrs.parsed);
using namespace mxnet_op;
MSHADOW_TYPE_SWITCH(out_data.type_flag_, DType, {
MXNET_ASSIGN_REQ_SWITCH(req[0], req_type, {
});
});
}
How can I implement the same forward function in C? Are there any materials that I can learn more about defining custom operators?