Using traction :: sorting inside a stream

I would like to know if thrust :: sort () can be used inside a thread

__global__
void mykernel(float* array, int arrayLength)
{
    int threadID = blockIdx.x * blockDim.x + threadIdx.x;
    // array length is vector in the device global memory
    // is it possible to use inside the thread?
    thrust::sort(array, array+arrayLength);
    // do something else with the array
}

If so, does sorting run other kernels to parallelize the sorting?

+4
source share
2 answers

Yes, thrust::sortit can be combined with an execution policy thrust::seqto sequentially sort numbers in a single CUDA thread (or sequentially within a single CPU thread):

#include <thrust/sort.h>
#include <thrust/execution_policy.h>

__global__
void mykernel(float* array, int arrayLength)
{
  int threadID = blockIdx.x * blockDim.x + threadIdx.x;

  // each thread sorts array
  // XXX note this causes a data race
  thrust::sort(thrust::seq, array, array + arrayLength);
}

Note that your example causes a data race because each CUDA thread tries to sort the same data in parallel. A proper non-racing program would split arrayaccording to the flow index.

thrust::seq, , Thrust v1.8 .

+7

@aland Thrust - , ; Thrust, CPU, GPU .

, , ( ), CUB, , .

. . @Jared, , Thrust GPU Thrust 1.7.

+2

Source: https://habr.com/ru/post/1538824/


All Articles