Blender OpenCL proposal


Typical desktop systems have multiple Processing Units (PU). The two most common Processing Units are the CPU and the GPU. The CPU is the main processor of a system. The GPU is specialized in Graphical processing. Over the last years the GPU became more powerful than the CPU. A CPU has typically 1-4 cores as the GPU can have 100 smaller cores.

GPU is accessed differently, than a CPU. This makes it hard to develop applications for it. OpenCL is a open standard that enables easier development for GPU’s and eventually their goal is heterogeneous computing systems (a system where multiple types of processing units can work together).


Currently only the MAC OS-X installs the OpenCL libraries by default. ATI and NVIDIA drivers can install OpenCL libraries on Windows and Linux systems.

To install OpenCL on Windows and Linux systems you need to install an OpenCL-implementation. NVIDIA and AMD/ATI deploy an implementation of the standard. But for now these are specialized for their GPU. At the moment only ATI has drivers that combines CPU and GPU in a single OpenCL implementation.

When using OpenCL within the Blender architecture it can only be done as an optional component. It can only be used when enabled by the user. Reasons for this are:

  1. not all development systems have OpenCL SDK’s installed
  2. not all system have OpenCL
  3. technical limitation of using OpenCL (like memory limits and not optimal OpenCL code for the specific task)


Compiler settings

  • WITH_OPENCL: This setting allows blender to be compiled with OpenCL support. Without this flag all linkage to OpenCL will not be compiled and linked.


commandline options

–enable-opencl: this setting will enable OpenCL inside Blender. Default OpenCL will not be used.


Changes in Blenderkernel

Add BKE_opencl.h and opencl.c. These files will add basic functions that can be used to identify if OpenCL must be used.

//this method can be called inside blender code to make sure if opencl is enabled
//by the user
int BKE_opencl_is_enabled();

// this method is called when the user places the –opencl startup flag. It will initialize
// the opencl library and search for suitable open cl devices.
// when no suitable devices are found the BKE_is_opencl_enabled() will return
// negative

// this method will be called as a shutdown hook to the blender process.
// it will deinitialize the opencl system and release all allocated resources.

// get the gpu device
BKE_opencl_get_gpu_device (hints);



Design principles

There must always and I say ALWAYS be a fall-back to normal CPU execution (without the usage of the OpenCL library).

GPU based rendering is not the goal. First get experience how the library works. Converting the internal blenderrenderer is not the (targeted) goal of this implementation.


First step

  • implement changes to the blender kernel
  • use these changes to implement a first test-case (eg. remove doubles?)
  • with this we can check how the implementation works on different platforms (OS, Graphical cards manufacturer, etc) and fine-tune where needed.
  • Implement a good test-case like the fractal generator (not in trunk ), not functional but be able to show the speedup to get sponsors interesting.


Next step

  • device and platform selection in system-preferences
  • basic opencl monitoring
  • use OpenCL in different area’s:
    • Compositing node system
    • Particle systems: SPH, boids
    • Baking, (for fluids and smoke etc)
    • Others…


Implementation pattern

Everywhere OpenCL is used the next coding-pattern can be used.


If (BKE_is_opencl_enabled() && doGPUCalculationInitialization() != ERROR) {
} else {
 // do normal CPU calculation due to memory limits or no opencl enabled system


Release target

I am not targeting this for Blender 2.5! perhaps a first release in Blender 2.6 but only when stable and tested. There are other people already working on this subject. The first implementation will be done in a separated branch.



Comments are closed.