This project has moved. For the latest updates, please go here.

Choose which GPU is used for OpenCL

Aug 11, 2016 at 2:34 PM
Hi Dirk,

This may be a weird question since I'm not too sure how OpenCL is utilized (or how it works in general).

While testing MagickNET on a computer with both an onboard/integrated graphics (Intel HD Graphics) as well as a separate GPU (GTX 780), the executable finishes and exits, but the EXE file itself is locked and won't release until the computer is rebooted.

The Windows Event Log says the culprit is igdrcl64.dll - which seems to be the Intel driver responsible for OpenCL. This may very well be a localized issue, but I was curious to see if IM or MagickNET can be instructed to use a specific GPU only for OpenCL operations.

Aug 11, 2016 at 2:54 PM
Edited Aug 11, 2016 at 2:56 PM
It might be possible that we don't unload the library when the application is unloaded. I will try and see if I can reproduce your issue. Would it be possible to give me access to a machine where I can reproduce this issue with a simple executable (not your whole program) to reproduce this issue? We could also have a chat on Skype and I can watch your screen if that is an option. This is of course only in the case when I cannot reproduce it.

You can configure OpenCL with the OpenCL class. You might need to upgrade to get that class since it was added recently. Feel free to reply to my message if you want a bit more explanation of that class.
Aug 11, 2016 at 2:57 PM
Thanks for the quick response!!

Might be that I'm still on an older build. I haven't switched since before IM 7 was in beta. I'll recompile with the latest libs and let you know if the problem persists.
Aug 11, 2016 at 4:32 PM
Edited Aug 11, 2016 at 4:32 PM
Investigated a bit more in detail. In previous versions (7.0.0.x), the Native.dll file was locked. The latest version ( does not have this problem. :)
Aug 11, 2016 at 4:48 PM
Looks like I spoke too.

Accessing the OpenCL object in keeps the process alive even after exiting.

If it helps, here are the Event Log details:
Fault bucket 120529672833, type 4
Event Name: APPCRASH
Response: Not available
Cab Id: 0

Problem signature:
P1: ImageProcesser.exe <----- this is my executable
P2: 2.0.603.622
P3: 57aca9ad
P4: igdrcl64.dll
P6: 57462743
P7: c0000005
P8: 000000000007a74a

Faulting application name: ImageProcesser.exe, version: 2.0.603.622, time stamp: 0x57aca9ad
Faulting module name: igdrcl64.dll, version:, time stamp: 0x57462743
Exception code: 0xc0000005
Fault offset: 0x000000000007a74a
Faulting process id: 0x7a18
Faulting application start time: 0x01d1f3ee966de51c
Faulting application path: Z:\Workspaces\Distribution\Current\Programs\ImageProcesser.exe
Faulting module path: C:\WINDOWS\SYSTEM32\igdrcl64.dll
Report Id: a405a5fc-7be3-4a0b-8137-af13f06f48c0
Faulting package full name: 
Faulting package-relative application ID: 
Aug 11, 2016 at 9:27 PM
Edited Aug 11, 2016 at 9:27 PM
It looks like your OpenCL library crashes. Can you upgrade your videocard driver to the latest version and see if that resolves your issue? This could also be a bug in the ImageMagick OpenCL code. Can you reproduce the issue on the command line with ImageMagick 7?
Aug 12, 2016 at 8:41 AM
So turns out it was a strange driver conflict. I was not using the integrated Intel HD Graphics and both my monitors were running on the main nVidia GPU board.

The OpenCL class would detect the CPU and the main GPU only. Now I plugged one monitor into the integrated graphics port and the problem instantly goes away.

My guess is that the problem is in ASUS's drivers for the integrated GPU, since it is different from Intel's distro. With the problem resolved I did not try IM7 command line. If it pops up again, will do.

Thanks for your help!
Aug 22, 2016 at 6:48 PM
Hey Dirk,

I had a followup question. The OpenCL class detects 3 devices (CPU, onboard GPU, main GPU), but only one is enabled (GPU). So I'm forcing all three to be enabled in the hopes that the OpenCL-enhanced code will utilize all enabled devices. Is that assumption correct? Or am I better off using only just the device with the best score?

Aug 23, 2016 at 6:35 PM
It is correct that each device will be used when you enable them all but the usage will be based on the score. Each time an OpenCL operations takes place a request is made for an OpenCL device. If none are enabled then OpenCL accelerated method will not be excuted. And when one device is enabled it will use that one. The special case is multiple devices. Based on the score it will pick a device. The calculation is score*timesUsed. So if one device has a score of 5 and the other one 10 it will use the second device 2 times and the first one 4 times. For most situations only enabling one device is the best though.