开发者

OpenCL to search array and set a flag

I'm brand new to using OpenCL, and this seems like it should be very simple, so bear with me.

I'm writing a simple kernel to scan an array and look for a particular value. If that value is found anywhere in the array, I'd like a flag to be set. If the value is not found, the flag should remain 0;

Currently I'm creating a cl_mem object to hold an int

    cl_mem outputFlag = clCreateBuffer(mCLContext, CL_MEM_WRITE_ONLY, sizeof(cl_int), NULL, NULL);

setting it as a kernel argument

    clSetKernelArg(mCLKernels[1],1, sizeof(cl_mem), &outputFlag);

and executing my kernel which looks like:

__kernel void checkForHole(__global uchar *image , __global int found, uchar holeValue)
{
    int i = get_global_id(0);
    int j = get_global_id(1);

    uchar sample = image[i*j];

    if (sample == holeValue) {
        found = 1;
    }   
}

Note that my array is 2D, though it shouldn't matter.

When I put a printf statement inside my found condition, it does get called (t开发者_StackOverflowhe value is found). But when I read back my value via:

 cl_int result;

errorCode = clEnqueueReadBuffer(mCLCommandQueue, outputFlag, CL_TRUE
                                , 0, sizeof(cl_int), &result, 0, NULL, NULL);

I get 0. Is there a proper way to set a flag in openCL? it would also be nice if there was a way to halt the entire execution and just return my value if it is found.

Can I write a bool return type kernel and just return true?

Thanks!


In the kernel the output flag should be a pointer to an int.

Change the kernel parameter to __global int *found

I always seem to figure out my issues just by writing them here....

If anyone knows a way to halt the execution though, or if it's even possible, I'd still be interested :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜