peri4n
peri4n

Reputation: 1421

OpenCL atomics do nothing

I try to program an example histogram tool using OpenCL. To start, I was just interessted to atomicly increment each bin. I came up with the following kernel code:

__kernel void Histogram(
    __global const int* input, 
    __global int* histogram, 
    int numElements) {
    // get index into global data array
    int iGID = get_global_id(0);

    // bound check, equivalent to the limit on a 'for' loop
    if (iGID >= numElements) {
        return;
    }

    if( iGID < 100 ) {
                // initialize histogram
        histogram[iGID] = 0;
    }

    barrier(CLK_GLOBAL_MEM_FENCE);

    int bin = input[iGID];

    atomic_inc(&histogram[bin]);
}

But the output histogram is zero in every bin. Why is that? Further more, the real strange things happen if a put a printf(" ") in the last line. Suddenly, it works. I am completely lost, has someone an idea why this happens?

P.S. I enabled all extensions

Upvotes: 0

Views: 239

Answers (1)

peri4n
peri4n

Reputation: 1421

I solved to problem by my self.

After nothing fixed the problem, I tried to change the CLDevice to the CPU. Everything went as it was supposed to be (unfortunately very slow :D). But this gave me the idea that it might not be a code problem but a OpenCL infrastructure problem.

I updated the OpenCL platform of AMD and now everything works.

Thank you, in case you thought about my problem.

Upvotes: 2

Related Questions