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.
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.
- 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.
- Method invocations.
- Intermediate operations like
map
orfilter
. - User exceptions.
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).