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_r228804985
##########
File path: src/operator/tensor/indexing_op.cc
##########
@@ -48,6 +70,29 @@ bool CheckIndexOutOfBound(const DType* data_ptr, size_t
data_size,
return is_valid;
}
+// Embedding forward implementation with dense weight
+template<>
+void EmbeddingOpForwardDnsImpl<cpu>(mshadow::Stream<cpu>* s,
+ const TBlob& data,
+ const TBlob& weight,
+ const OpReqType req,
+ const TBlob& output) {
+ using namespace mxnet_op;
+ const TShape& ishape = data.shape_;
+ const TShape& oshape = output.shape_;
+
+ MSHADOW_TYPE_SWITCH(output.type_flag_, DType, {
+ MSHADOW_TYPE_SWITCH(data.type_flag_, IType, {
+ Tensor<cpu, 1, IType> idx = data.get_with_shape<cpu, 1, IType>(
+ Shape1(ishape.ProdShape(0, ishape.ndim())), s);
+ Tensor<cpu, 2, DType> wmat = weight.get<cpu, 2, DType>(s);
+ Tensor<cpu, 2, DType> out = output.get_with_shape<cpu, 2, DType>(
+ Shape2(oshape.ProdShape(0, oshape.ndim()-1), oshape[oshape.ndim()-1]),
s);
+ Kernel<TakeCPU<true>, cpu>::Launch(s, oshape.Size() / wmat.shape_[1],
out.dptr_, wmat.dptr_,
Review comment:
As above. What if oshape.Size() % wmat.shape_[1] != 0; the remaining
oshape.Size() % wmat.shape_[1] bit ?
----------------------------------------------------------------
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