vendredi 23 octobre 2020

Is it possible to apply one or more boolean condition(s) to every element of a thrust::device_vector?

I would like to mention that there is another question you can read here which I think is similar to my question, but after reading it and trying to cross-reference with the documentation I am still confused as to how everything works. As such, I would like to ask my own question to get further clarification on the operation I am trying to perform.

Background: I am using C++11 on Windows 10 compiled with MinGW and CLion; the overall package is intended to be the back-end of a Wolfram Language package connected through a dynamic link library once completed.

To continue, I'm currently trying to apply the following function, F, which when given a 0-indexed sorted array V of length n where V[0]=0 and V[n-1] = 1 and a value r which is a float in the range [0, 1], returns the forward index of the two vector elements that the value exists inbetween. This is formulated in rough pseudocode like so:

F(arr V, int n, float r):
     for all 1 <= j <= n in parallel do:
          if j == n - 1:
               if V[j - 1] <= r <= V[j]:
                    return j;
               else:
                    return 0;
          else:
               if V[j - 1] <= r < V[j]:
                    return j;
               else:
                    return 0;

The first-level if-else is merely to avoid excluding the value 1.0. My main question is that if it's possible to do this in one or more parts using thrust. I think that if I could do a Boolean comparison on each value of the array in parallel then I could mimic the function, but I'm not sure how to do that in parallel.

I could write my own CUDA kernel as well, but I would prefer not to as I'm only a novice at parallel computing and GPU stuff so I'm sure that a thrust-based solution would be faster. I'm also not sure if using CUDA as well as Thrust would make it more difficult to create the dynamic link library later on. However if anyone thinks it would be easier to write my own kernel with this end-goal in mind then I would appreciate the perspective as a novice. Thank you for any help!

Aucun commentaire:

Enregistrer un commentaire