Skip to content
Snippets Groups Projects

Gray-Scott with SYCL

SYCL Setup : DO IT BEFOREHAND !

With SYCL, you benefit from easier coding of portable parallel code... and typically suffer from harder setup. This document try to help.

To be fully accompanied in this GrayScoot course, you should better have Intel oneAPI installed on your computer, or have access to a computing center where it is.

Another famous implementation of SYCL is AdaptativeCpp, but we have not tested it enough. You can use it if you prefer and know how to, but you are on your own.

Be aware that the basic Intel oneAPI installation will only see the Intel hardware, unless you additionally installed some specific plugins, such a the codeplay ones. In the following, we generally only address the NVidia/CUDA plugin. If you want to work with an AMD card, we encourage, but you are on your own ;)

Also, most of our instructions and utility scripts assume you are running a bash shell.

The following alternative strategies are proposed in priority:

The additional alternatives below nicely provide an integrated Visual Studio Code Server, but they have been less tested, due to a lack of time:

Gray-Scott in a nutshell

We let you investigate on your own the details of the chemical background for the Gray-Scott reaction.

For what concerns this tutorial, just retain that we must iterativaly modify two images, one which is the grid of the U values, and the other which is the grid of the V values.

For each iteration, each pixel will evolve depending on the values of U and V in their neighbourhood, what is often called a "stencil algorithm".

For the needs of this tutorial, we will consider the 8 immediate neighbours, and those parameters will be fixed (pseudo-code):

DIFFUSION_RATE_U = 0.1
DIFFUSION_RATE_V = 0.05
KILL_RATE = 0.062
FEED_RATE = 0.03
DT = 1.0

So to start the chemical reaction, we drop some V in a central area of the grid. The arbitrary drop size is 4x6, which results in 0 values in the U grid, and 1 values in the V grid.

Then we compute step by step the evolution of U and V. Given the pixel row r, and the pixel column c, one iteration may be written (pseudo-code):

for ( dr : -1, 0, 1 )
  for ( dc : -1, 0, 1 )
	full_u += u[r+dr,c+dc] - u[r,c]
	full_v += v[r+dr,c+dc] - v[r,c]

uvv = u[r,c]*v[r,c]*v[r,c]
du = DIFFUSION_RATE_U*full_u - uvv + FEED_RATE*(1.0 - u)
dv = DIFFUSION_RATE_V*full_v + uvv - (FEED_RATE + KILL_RATE)*v

u[r,c] += du*DT;
v[r,c] += dv*DT;

Have a look at the code in the directory GrayScottSeq/src/gray-scott.cpp. Understand and run it with the commands below. The value printed at the end is juste there as a first check that the code is working as expected, when you will try to parallelize it. This final magic number is possibly different for every user. Also, you can inspect the steps in coliru.bash and adapt it to your own needs.

cd GrayScottSeq
./coliru.bash

Virtual tutors

currently require a password

Prototyped with Corolair:

SYCL Webography

SYCL general ressources

Training and documentation

Specific implementations

Other useful resources