Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CL_OUT_OF_RESOURCES for 2 millions floats with 1GB VRAM?

It seems like 2 million floats should be no big deal, only 8MBs of 1GB of GPU RAM. I am able to allocate that much at times and sometimes more than that with no trouble. I get CL_OUT_OF_RESOURCES when I do a clEnqueueReadBuffer, which seems odd. Am I able to sniff out where the trouble really started? OpenCL shouldn't be failing like this at clEnqueueReadBuffer right? It should be when I allocated the data right? Is there some way to get more details than just the error code? It would be cool if I could see how much VRAM was allocated when OpenCL declared CL_OUT_OF_RESOURCES.

like image 717
smuggledPancakes Avatar asked Oct 21 '10 14:10

smuggledPancakes


3 Answers

I just had the same problem you had (took me a whole day to fix). I'm sure people with the same problem will stumble upon this, that's why I'm posting to this old question.

You propably didn't check for the maximum work group size of the kernel.

This is how you do it:

size_t kernel_work_group_size;
clGetKernelWorkGroupInfo(kernel, device, CL_KERNEL_WORK_GROUP_SIZE, sizeof(size_t), &kernel_work_group_size, NULL);

My devices (2x NVIDIA GTX 460 & Intel i7 CPU) support a maximum work group size of 1024, but the above code returns something around 500 when I pass my Path Tracing kernel. When I used a workgroup size of 1024 it obviously failed and gave me the CL_OUT_OF_RESOURCES error.

The more complex your kernel becomes, the smaller the maximum workgroup size for it will become (or that's at least what I experienced).

Edit:
I just realized you said "clEnqueueReadBuffer" instead of "clEnqueueNDRangeKernel"...
My answer was related to clEnqueueNDRangeKernel.
Sorry for the mistake.
I hope this is still useful to other people.

like image 90
Tara Avatar answered Sep 18 '22 03:09

Tara


From another source:

- calling clFinish() gets you the error status for the calculation (rather than getting it when you try to read data).
- the "out of resources" error can also be caused by a 5s timeout if the (NVidia) card is also being used as a display
- it can also appear when you have pointer errors in your kernel.

A follow-up suggests running the kernel first on the CPU to ensure you're not making out-of-bounds memory accesses.

like image 40
Eric Towers Avatar answered Sep 20 '22 03:09

Eric Towers


Out of bounds acesses in a kernel are typically silent (since there is still no error at the kernel queueing call).

However, if you try to read the kernel result later with a clEnqueueReadBuffer(). This error will show up. It indicates something went wrong during kernel execution.

Check your kernel code for out-of-bounds read/writes.

like image 29
DarkZeros Avatar answered Sep 18 '22 03:09

DarkZeros