Wait if CL_DEVICE_NOT_AVAILABLE is returned?

Hi there,

I’m now pushig my Project to work in multiple instances. One error thats hard to produce but happens often is CL_DEVICE_NOT_AVAILABLE while creating the context. Do you think it is good practice to wait when you get this? I can’t sync over multiple instances of the program so blocking would not solve the problem.

Thanks in advance,
clint3112

P.S.: If the topic already exists, I could not find it, because the search term “CL_DEVICE_NOT_AVAILABLE” was rejected by the search system (all 4 words are too common)

Why is the device unavailable? By the sounds of it, you are launching more instances of your program than there are devices. Is that correct?

Whether it is good practice to wait depends on the program you are writing and the program that is using the device? Please give some more details about both. Also, what hardware are you using?

Correct with the Instances.

My Program has only a small part of openCL and lots of other parts with many user interaction. I had to run 6 instances in parallel end do some mouse artistics to get the error. OpenCL is only used for a few secs in each instance, so there is a good chance that it will never happend to a user but still i have to avoid this problem.

What i am doing right now is:

  1. try to aquire the context
    a. if i get the context, continue
    b. if i get Dev_not_available show a modal dialoge that says “please wait until the calculations of other instances are completed an press okay”. Than will try to get the context again.

I could answer the hardware question for my dev PC (x990 + gtx580) but the user will not have that compute caps. So maybe they will get the problem more often.

Greetings
Clint3112

Ah, now I understand why you are doing this. In addition to trying to create the context and catch an error when that fails, you could also query the device properties for CL_DEVICE_AVAILABLE. If that returns CL_TRUE then your program should be able to continue. If CL_FALSE, show the error. Strangely enough, I have run code that has used two contexts on a device at the same time without any problems. Perhaps the number of contexts is implementation specific.

As you said, you used “just” two. I was actively working on 6 in parallel. So the problem might be that an enqueue call came “at the same time”, the createContext was called. It worked with 5 / 6 in parallel most of the time :wink:
Thanks for the hint. Maybe that could bring me the extra time i need to get that running.