samskalicky commented on a change in pull request #17569: Adding sparse support
to MXTensor for custom operators
URL: https://github.com/apache/incubator-mxnet/pull/17569#discussion_r387836987
##########
File path: include/mxnet/lib_api.h
##########
@@ -1193,19 +1312,57 @@ extern "C" {
const int64_t** outshapes, int* outdims, void**
outdata, int* outtypes,
size_t* outIDs, const char** outdev_type, int*
outdev_id, int num_out,
xpu_malloc_t cpu_malloc, void* cpu_alloc,
- xpu_malloc_t gpu_malloc, void* gpu_alloc, void*
stream) {
+ xpu_malloc_t gpu_malloc, void* gpu_alloc, void*
stream,
+ void** in_indices, void** in_indptr,
+ int64_t* in_indices_shapes, int64_t*
in_indptr_shapes,
+ std::vector<std::vector<float>>& tmp_data,
+ std::vector<std::vector<int64_t>>& col_idx,
+ std::vector<std::vector<int64_t>>& row_ptr) {
// create a vector of tensors for inputs
std::vector<MXTensor> inputs(num_in);
+ // create a vector for sparse inputs
+ std::vector<MXInSparse> in_sparse(num_in);
+
for (int i = 0; i < num_in; i++) {
- inputs[i].setTensor(indata[i], (MXDType)intypes[i], inshapes[i],
indims[i],
- inIDs[i], {indev_type[i], indev_id[i]});
+ // Dense representation.
+ if(!in_indices_shapes) {
+ inputs[i].setTensor(indata[i], (MXDType)intypes[i], inshapes[i],
indims[i],
+ inIDs[i], {indev_type[i], indev_id[i]},
kDefaultStorage);
+ }
+ // Sparse representation.
+ else {
+ MXStorageType type;
+ if(!in_indptr_shapes) {
+ type = kRowSparseStorage;
+ in_sparse[i].set(indata[i], inshapes[i], indims[i], in_indices[i],
in_indices_shapes[i]);
Review comment:
some sparse operators produce dense outputs, not sure we can guarantee all
or nothing
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services