You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2019/12/09 03:31:00 UTC

[GitHub] [incubator-mxnet] sxjscience commented on issue #16990: [numpy] add op matmul

sxjscience commented on issue #16990: [numpy] add op matmul
URL: https://github.com/apache/incubator-mxnet/pull/16990#issuecomment-563047925
 
 
   I think you may call the BatchedGEMMStrided Kernel directly: https://devblogs.nvidia.com/cublas-strided-batched-matrix-multiply/
   
   Get Outlook for iOS<https://aka.ms/o0ukef>
   ________________________________
   From: JiangZhaoh <no...@github.com>
   Sent: Sunday, December 8, 2019 6:04:32 PM
   To: apache/incubator-mxnet <in...@noreply.github.com>
   Cc: Xingjian SHI <xs...@connect.ust.hk>; Comment <co...@noreply.github.com>
   Subject: Re: [apache/incubator-mxnet] [numpy] add op matmul (#16990)
   
   
   @JiangZhaoh commented on this pull request.
   
   ________________________________
   
   In src/operator/numpy/np_matmul_op-inl.h<https://github.com/apache/incubator-mxnet/pull/16990#discussion_r355237851>:
   
   > +            It is treated as a stack of matrices residing in the last two indexes and broadcast accordingly.
   +   * \param out - output: insert 'value' to 'arr' according to 'index'.
   +   * \param a - input: the first argument.
   +   * \param b - input: the second argument.
   +   * \param ndim - ndim of a, b and output. Because of broadcast, regard their ndim as equal.
   +   */
   +  template<typename DType>
   +  MSHADOW_XINLINE static void Map(int i, DType* out,
   +                                  const DType* a, const DType* b,
   +                                  const mshadow::Shape<10> a_stride,
   +                                  const mshadow::Shape<10> b_stride,
   +                                  const mshadow::Shape<10> out_stride,
   +                                  const mshadow::Shape<10> a_shape,
   +                                  const mshadow::Shape<10> b_shape,
   +                                  const mshadow::Shape<10> out_shape,
   +                                  const size_t ndim){
   
   
   You may refer to the implementation of batch_dot. There is no need to store the strides and shapes as Shape<10>. You can reshape the array to a 3D array and just dot the last two dimensions:
   
   https://github.com/apache/incubator-mxnet/blob/1aa1b5a9ab53bb57a3c653793fb824d01f2d5e81/src/operator/tensor/dot-inl.h#L1348-L1409
   
   Thanks for your advice. But, may I ask how could I broadcast the shape if I don't store strides and shapes?
   e.g. Matrix A in shape (2, 1, 3, 4, 5) and matrix B in shape (3, 1, 5, 2), C=np.matmul(A, B) would broadcast A and B to shape (2, 3, 3, 4, 5) and (3, 3, 5, 2) respectively, and C's shape would be (2, 3, 3, 4, 2).
   If I didn't store shape and stride, I think I should copy the content in each array to get the consistent shape firstly, and use your method then. Is this your mean?
   
   —
   You are receiving this because you commented.
   Reply to this email directly, view it on GitHub<https://github.com/apache/incubator-mxnet/pull/16990?email_source=notifications&email_token=ABHQH3VQJPJ2ICENM5STTDTQXWRTBA5CNFSM4JWMPQEKYY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOCOLORVI#discussion_r355237851>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ABHQH3R4ZQCQQAG34ABFOA3QXWRTBANCNFSM4JWMPQEA>.
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services