狠狠撸

狠狠撸Share a Scribd company logo
OpenCL in GEGL and GIMP
     Victor Oliveira

Libre Graphics Meeting 2012
The goats are ?nally running!
GIMP was designed to process images with 8-bits per channel.
    ? Artifacts
    ? Noise

GEGL is optimized to do it in high-depth formats, like ?oating-point.
Processing images in ?oating-point is intensive.
How can we improve GEGL performance?
The solution: making ?oating-poing processing
faster using GPUs, multi-threading and vectorization!

               (All to do with OpenCL)
But what is OpenCL?
? A language for writing functions that
 execute in OpenCL devices:
    ? GPUs
    ? Multi-core CPUs
? An API to control these OpenCL devices
? A speci?cation
? A shared library (you can use it in your C/C++ code)
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;
}
Common ?ow 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
AMD, Intel and Nvidia proprietary implementations.

Mesa open-source implementation is progressing fast.
What I have done:
? Automatic data transference to the
 OpenCL Device when necessary
? Conversion between color spaces
? A simple API for writing OpenCL
 ?lters in GEGL
? Benchmarking
? Integrating this work in the next
 release of GIMP (2.8)
Sharing data in the OpenCL Device among many operations
Implementing OpenCL support in GEGL and GIMP
Implementing OpenCL support in GEGL and GIMP
Implementing OpenCL support in GEGL and GIMP
Implementing OpenCL support in GEGL and GIMP
Color conversion in the OpenCL Device
Implementing OpenCL support in GEGL and GIMP
Point Operations API
Implementing OpenCL support in GEGL and GIMP
Benchmarks

(GEGL single-threaded x GEGL w/ OpenCL)
Implementing OpenCL support in GEGL and GIMP
Pro?ling is hard.
Implementing OpenCL support in GEGL and GIMP
Implementing OpenCL support in GEGL and GIMP
Implementing OpenCL support in GEGL and GIMP
? OpenCL is a portable and e?cient
 way to write ?lters in GEGL/GIMP.
? There is a huge performance boost
 using GPUs.
? On CPUs, we gained multi-core support
 for free.
? 91 commits - 14,161 lines changed,
 code in GEGL 0.20, which is required
 by GIMP 2.8.
What is left to be done:
? Testing by users on di?erent
 cards/drivers/cpus and feedback
? Porting more ops to OpenCL
? Multiple GPUs support
? OpenGL output node for GEGL
? The more GIMP uses GEGL, more
 performance gains
Thanks!

  Victor Oliveira (victorm)
victormatheus@gmail.com

More Related Content

Implementing OpenCL support in GEGL and GIMP