From bd53175a16cfe8e6f3f0b47d5ef5cae81814df38 Mon Sep 17 00:00:00 2001 From: reminisce Date: Wed, 28 Jun 2017 11:54:49 -0700 Subject: [PATCH 1/2] Change idx type switch for aux data --- src/kvstore/comm.h | 4 ++-- src/operator/nn/cast_storage-inl.h | 12 ++++++------ src/operator/optimizer_op-inl.h | 4 ++-- src/operator/tensor/indexing_op.h | 4 ++-- src/operator/tensor/init_op.h | 2 +- src/operator/tensor/matrix_op-inl.h | 8 ++++---- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/kvstore/comm.h b/src/kvstore/comm.h index a8a5cf3b5268..218781f5bbf7 100644 --- a/src/kvstore/comm.h +++ b/src/kvstore/comm.h @@ -191,7 +191,7 @@ class CommCPU : public Comm { std::vector skip(num_in, false); // the values tensor of the inputs MSHADOW_TYPE_SWITCH(out->dtype(), DType, { - MSHADOW_INT_TYPE_SWITCH(out->aux_type(kIdx), IType, { + MSHADOW_IDX_TYPE_SWITCH(out->aux_type(kIdx), IType, { std::vector> in_vals(num_in); std::vector> in_indices(num_in); // offset to the values tensor of all inputs @@ -350,7 +350,7 @@ class CommCPU : public Comm { << out->storage_type() << " given)"; MSHADOW_TYPE_SWITCH(out->dtype(), DType, { - MSHADOW_INT_TYPE_SWITCH(out->aux_type(kIdx), IType, { + MSHADOW_IDX_TYPE_SWITCH(out->aux_type(kIdx), IType, { std::vector uniq_row_idx; GetUniqueRspRowIdx(nds, &uniq_row_idx); out->CheckAndAlloc({mshadow::Shape1(uniq_row_idx.size())}); diff --git a/src/operator/nn/cast_storage-inl.h b/src/operator/nn/cast_storage-inl.h index 003161f8797a..f0268c797c74 100644 --- a/src/operator/nn/cast_storage-inl.h +++ b/src/operator/nn/cast_storage-inl.h @@ -51,7 +51,7 @@ inline void CastStorageDnsRspImpl(mshadow::Stream* s, const TBlob& dns, NDA CHECK_EQ(rsp->storage_type(), kRowSparseStorage); CHECK_EQ(dns.shape_, rsp->shape()); MSHADOW_TYPE_SWITCH(dns.type_flag_, DType, { // data type - MSHADOW_INT_TYPE_SWITCH(rsp->aux_type(rowsparse::kIdx), RType, { // row idx type + MSHADOW_IDX_TYPE_SWITCH(rsp->aux_type(rowsparse::kIdx), RType, { // row idx type const index_t num_rows = dns.shape_[0]; const index_t num_cols = dns.shape_[1]; rsp->CheckAndAllocAuxData(rowsparse::kIdx, mshadow::Shape1(num_rows)); @@ -102,7 +102,7 @@ void CastStorageRspDnsImpl(mshadow::Stream* s, const NDArray& rsp, TBlob* d using namespace mshadow::expr; CHECK_EQ(rsp.storage_type(), kRowSparseStorage); MSHADOW_TYPE_SWITCH(dns->type_flag_, DType, { - MSHADOW_INT_TYPE_SWITCH(rsp.aux_type(rowsparse::kIdx), IType, { + MSHADOW_IDX_TYPE_SWITCH(rsp.aux_type(rowsparse::kIdx), IType, { // assign zeros mxnet_op::Kernel::Launch(s, dns->Size(), dns->dptr()); if (rsp.storage_initialized()) { @@ -186,8 +186,8 @@ inline void CastStorageDnsCsrImpl(mshadow::Stream* s, const TBlob& dns, NDA CHECK_EQ(dns.shape_.ndim(), 2); CHECK_EQ(dns.shape_, csr->shape()); MSHADOW_TYPE_SWITCH(dns.type_flag_, DType, { // data type - MSHADOW_INT_TYPE_SWITCH(csr->aux_type(csr::kIndPtr), IType, { // indptr type - MSHADOW_INT_TYPE_SWITCH(csr->aux_type(csr::kIdx), CType, { // col idx type + MSHADOW_IDX_TYPE_SWITCH(csr->aux_type(csr::kIndPtr), IType, { // indptr type + MSHADOW_IDX_TYPE_SWITCH(csr->aux_type(csr::kIdx), CType, { // col idx type const index_t num_rows = dns.shape_[0]; const index_t num_cols = dns.shape_[1]; csr->CheckAndAllocAuxData(csr::kIndPtr, mshadow::Shape1(num_rows+1)); @@ -248,8 +248,8 @@ void CastStorageCsrDnsImpl(mshadow::Stream* s, const NDArray& csr, TBlob* d CHECK_EQ(dns->shape_.ndim(), 2); CHECK_EQ(dns->shape_, csr.shape()); MSHADOW_TYPE_SWITCH(dns->type_flag_, DType, { // data type - MSHADOW_INT_TYPE_SWITCH(csr.aux_type(csr::kIndPtr), IType, { // indptr type - MSHADOW_INT_TYPE_SWITCH(csr.aux_type(csr::kIdx), CType, { // col idx type + MSHADOW_IDX_TYPE_SWITCH(csr.aux_type(csr::kIndPtr), IType, { // indptr type + MSHADOW_IDX_TYPE_SWITCH(csr.aux_type(csr::kIdx), CType, { // col idx type const index_t num_rows = dns->shape_[0]; const index_t num_cols = dns->shape_[1]; DType* dns_data = dns->dptr(); diff --git a/src/operator/optimizer_op-inl.h b/src/operator/optimizer_op-inl.h index 176da461f31f..ac2cc8785a86 100755 --- a/src/operator/optimizer_op-inl.h +++ b/src/operator/optimizer_op-inl.h @@ -129,7 +129,7 @@ inline void SGDUpdateDnsRspImpl(const SGDParam& param, CHECK_GT(weight.shape_.Size(), 0); MSHADOW_REAL_TYPE_SWITCH(weight.type_flag_, DType, { - MSHADOW_INT_TYPE_SWITCH(grad.aux_type(rowsparse::kIdx), IType, { + MSHADOW_IDX_TYPE_SWITCH(grad.aux_type(rowsparse::kIdx), IType, { MXNET_ASSIGN_REQ_SWITCH(req, req_type, { auto weight_data = weight.dptr(); auto grad_idx = grad.aux_data(rowsparse::kIdx).dptr(); @@ -364,7 +364,7 @@ inline void SGDMomUpdateDnsRspDnsImpl(const SGDMomParam& param, CHECK_GT(mom.shape_.Size(), 0); MSHADOW_REAL_TYPE_SWITCH(weight.type_flag_, DType, { - MSHADOW_INT_TYPE_SWITCH(grad.aux_type(kIdx), IType, { + MSHADOW_IDX_TYPE_SWITCH(grad.aux_type(kIdx), IType, { MXNET_ASSIGN_REQ_SWITCH(req, req_type, { auto weight_data = weight.dptr(); auto grad_idx = grad.aux_data(kIdx).dptr(); diff --git a/src/operator/tensor/indexing_op.h b/src/operator/tensor/indexing_op.h index 213c2d2c3313..2a1590f9a8a5 100644 --- a/src/operator/tensor/indexing_op.h +++ b/src/operator/tensor/indexing_op.h @@ -891,7 +891,7 @@ void SparseRetainOpForwardEx(const nnvm::NodeAttrs& attrs, using namespace mxnet_op; Stream *s = ctx.get_stream(); MSHADOW_TYPE_SWITCH(output_data.type_flag_, DType, { // output data type - MSHADOW_INT_TYPE_SWITCH(output_idx.type_flag_, RType, { // row index data type + MSHADOW_IDX_TYPE_SWITCH(output_idx.type_flag_, RType, { // row index data type MSHADOW_TYPE_SWITCH(idx_data.type_flag_, IType, { // index array data type Kernel::Launch(s, output_data.Size(), output_data.dptr()); Kernel::Launch(s, idx_data.Size(), output_data.dptr(), @@ -949,7 +949,7 @@ void SparseRetainOpBackwardEx(const nnvm::NodeAttrs& attrs, using namespace mxnet_op; Stream *s = ctx.get_stream(); MSHADOW_TYPE_SWITCH(out_grad_data.type_flag_, DType, { // output data type - MSHADOW_INT_TYPE_SWITCH(in_grad_idx.type_flag_, RType, { // row index data type + MSHADOW_IDX_TYPE_SWITCH(in_grad_idx.type_flag_, RType, { // row index data type MSHADOW_TYPE_SWITCH(idx_data.type_flag_, IType, { // index array data type MXNET_ASSIGN_REQ_SWITCH(req[sr::kArr], req_type, { Kernel, xpu>::Launch( diff --git a/src/operator/tensor/init_op.h b/src/operator/tensor/init_op.h index bc885f3cecf5..7cbf986cbf9c 100644 --- a/src/operator/tensor/init_op.h +++ b/src/operator/tensor/init_op.h @@ -138,7 +138,7 @@ inline void FillDnsZerosRspImpl(mshadow::Stream *s, NDArray *dst) { using namespace mxnet_op; CHECK_EQ(dst->storage_type(), kRowSparseStorage); MSHADOW_REAL_TYPE_SWITCH(dst->dtype(), DType, { - MSHADOW_INT_TYPE_SWITCH(dst->aux_type(kIdx), IType, { + MSHADOW_IDX_TYPE_SWITCH(dst->aux_type(kIdx), IType, { auto num_rows = dst->shape()[0]; dst->CheckAndAlloc({Shape1(num_rows)}); auto idx = dst->aux_data(kIdx).FlatTo1D(s); diff --git a/src/operator/tensor/matrix_op-inl.h b/src/operator/tensor/matrix_op-inl.h index 0aad920d641c..207003ae029d 100644 --- a/src/operator/tensor/matrix_op-inl.h +++ b/src/operator/tensor/matrix_op-inl.h @@ -661,8 +661,8 @@ void DotCsrDnsDnsImpl(const OpContext& ctx, const TBlob data_out = *ret; MSHADOW_TYPE_SWITCH(data_l.type_flag_, DType, { // data type - MSHADOW_INT_TYPE_SWITCH(indptr_l.type_flag_, IType, { // indptr type - MSHADOW_INT_TYPE_SWITCH(col_idx_l.type_flag_, CType, { // col idx type + MSHADOW_IDX_TYPE_SWITCH(indptr_l.type_flag_, IType, { // indptr type + MSHADOW_IDX_TYPE_SWITCH(col_idx_l.type_flag_, CType, { // col idx type if (std::is_same::value) { // cpu parallelization by row blocks if (kWriteTo == req) { mxnet_op::Kernel::Launch( @@ -1157,8 +1157,8 @@ void SliceCsrImpl(const SliceParam ¶m, const OpContext& ctx, return; } // assume idx indptr share the same type - MSHADOW_INT_TYPE_SWITCH(in.aux_type(kIndPtr), RType, { - MSHADOW_INT_TYPE_SWITCH(in.aux_type(kIdx), IType, { + MSHADOW_IDX_TYPE_SWITCH(in.aux_type(kIndPtr), RType, { + MSHADOW_IDX_TYPE_SWITCH(in.aux_type(kIdx), IType, { MSHADOW_TYPE_SWITCH(in.dtype(), DType, { auto in_indptr = in.aux_data(kIndPtr).dptr(); auto out_indptr = out.aux_data(kIndPtr).dptr(); From 7efa0f2692679603561597aab52add4d41f745a1 Mon Sep 17 00:00:00 2001 From: reminisce Date: Wed, 28 Jun 2017 16:15:07 -0700 Subject: [PATCH 2/2] Add mshadow commit --- mshadow | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mshadow b/mshadow index 8db65bd081c7..06407689699e 160000 --- a/mshadow +++ b/mshadow @@ -1 +1 @@ -Subproject commit 8db65bd081c7e243028ace93ef0acc9efc4383ba +Subproject commit 06407689699efc043db1ba5a8131abc2c53c4cda