imagick icon indicating copy to clipboard operation
imagick copied to clipboard

OpenCL acceleration not working

Open fubla opened this issue 8 years ago • 5 comments

When using a version of ImageMagick built with OpenCL enabled, I can see no increase in performance in the resize operation. This has been verified using numerous performance tests. However, there is a significant increase in performance when using ImageMagick from the command line, as such I am quite certain this has to do with the go bindings rather than the ImageMagick build.

fubla avatar Apr 14 '16 12:04 fubla

imagick bindings are pretty thin wrappers over the C api. That means we don't do much business logic. Only type conversions and then calling right into C. So I am not sure where we would be missing something.

Have you tested against the C api directly to see of you get your speed ups? Maybe there is logic in the command line tools that switches to other code if Opencl is enabled, and it is not handled directly in the C api resize calls that we wrap?

justinfx avatar Apr 14 '16 19:04 justinfx

hmm.. maybe an issue in how the imagemagick static library is linked with opencl...? then when CGO linked to the Go package, its not bringing with it opencl? or, second, figure out how to force enable opencl. I'd be very interested in this as well if opencl did actually increase performance of resizing, that would be awesome.

pkieltyka avatar Apr 14 '16 19:04 pkieltyka

I took a brief look at this and the ImageMagick docs say that the first time you call OpenCL accelerated operations (retime, ...) the OpenCL initialisation is done and all the kernels are compiled, etc, etc. I also see code in the C++ layer for initialising: https://github.com/ImageMagick/ImageMagick/blob/e93e339c0a44cec16c08d78241f7aa3754485004/Magick%2B%2B/lib/Functions.cpp#L37

Maybe we need to wrap the opencl init function and see if it needs to be called directly? https://github.com/ImageMagick/ImageMagick/blob/e93e339c0a44cec16c08d78241f7aa3754485004/MagickCore/opencl.h#L54

justinfx avatar Apr 15 '16 05:04 justinfx

Actually I forgot to mention that I made a fork of this repository and made my own wrapper for the InitImageMagickOpenCL(ImageMagickOpenCLMode,void_,void_,ExceptionInfo*) -function. It did not provide any solution whatsoever. I also tried to bind to the accelerated resize function: https://github.com/ImageMagick/ImageMagick/blob/e93e339c0a44cec16c08d78241f7aa3754485004/MagickCore/accelerate.h#L40 I'm not very proficient with CGo yet so I could not get it to work, partly because of differences with Image structs which MagickCore uses and Image structs inside MagickWand structs.

fubla avatar Apr 15 '16 06:04 fubla

Here is the link to my wrapper: https://github.com/fubla/imagick/blob/master/imagick/opencl.go

fubla avatar Apr 15 '16 06:04 fubla