Cuda SparseLabelSplitOp
Cuda SparseLabelSplitOp

Summary:
This is a brief introduction to what this op is doing. In the multi-label case,
i.e., each example has more than one label, we want to find out which examples
have values for each label. That is, given a sparse representation in
len = (2,3), ind = (1, 2, 0, 1, 2), val = (10, 20, 5, 8, 15), we want to return
example_id_0 = [1], example_id_1 = [0,1], example_id_2 = [0,1],
value_0 = [5], value_1 = [10,8], value_2 = [20,15].

There are two special things here. 1. The size of each output tensor is unknown until runtime;
2. The ordering in each output tensor should be preserved, e.g., example_id_1 = [0,1] instead of [1,0].

What I am doing now is to get the output size and an offset map (see codes) in cpu and then
launch a kernel to take care of the rest. This requires a copy of O(N) which is really not ideal.

Previously I had an implementation that computes the output size in gpu but when I fill values in
the output tensors it is hard to make sure the ordering will be preserved unless I do a sorting afterwards.

Reviewed By: azzolini

Differential Revision: D5825104

fbshipit-source-id: 4d987cef0247746998ec1d2acc47fc5ed2302722

sf-wind/caffe2,pietern/caffe2,Yangqing/caffe2,pietern/caffe2,pietern/caffe2,davinwang/caffe2,xzturn/caffe2,Yangqing/caffe2,caffe2/caffe2,davinwang/caffe2,sf-wind/caffe2,davinwang/caffe2,Yangqing/caffe2,davinwang/caffe2,xzturn/caffe2,sf-wind/caffe2,sf-wind/caffe2,davinwang/caffe2,Yangqing/caffe2,pietern/caffe2,pietern/caffe2,sf-wind/caffe2,Yangqing/caffe2,xzturn/caffe2,xzturn/caffe2,xzturn/caffe2