May I Use Cuda Cub Iterator Instead of Thrust?

Is it possible to use iterators with CUB like Thrust? I want t use CUB instead of thrust as follow:

__global__ void reduce_roster(thrust::device_vector<float>::iterator vect, float * tab_seq, int SEUIL_ROSTER)
{
    int tid = blockIdx.x * blockDim.x + threadIdx.x;
    float resultat = 0;

    int i = TAILLE_ROSTER/TAILLE_SEQ_ROSTER;
    resultat = thrust::reduce(thrust::device, vect + (tid * TAILLE_ROSTER) + TAILLE_SEQ_ROSTER *  (i - 1), vect + (tid * TAILLE_ROSTER) + TAILLE_SEQ_ROSTER * i);


    float tmp;
    i--;

    while (resultat != -1 && i != 0)
    {
        if (resultat > SEUIL_ROSTER)
        {
            resultat = -1; 
        }
        else
        {               

            tmp = thrust::reduce(thrust::device, vect + (tid * TAILLE_ROSTER) + TAILLE_SEQ_ROSTER *  (i - 1), vect + (tid * TAILLE_ROSTER) + TAILLE_SEQ_ROSTER * i);

            resultat = resultat + tmp;


            i--;
        }
    }

Since CUB is faster than trust I'm trying to use it to reduce segments of an array.

1 Answer

No.

And further to that, it isn't possible to use CUB to perform the same operation as you have shown in your code either. Depending on how you compile your kernel, thrust will either emit code where the reduction is performed serially by each thread, or by a child kernel launch using dynamic parallelism. CUB, on the other hand, has warp and block scope device reduction functions. It does not support single thread or dynamic parallelism scope operations.

5

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Alexander Ross

Alexander Ross

Gaming, Esports & Interactive Media Writer

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.

Share this article
Twitter Facebook Pinterest