You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Debian Bookworm, Linux 6.5.13, OpenCL 3.0 Intel 22.43.24595 ICD Loader 2.3.1 on UHD Graphics P630 (Xeon E-2274G)
Description
After finding out our new server GPU supported OpenCL and it appeared to effectively save one of four cores (and offer a ~20% speedup for image scaling) I was very excited.
However I found out with intel_gpu_top that the Render/3D cores were not being used in production once the system had been fully set up. Curious, I tried to run it manually and ran into this headscratcher:
This was rather confusing, as I wasn't trying to blur the image, and further error messages would have been useful to help identify the root cause - a policy restriction impacting a component of the OpenCL benchmark.
Steps to Reproduce
Rather, the operation was along the lines of a scaling in linear colour space:
(It is possible there are other deficiencies in this policy, which was established in a hurry after seeing what happened to other sites a few years ago, along with compiling our own build to reduce surface area - I just include it because it led to the issue.)
XC is not mentioned in the OpenCL requirements. We probably didn't notice this earlier because the home directory for www-data was unset (it was in the render group to access the device node) so it would have failed even earlier on with something like:
This can be duplicated with e.g. MAGICK_OPENCL_CACHE_DIR=/root MAGICK_OCL_DEVICE=true on a regular user. It's a bit insidious because the convert then works, it's just not accelerated. Perhaps this is better than not working, though.
After defining a dir and adding <policy domain="coder" rights="read" pattern="{XC}" /> to policy we got a better experience:
The effect is dominated by PNG compression; the CPU benefit is even more noticeable with a 15300x8925 JPG.
$ time MAGICK_OCL_DEVICE=GPU convert JPEG:test.jpg -gamma 0.454545454545455 -filter Lanczos2 -resize '920x920>' -gamma 2.2 -sampling-factor 1x1 -quality 95 -strip +profile '*' -depth 8 JPEG:screen.jpg
real 0m5.233s
user 0m10.870s
sys 0m0.245s
$ time convert JPEG:test.jpg -gamma 0.454545454545455 -filter Lanczos2 -resize '920x920>' -gamma 2.2 -sampling-factor 1x1 -quality 95 -strip +profile '*' -depth 8 JPEG:screen.jpg
real 0m6.549s
user 0m28.351s
sys 0m0.225s
FWIW, a JPG of 16000x9000 was not accelerated and it was not clear why, although looking at the source there are many potential exit points. Debug just showed that it opened and closed a pixel cache, where normally it would have had this in the middle:
Accelerate convert[1754212]: opencl.c/AcquireOpenCLKernel/726/Accelerate Using kernel: ResizeHorizontalFilter
Accelerate convert[1754212]: opencl.c/AcquireOpenCLKernel/726/Accelerate Using kernel: ResizeVerticalFilter
before doing it the regular way. We have few files that size, and it worked on 15300x8925 and 10963x12350, so not really an issue. The iGPU's own limit on JPEG output is 16k so perhaps it's running into that. Anyway, just mentioning that in passing - the issue here is that Accelerate failed in a confusing way, and from the error message it wasn't clear that it was OpenCL-related, let alone policy. Possibly this is because OpenCL was added before security policies became popular, so xc: would very rarely be restricted.
The text was updated successfully, but these errors were encountered:
GreenReaper
changed the title
OpenCL accelerate fails with confusing reason if policy prevents benchmark execution due to xc: delegate
OpenCL accelerate fails with confusing reason if policy prevents benchmark execution due to xc: coder
Dec 4, 2023
Thank you for reporting the issue. We have successfully reproduced it and are actively working on a patch to resolve it. You can expect this patch to be merged into the main GIT branch, later today. As part of our commitment to quality, this fix will also be included in the upcoming beta releases of ImageMagick by tomorrow. Your patience and feedback are greatly appreciated.
ImageMagick version
7.1.1-21 Q16 x86_64 21667
Operating system
Linux
Operating system, version and so on
Debian Bookworm, Linux 6.5.13, OpenCL 3.0 Intel 22.43.24595 ICD Loader 2.3.1 on UHD Graphics P630 (Xeon E-2274G)
Description
After finding out our new server GPU supported OpenCL and it appeared to effectively save one of four cores (and offer a ~20% speedup for image scaling) I was very excited.
However I found out with intel_gpu_top that the Render/3D cores were not being used in production once the system had been fully set up. Curious, I tried to run it manually and ran into this headscratcher:
This was rather confusing, as I wasn't trying to blur the image, and further error messages would have been useful to help identify the root cause - a policy restriction impacting a component of the OpenCL benchmark.
Steps to Reproduce
Rather, the operation was along the lines of a scaling in linear colour space:
Eventually I found the very helpful -debug that helped me track down the blur in question that uses xc: assuming it works:
This referred to our policy, which consisted of the following:
(It is possible there are other deficiencies in this policy, which was established in a hurry after seeing what happened to other sites a few years ago, along with compiling our own build to reduce surface area - I just include it because it led to the issue.)
I am not sure if this would apply to the currently-suggested module-based web server security policy, or websafe policy i.e.
XC is not mentioned in the OpenCL requirements. We probably didn't notice this earlier because the home directory for www-data was unset (it was in the render group to access the device node) so it would have failed even earlier on with something like:
This can be duplicated with e.g.
MAGICK_OPENCL_CACHE_DIR=/root MAGICK_OCL_DEVICE=true
on a regular user. It's a bit insidious because the convert then works, it's just not accelerated. Perhaps this is better than not working, though.After defining a dir and adding
<policy domain="coder" rights="read" pattern="{XC}" />
to policy we got a better experience:The effect is dominated by PNG compression; the CPU benefit is even more noticeable with a 15300x8925 JPG.
FWIW, a JPG of 16000x9000 was not accelerated and it was not clear why, although looking at the source there are many potential exit points. Debug just showed that it opened and closed a pixel cache, where normally it would have had this in the middle:
before doing it the regular way. We have few files that size, and it worked on 15300x8925 and 10963x12350, so not really an issue. The iGPU's own limit on JPEG output is 16k so perhaps it's running into that. Anyway, just mentioning that in passing - the issue here is that Accelerate failed in a confusing way, and from the error message it wasn't clear that it was OpenCL-related, let alone policy. Possibly this is because OpenCL was added before security policies became popular, so xc: would very rarely be restricted.
The text was updated successfully, but these errors were encountered: