Something like ForAll in cuda

Mar 4, 2014 at 7:35 AM
Edited Mar 4, 2014 at 10:03 AM

I am fairly new to this whole Cuda experience, and although i did read through all the litterature i could come across, i have a question to a problem that i cant quite wrap my head around.

Basically i want to test if something is true for all elements of an array, inside of kernel.

i came up with this (simplified for clarity)
public static void GetResults(GThread thread, Test[] tests, byte[] output)
    byte found = 1;
    for (int i = 0; i < tests.Length; i++)
        if ((tests[i].X + tests[i].Y + tests[i].Z) % 13 != 0)
            found = 0;
    if (found == 1)
        output[thread.blockIdx.x] = 1;
but it is painfully slow, compared to how fast it is when i remove the found and the associated lines of code.

I noticed the thread.All method, but i am very unsure as to how it works. Any idea of how i can do this, or where i can seek more knowledge to aid me in finding a solution?

Any input is much appreciated.

Its worth noting that the length of Test varies between executions.
Mar 5, 2014 at 8:58 AM
You are only running one thread! Take a look at the examples in CudafyByExample project.