WebCL doesn't fill global table

79 Views Asked by At

I started using Nokia WebCL implementation for Mozilla Firefox.

I'm testing my application on Firefox version 32.0 (which is version for which Nokia binding was implemented).

This is my code (for simplicity and to show you what my issue is I've simplified the kernel code to minimum):

Kernel code:

<script id="julia_set" type="text/x-opencl">
__kernel void julia_set(__global int* pix)
{
pix[0]=5;
}

</script>

My Javascript code:

function loadKernel(id){
    var kernelElement = document.getElementById(id);
    var kernelSource = kernelElement.text;
    if (kernelElement.src != "") {
        var mHttpReq = new XMLHttpRequest();
        mHttpReq.open("GET", kernelElement.src, false);
        mHttpReq.send(null);
        kernelSource = mHttpReq.responseText;
    }
    return kernelSource;
}
 var platforms = webcl.getPlatforms();
 var width = 2;
 var height = 2;
 var ctx = webcl.createContext(platforms[2],WebCL.DEVICE_TYPE_GPU);
 var length = 4*width*height;
 var bufSize = 4*length;
 var bufferC = ctx.createBuffer (WebCL.MEM_WRITE_ONLY, bufSize);
 var kernelSrc = loadKernel("julia_set");
 var program = ctx.createProgram(kernelSrc);
 var device = ctx.getInfo(WebCL.CONTEXT_DEVICES)[0];
 try {

     program.build ([device], "");
 } catch(e) {
     alert ("Failed to build WebCL program. Error "
         + program.getBuildInfo (device,
             WebCL.PROGRAM_BUILD_STATUS)
         + ":  "
         + program.getBuildInfo (device,
             WebCL.PROGRAM_BUILD_LOG));
     throw e;
 }
 var kernel = program.createKernel ("julia_set");
 kernel.setArg (0, bufferC);
 var cmdQueue = ctx.createCommandQueue (device);  
 var local = [16,16];
 var global = [32,32];
 cmdQueue.enqueueNDRangeKernel(kernel, 2, null,global, local);
 var outBuffer = new Uint32Array(length);

 cmdQueue.enqueueReadBuffer (bufferC, false, 0, bufSize, outBuffer);
 cmdQueue.finish ();
 console.log(outBuffer);

It's the most simple OpenCL application I could imagine. I expect my outBuffer to be filled with 0's and first element to be 5, but all the elements are 0. Whatever I try to do in kernel, my array seems untouched.

The device I'm using is NVidia GeForce GT 750M.

What can be possibly wrong in my code?

1

There are 1 best solutions below

1
On
if(get_global_id(0)==0 && get_global_id(1)==0)
    pix[0]=5;

should fix the issue, without race condition.