haojin2 commented on a change in pull request #10550: [MXNET-320] Support elemwise_add/sub between dense and csr tensors URL: https://github.com/apache/incubator-mxnet/pull/10550#discussion_r182915595
########## File path: src/operator/tensor/elemwise_binary_op-inl.h ########## @@ -374,6 +374,87 @@ void ElemwiseBinaryOp::CsrCsrOp(mshadow::Stream<cpu> *s, } } +/*! + * \brief Kernel for performing elemwise op between dense and csr matrix + * \param i global thread id + * \param req type of request + * \param out output array + * \param dns_data data array of dense input + * \param csr_data data array of csr input + * \param csr_indices indices array of csr input + * \param csr_indptr indptr array of csr input + * \param num_rows number of rows of both inputs + * \param num_cols number of columns of both inputs + */ +template<typename OP> +struct ElemwiseDnsCsrDnsKernel { + template<typename DType, typename IType, typename CType> + static void inline Map(int i, OpReqType req, DType* out, DType* dns_data, const DType* csr_data, + const IType* csr_indices, const CType* csr_indptr, + const nnvm::dim_t num_rows, const nnvm::dim_t num_cols) { + if (i < num_rows) { + for (int j = csr_indptr[i]; j < csr_indptr[i+1]; ++j) { + KERNEL_ASSIGN(out[i * num_cols + csr_indices[j]], req, + OP::Map(dns_data[i * num_cols + csr_indices[j]], csr_data[j])); + } + } + } +}; + +/*! \brief DNS -op- CSR binary operator for non-canonical NDArray */ +template<typename OP> +void ElemwiseBinaryOp::DnsCsrDnsOp(mshadow::Stream<cpu> *s, + const nnvm::NodeAttrs &attrs, + const OpContext &ctx, + const NDArray &dns, + const NDArray &csr, + const OpReqType req, + const NDArray &output, + const bool reverse) { + using namespace mshadow; + using namespace mxnet_op; + CHECK_EQ(dns.storage_type(), kDefaultStorage); + CHECK_EQ(csr.storage_type(), kCSRStorage); + CHECK(req != kAddTo); + CHECK(req != kNullOp); + const nnvm::dim_t num_csr_rows = csr.shape()[0]; Review comment: Done ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services