Search code examples
cudagpujocl

determine global memory available on GPU with JOCL?


I'm writing a JOCl.org (which is different then jogamps jocl) running on GPU. Were working with sufficient data that I need to be careful to stay under the GPU's global memory limit. To do this I need a way of programmatically determining how much memory the GPU has. I assume there must be a simple JOCL method/variable to do this, but for some reason I can't seem to figure out what it is. I've looked at the CL.CL_MEM_SIZE and CL_DEVICE_GLOBAL_MEM_CACHE_SIZE but these both return something around 4100; I know I'm currently working with a graphics card that is suppose to contain 512 MB.

Also, I can't seem to use nearly as much memory as I should. In my worst case scenario I have to run a kernel that processes frames of 2^22 floats and will internally require twice as much data as frame size. If I try to cache two frames (so 2 frames * 2^22 * 2^2 bytes/float * 2 for overhead = 2^26) I can cache without difficulty, but when I increase my caching so I process three frames at a time (or 2^25*3) I appear to run out of memory. However, I believe I should only be using ~100 of my 512 MB of global memory. I believe I'm properly freeing memory when not used, but apparently I'm either doing something wrong or am misinterpreting the GPU's advertised 512 MB. Can anyone help explain this confusion to me?

Is there a way I can profile the GPU to get a sense for actual memory usage?


Solution

  • CL.CL_MEM_SIZE and CL_DEVICE_GLOBAL_MEM_CACHE_SIZE are constant values which are used as parameters for clGetDeviceInfo to query the device.

    http://www.jocl.org/doc/org/jocl/CL.html#clGetDeviceInfo(org.jocl.cl_device_id, int, long, org.jocl.Pointer, long[])

    The method clGetDeviceInfo is the method you use to query the device information. It returns the value of the parameter you asked for in param_name. The link has a list of all the parameter names available with a brief explanation. (CL_DEVICE_GLOBAL_MEM_SIZE should be the one you are looking for).