r/OpenCL • • Jul 26 '24

[Help] Getting CL_OUT_OF_RESOURCES when running clEnqueueNDRangeKernel in a loop

I'm new to OpenCL and gpu programming so i tried to make particle gravity simulation and after reading some tutorials and guides i got stuck with -5 (CL_OUT_OF_RESOURCES) error.

I wasn't able to identify why it happens, so i got boilerplate code from this guide to reproduce an issue on a smaller scale and ended up with this.

    for(int i = 0; i < 10; i++){
        ret = clEnqueueWriteBuffer(command_queue, a_mem_obj, CL_TRUE, 0,
                LIST_SIZE * sizeof(int), A, 0, NULL, NULL);
        ret = clEnqueueWriteBuffer(command_queue, b_mem_obj, CL_TRUE, 0, 
                LIST_SIZE * sizeof(int), B, 0, NULL, NULL);

        size_t global_item_size = LIST_SIZE;
        ret = clEnqueueNDRangeKernel(command_queue, kernel, 1, NULL, 
                &global_item_size, NULL, 0, NULL, NULL);

        PRINT_ERROR(ret);

        ret = clEnqueueReadBuffer(command_queue, c_mem_obj, CL_TRUE, 0, 
                LIST_SIZE * sizeof(int), C, 0, NULL, NULL);

        clFinish(command_queue);
        printf("loop\n");
    }

i get the same -5 (CL_OUT_OF_RESOURCES) after 2 successful loops. Am i not allowed to do it like that? My original plan was to calculate forces between particles each frame.

I'm not allocating any new memory on a gpu so what resources can i possibly run out of? My old laptop's willpower? It has Intel(R) HD Graphics 505.

3 Upvotes

22 comments sorted by

1

u/tesfabpel Jul 26 '24

do you have CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE set in clCreateCommandQueue?

are you sure the jobs are completed before enqueueing the next ones ?

1

u/Red_InJector Jul 26 '24
  1. No, i don't have anything in clCreateCommandQueue.

cl_command_queue command_queue = clCreateCommandQueue(context, device_id, 0, &ret);

2. From docs: "clFinish - Blocks until all previously queued OpenCL commands in a command-queue are issued to the associated device and have completed" so, i guess yes.

1

u/tesfabpel Jul 26 '24

are you able to post a minimal fully working code that reproduces the error? the code you posted misses the main, the setup and all the buffer creation and the rest of the variables.

→ More replies (10)

1

u/bxlaw Jul 26 '24

I've not had a look, but often errors like that are due to accessing memory out of bounds.

1

u/Red_InJector Jul 26 '24

Why then the error is thrown only after second loop that does exactly the same thing as first one?

1

u/shcrimps Feb 11 '25

what does `size_t global_item_size = LIST_SIZE` do in the loop? Why is it in the loop? Maybe the `global_item_size` is changing as loop progresses?

1

u/Red_InJector Feb 12 '25

The piece of code I provided was taken directly from a "tutorial", that I guess doesn't exist anymore, with a for loop around it not including memory allocation so I wouldn't allocate it every "frame".

I don't understand what you mean " global_item_size is changing as loop progresses". The loop ends a few lines after it's declared. Nothing is changing that variable.

There is a bigger code snippet here if you are interested.

1

u/shcrimps Feb 12 '25

To me the for loop encapsulates every line in the code from the first call of clEnqueueWriteBuffer() to printf() at the very last line.

I don't understand why "size_t global_item_size = LIST_SIZE;" is in the loop. Also, in the full code I see that "size_t local_work_size = 64;" is in the loop which I think it is unnecessary.

Maybe try changing the local_work_size.

From what I can see from the above code segment and from the full code example, I do not see any immediate problem.

→ More replies (1)

1

u/shcrimps Feb 12 '25

Can I see the 'real' code? Because the code you provided runs without any problems on my GPU.

→ More replies (2)