thrust::stable_sort_by_key cause Aborted (core dumped)

hi, everyone. I don’t know how to deal with this situation. pls help me~ Thank you

here is the code:

float *d_scores = 0;
cudaMalloc((void **) &d_scores, batchSize * scoresLength * sizeof(float));

... d_scores = value;

int *d_scoresIndex = 0;
cudaMalloc((void **) &d_scoresIndex, batchSize * scoresLength * sizeof(int));

...  d_scoresIndex = kes;

thrust::device_ptr<float> thrust_d_scores(d_scores);
thrust::device_ptr<int> thrust_d_scoresIndex(d_scoresIndex);

for (int i = 0; i < batchSize; ++i) 
{
    std::cout << "for trust i:" << i << std::endl;

    thrust::stable_sort_by_key(thrust_d_scores + i * scoresLength,
                            thrust_d_scores + i * scoresLength + scoresLength,
                            thrust_d_scoresIndex + i * scoresLength,
                            thrust::greater<float>());
}

runtime error information:

terminate called after throwing an instance of ‘thrust::system::system_error’
what(): radix_sort: failed to get memory buffer: invalid configuration argument
Aborted (core dumped)

when I use this code, just change float to int, still core dump.

    thrust::stable_sort_by_key(thrust_d_scores + i * scoresLength,
                            thrust_d_scores + i * scoresLength + scoresLength,
                            thrust_d_scoresIndex + i * scoresLength,
                            thrust::greater<

int>());

runtime error information changed to :
terminate called after throwing an instance of ‘thrust::system::system_error’
what(): merge_sort: failed to get memory buffer: invalid configuration argument
Aborted (core dumped)

not sure what you’re doing here:

d_scores = value;

but its almost certainly wrong.

If you were trying to copy data to d_scores that way, it won’t work.

If you want to use a method like this, then learn how to copy data from host to device in CUDA. The CUDA sample code vectorAdd is one possible place to start.

i have found the reason. it is because the grid size and block size set wrong.