Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCL Cloo: Out of Resources Error

While running some test code in OpenCL (using Cloo C#), I started getting these OutOfResource errors from OpenCL and sometimes Unity just crashes entirely before I get an exception. I am basically re-calling a kernel function over and over with varying number of global/local work items to check timing. I leave the arguments the same and call the kernel starting with 2x2x2 global and 2x2x2 local and iterating uperwards checking only valid sizes. It works fine occasionally, but most of the time it completes about 30 or 40 Execute() calls and then crashes on the next Execute() call.

Note: Execute refers to the OpenCL.dll on the computer. The stack trace Unity returns is NULL I assume because of the native code.

Anyone have any idea what could be causing this?

Note: This version of Cloo is Cloo-Unity from GitHub and I am using it in Unity. The equivalent OpenCL function being called when I get the error is clEnqueueNDRangeKernel(), but it is called Execute() in Cloo.

Code Sample:

//Setup inputs one time...
foreach (var input in p_inputs)
{
     inputs.Add(input.Function, input);
     profiles.Add(input.Function, new RunProfile(input.Function, input.Weight));
     input.Input.Prepare(package[input.Function]);
}


//Profile...
DateTime start;
int g_state = 0;
int l_state = 0;
long[] g = new long[3] { 2, 2, 2 };
long[] l = new long[3] { 2, 2, 2 };
while(g[0] * g[1] * g[2] < Device.MaxWorkGroupSize)
{
       l[0] = 2; l[1] = 2; l[2] = 2; l_state = 0; //Reset locals
       bool proceed = true;
       while(proceed)
       {
           proceed = (l[0] != g[0] || l[1] != g[1] || l[2] != g[2]);

           if (CLUtilities.ValidateExecutionParameters(Device, g, l))
           {
               Debug.Log("Profiling Start: " + g.ToEnumeratedString() + " / " + l.ToEnumeratedString());
               foreach (var profile in profiles)
               {
                   start = DateTime.Now;
                   //Exception here when on (g=6x4x4, l=6x4x4) 
                   package.Execute(package[profile.Key], g, l);
                   package.Commands.Flush();
                   package.Commands.Finish();
                   float time = (float)(DateTime.Now - start).TotalMilliseconds;
                   profile.Value.AddRun(g, l, time);
               }
               Debug.Log("Profiling Ending: " + g.ToEnumeratedString() + " / " + l.ToEnumeratedString());
           }

           l[l_state] += 2;
           l_state = (l_state == 2) ? 0 : l_state + 1;
       }

    g[g_state] += 2;
    g_state = (g_state == 2) ? 0 : g_state + 1;
}
like image 221
guitar80 Avatar asked Mar 29 '16 15:03

guitar80


Video Answer


2 Answers

Sorry i cannot comment cause less than 50 rep. but which operating system do you use? gpu? driver? i got similar problems caused by opencl.dll i used win10 and Nvidia (x64). Also have a look on https://social.technet.microsoft.com/Forums/en-US/85680348-c2c4-40bc-9f39-9dcfeea331c0/windows-10-opencldll-error?forum=win10itprogeneral

It seems that there is/was a issue with the memory compression in win10.

My problem was caused by updating win7 to win10, without updating the nvidia drivers.

like image 64
Matthias Rittler Avatar answered Oct 14 '22 12:10

Matthias Rittler


I just got back around to posting this, but the issue turned out be related to the fact that I didn't recall Kernel.SetArgument() each time I called the Execute() method. I originally did this because I was worried it would re-copy the buffer, but as it turns out the buffer copy doesn't occur in this method anyway (so the overhead was small anyway).

like image 31
guitar80 Avatar answered Oct 14 '22 10:10

guitar80