rongzha1 commented on a change in pull request #12997: A better take forward
kernel for CPU
URL: https://github.com/apache/incubator-mxnet/pull/12997#discussion_r228805617
##########
File path: src/operator/tensor/indexing_op.cc
##########
@@ -227,6 +272,74 @@ void TakeOpForwardCsrImpl<cpu>(const TakeParam& params,
});
}
+template<>
+void TakeOpForward<cpu>(const nnvm::NodeAttrs& attrs,
+ const OpContext& ctx,
+ const std::vector<TBlob>& inputs,
+ const std::vector<OpReqType>& req,
+ const std::vector<TBlob>& outputs) {
+ using namespace mxnet_op;
+ if (req[take_::kOut] == kNullOp) return;
+ const TakeParam& param = nnvm::get<TakeParam>(attrs.parsed);
+ CHECK_EQ(inputs.size(), 2U);
+ CHECK_EQ(outputs.size(), 1U);
+
+ const TShape& idxshape = inputs[take_::kIdx].shape_;
+ const TShape& arrshape = inputs[take_::kArr].shape_;
+ const TShape& oshape = outputs[take_::kOut].shape_;
+
+ Stream<cpu> *s = ctx.get_stream<cpu>();
+ const int actual_axis = param.axis + ((param.axis < 0) ? arrshape.ndim() :
0);
+
+ MSHADOW_TYPE_SWITCH(outputs[0].type_flag_, DType, { // output data type
+ MSHADOW_TYPE_SWITCH(inputs[1].type_flag_, IType, { // index data type
+ if (actual_axis == 0) {
+ if (param.mode == take_::kClip) {
+ Kernel<TakeCPU<true>, cpu>::Launch(s, idxshape.Size(),
+
outputs[take_::kOut].dptr<DType>(),
+ inputs[take_::kArr].dptr<DType>(),
+ inputs[take_::kIdx].dptr<IType>(),
+ oshape.Size()/idxshape.Size(),
arrshape[0]);
+ } else {
+ Kernel<TakeCPU<false>, cpu>::Launch(s, idxshape.Size(),
Review comment:
same as above. What if oshape.Size()%idxshape.Size() != 0?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services