Kernel Guidelines

What code can and can't be converted to OpenCL by Aparapi.

Aparapi Java Kernel Guidelines

Certain practices can improve the chances of your Java kernel being converted to OpenCL and executing on a GPU.

The following guidelines/restrictions only apply to the method and any method reachable from run() (called” run-reachable methods” in this documentation), clearly any methods executed via a normal Java execution path will not be subject to these restrictions.

Some restrictions/guidelines may be removed or augmented in a future Aparapi releases.

Data Types




Other Restrictions

        int foo(int a) {
           // . . .
        public void run() {
          int z;
          foo(z = 3);

Beware Of Side Effects

OpenCL is C99-based and as such the result of expressions depending on side effects of other expressions can differ from what one might expect from Java, please avoid using code that assumes Java’s tighter rules. Generally code should be as simple as possible. For example, although Java explicitly defines

        arra[i++] = arrb[i++];

to be equivalent to

        arra[i] = arrb[i+1];
        i += 2;

The C99/OpenCL standard does not define this and so the result would be undefined.

Runtime Exceptions