I trying to use OpenCL using HASKELL. I write a simple program converting a working one in C. It appears to work well, but when I assign a memory object to the kernel parameters, it fails with CL_INVALID_MEM_OBJECT error. I don’t know who to fix because I use the same calls than in C program and there it works:
The programSource is the OpenCL code
programSource :: String
programSource = "__kernel void duparray(__global float *in, __global float *out ){ int id = get_global_id(0); out[id] = 2*in[id]; }"
And the initializacion works until the call of clSetKernelArg that fails with Just (ErrorCode (-38))
-- test openCL
input <- newArray ([0,1,2,3,4] :: [CFloat])
Right mem_in <- clCreateBuffer myContext (memFlagsJoin [clMemReadOnly,clMemCopyHostPtr]) (4*5) (castPtr input)
Right mem_out <- clCreateBuffer myContext clMemWriteOnly (4*5) nullPtr
print (mem_in,mem_out)
Right program <- clCreateProgramWithSource myContext programSource
print program
err <- clBuildProgram program [myDeviceId] "" buildProgramCallback nullPtr
print err
Right kernel <- clCreateKernel program "duparray"
print kernel
kaErr0 <- clSetKernelArg kernel 0 (fromIntegral.sizeOf $ mem_in) (castPtr mem_in)
kaErr1 <- clSetKernelArg kernel 1 (fromIntegral.sizeOf $ mem_out) (castPtr mem_out)
print (kaErr0,kaErr1)
I’m using OpenCLRaw, with several modifications that i put on https://github.com/zhensydow/OpenCLRaw
I found that I need to pass the direction of the mem buffer pointer, no the pointer itself. This is the rigth way to call
clSetKernelArg: