Search code examples
pythonpython-3.ximagemagickopenclwand

How to disable OpenCL with wand in python


So I'm using wand for a project and it's been working fine, except whenever I want to use a function that has been 'OpenCL-accelerated' (list of functions here), it stops working, no error or anything, but I'm pretty sure that OpenCL is what's causing it.

So my question is, how can I disable OpenCL in wand so that I can use those functions? Again, I've looked for solutions, but alas I couldn't find anything python specific, and the api module and the python module itself don't seem to mention anything about it either.

Any help would be greatly appreciated, thanks!


Solution

  • Just set the environment variable MAGICK_OCL_DEVICE=off to disable OpenCL.

    Either before running the script.

    export MAGICK_OCL_DEVICE=OFF
    python myScript.py
    

    Or within the python script before invoking any Wand code.

     import os
    
     os.environ['MAGICK_OCL_DEVICE'] = 'OFF'
    
     # ... wand stuff ...
    

    And the reason that it looks like your application stops running is that ImageMagick will need to run an OpenCL benchmark the first time and that can take a while. The result of the benchmark will be cached and used the next time an "OpenCL-accelerated" method is executed.