How can I use clSetKernelArg to set the local memory size in OpenCL Haskell?

I use the System.GPU.OpenCL module from Luis Cabellos to manage the OpenCL core. Everything works fine, but to speed things up, I'm trying to cache some global memory in a local buffer. I just noticed that it is not possible to pass a local buffer using the current definition of clSetKernelArg , but maybe someone can enlighten me?

Definition:

 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, a high level of clSetKernelArg conveniently determines the size of the memory and also extracts a pointer to it. This is ideal for global memory, but it seems like the way to use clSetKernelArg when querying local memory is to specify the size of the required memory in CSize and set Ptr to zero. Of course, nullPtr placement nullPtr not work here, so how can I get around this? I would call raw_clSetKernelArg directly, but it does not seem to be exported by the module.

Thanks.

+4
source share
1 answer

I don't think there is a way to tune the hack so that pval turns out to be nullPtr .

This seems like a pretty simple exception to the wrapped API; I would suggest just reporting it , rather than trying to crack it :)

+1
source

Source: https://habr.com/ru/post/1390341/


All Articles