Implementing OpenCL support in GEGL and GIMP

2,879 views

Published on

"In this session I'm going to describe some efforts to bring OpenCL acceleration to the General Graphics Library (GEGL) and the GNU Image Manipulation Program (GIMP). I intend to show the current state of the project, some implementations techniques used and performance comparisons among common GPUs."

Published in: Design, Technology, Art & Photos
  • Be the first to comment

Implementing OpenCL support in GEGL and GIMP

  1. 1. OpenCL in GEGL and GIMP Victor OliveiraLibre Graphics Meeting 2012
  2. 2. The goats are finally running!
  3. 3. GIMP was designed to process images with 8-bits per channel. • Artifacts • NoiseGEGL is optimized to do it in high-depth formats, like floating-point.
  4. 4. Processing images in floating-point is intensive.How can we improve GEGL performance?
  5. 5. The solution: making floating-poing processingfaster using GPUs, multi-threading and vectorization! (All to do with OpenCL)
  6. 6. But what is OpenCL?
  7. 7. ✔ A language for writing functions that execute in OpenCL devices: • GPUs • Multi-core CPUs
  8. 8. ✔ An API to control these OpenCL devices
  9. 9. ✔ A specification
  10. 10. ✔ A shared library (you can use it in your C/C++ code)
  11. 11. for (i=0; i<n_pixels; i++) { out_pixel[0] = (in_pixel[0] - 0.5f) * contrast + brightness + 0.5; out_pixel[1] = (in_pixel[1] - 0.5f) * contrast + brightness + 0.5; out_pixel[2] = (in_pixel[2] - 0.5f) * contrast + brightness + 0.5; out_pixel[3] = in_pixel[3]; /* copy the alpha */ in_pixel += 4; out_pixel += 4; }__kernel void gegl_brightness_contrast(__global const float4 *in, __global float4 *out, float contrast, float brightness){ int gid = get_global_id(0); float4 in_v = in[gid]; float4 out_v; out_v.xyz = (in_v.xyz - 0.5f) * contrast + brightness + 0.5f; out_v.w = in_v.w; out[gid] = out_v;}
  12. 12. Common flow in a OpenCL program:➡ Write code in the OpenCL language➡ Detect the device➡ Build your code➡ Transfer data to the device➡ Run your OpenCL program➡ Transfer data back from device
  13. 13. AMD, Intel and Nvidia proprietary implementations.Mesa open-source implementation is progressing fast.
  14. 14. What I have done:
  15. 15. ✔ Automatic data transference to the OpenCL Device when necessary
  16. 16. ✔ Conversion between color spaces
  17. 17. ✔ A simple API for writing OpenCL filters in GEGL
  18. 18. ✔ Benchmarking
  19. 19. ✔ Integrating this work in the next release of GIMP (2.8)
  20. 20. Sharing data in the OpenCL Device among many operations
  21. 21. Color conversion in the OpenCL Device
  22. 22. Point Operations API
  23. 23. Benchmarks(GEGL single-threaded x GEGL w/ OpenCL)
  24. 24. Profiling is hard.
  25. 25. ✔ OpenCL is a portable and efficient way to write filters in GEGL/GIMP.
  26. 26. ✔ There is a huge performance boost using GPUs.
  27. 27. ✔ On CPUs, we gained multi-core support for free.
  28. 28. ✔ 91 commits - 14,161 lines changed, code in GEGL 0.20, which is required by GIMP 2.8.
  29. 29. What is left to be done:
  30. 30. ✔ Testing by users on different cards/drivers/cpus and feedback
  31. 31. ✔ Porting more ops to OpenCL
  32. 32. ✔ Multiple GPUs support
  33. 33. ✔ OpenGL output node for GEGL
  34. 34. ✔ The more GIMP uses GEGL, more performance gains
  35. 35. Thanks! Victor Oliveira (victorm)victormatheus@gmail.com

×