Can CUB::DeviceSelect also return not selected part

53 Views Asked by At

I want to return both selected and not selected part of an array using CUB::DeviceSelect. The only workaround come to me is by calling CUB::DeviceSelect again with the opposite SelectOp, but I wonder if there is more effective way to do this.

A quick demo:

struct Positive {
    __host__ __device__ __forceinline__
    bool operator()(const int a) const {
        return (a > 0);
    }
}

int len = 6;
int *d_in = {0, 2, -2, -1, 1, 3};
int *d_out;
int *d_num_select;
void *temp = NULL;
size_t temp_size = 0;


// I want to get something like
// d_out = {2, 1, 3, 0, -2, -1} and *d_num_select = 3
// but calling the code below only give me d_out = {2, 1, 3}
cub::DeviceSelect::If(temp, temp_size, d_in, d_out, d_num_select, len, Positive());
cudaMalloc(&temp, temp_size);
cub::DeviceSelect::If(temp, temp_size, d_in, d_out, d_num_select, len, Positive());
0

There are 0 best solutions below