4

I'm using the System.GPU.OpenCL module by Luis Cabellos to control an OpenCL kernel. All is working well but to speed things up I am trying to cache some global memory into a local buffer. I have just noticed that it seems to be impossible to pass a local buffer using the current definition of clSetKernelArg, but perhaps someone can enlighten me?

The definition is,

clSetKernelArg :: Storable a => CLKernel -> CLuint -> a -> IO ()
clSetKernelArg krn idx val = with val $ \pval -> do
  whenSuccess (raw_clSetKernelArg krn idx (fromIntegral . sizeOf $ val) (castPtr pval))
    $ return ()

where the raw function is defined as,

foreign import CALLCONV "clSetKernelArg" raw_clSetKernelArg ::
  CLKernel -> CLuint -> CSize -> Ptr () -> IO CLint

Therefore the high level clSetKernelArg conveniently figures out the size of the memory and also extracts a pointer to it. This is perfect for global memory, but it seems that the way to use clSetKernelArg when local memory is requested is to specify the size of the desired memory in the CSize, and set Ptr to zero. Of course, putting nullPtr here doesn't work, so how can I circumvent this problem? I would call raw_clSetKernelArg directly, but it seems it is not exported by the module.

Thanks.

2
  • Looking at the OpenCL documentation it seems that you are correct that when the object is local that the pointer should be NULL. Why doesn't nullPtr work? Commented Jan 11, 2012 at 3:25
  • @vivian: Because the exported clSetKernelArg interface doesn't let you specify your own pointer. Commented Jan 11, 2012 at 7:20

1 Answer 1

1

I don't think there's any way to rig up a hack so that pval ends up being a nullPtr.

This seems like a fairly simple omission from the wrapped API; I'd suggest simply reporting it rather than trying to hack around it :)

Sign up to request clarification or add additional context in comments.

2 Comments

clSetKernelArg :: Storable a => CLKernel -> CLuint -> Maybe a -> IO () would do the trick.
@vivian: It seems the functionality has already been added :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.