How the JIT compiler uses a GPU (Linux, Windows only)

You can enable the Just-In-Time (JIT) compiler to offload certain processing tasks to a general-purpose graphics processing unit (GPU). The JIT determines when to offload these tasks based on performance heuristics.

A parallel().forEach loop runs a section of code multiple times in parallel by using different threads. This type of parallel processing task is suited to processing on a GPU, which has thousands of cores that can run the same instruction at the same time. However, because there is an overhead in moving data between the CPU and GPU, the JIT offloads processing only when certain performance heuristics are met.

When enabled, the JIT compiler attempts to accelerate the following Java™ constructs by launching the corresponding lambda expression on the GPU:
IntStream.range(<range>).parallel().forEach(<lambda>)
IntStream.rangeClosed(<range>).parallel().forEach(<lambda>)
Where:
  • <range> defines upper and lower bounds.
  • <lambda> is a correctly defined lambda expression.
This JIT optimization handles the following constructs inside the lambda expression:
Types
Variables and one-dimensional arrays of all Java primitive types.
Storage
Automatic, parameters, and instance variables. Static variables are not supported.
Operations
All Java operators except instanceof.
Statements and expressions
All Java statements and expressions except new, throw, and method invocations.
Java exceptions
All standard Java exceptions, which includes NullPointerException, ArrayIndexOutOfBoundsException, and ArithmeticException.
The following operations are not supported:
  • Method invocations.
  • Intermediate operations like map or filter.
  • User exceptions.
Note: Some calls are inlined by the JIT compiler

You can enable GPU processing by setting the -Xjit:enableGPU option on the command line when you start your application. For more information, see Enabling application processing on a graphics processing unit (Linux, Windows only).

To offload processing to a GPU, your system must meet the minimum requirements that are specified in GPU system requirements (Linux, Windows only). If you are experiencing problems, see GPU problem determination (Linux, Windows only).