Working alongside GPU libraries
Questions
My code needs to use a library, how should they work together?
How to use OpenMP mapped variables?
How to use CUDA or HIP device variables into OpenMP?
Objectives
Understand TODO
Understand TODO
Understand
Understand
Prerequisites
TODO
TODO
First heading
OpenMP interoperability with CUDA C/C++ and CUDA Fortran.
You can call kernels written in CUDA C/C++ or CUDA Fortran in your OpenMP programs from the host.
You can use the OpenMP USE_DEVICE_PTR clause to pass OpenMP mapped variables to CUDA kernels that are launched from the host.
You can use the OpenMP IS_DEVICE_PTR clause to access CUDA device attribute variables or to pass device addresses directly to target regions.
Second heading
Some more text, with a figure
Exercise
TODO get the students to think about the content and answer a Zoom quiz
Solution
Hide the answer and reasoning in here
Some source code
Sometimes we need to look at code, which can be in the webpage and optionally you can pull out only some lines, or highlight others. Make sure both C++ and Fortran examples exist and work.
The field data structure
struct field {
// nx and ny are the dimensions of the field. The array data
// contains also ghost layers, so it will have dimensions nx+2 x ny+2
int nx;
int ny;
// Size of the grid cells
double dx;
double dy;
// The temperature values in the 2D grid
std::vector<double> data;
};
type :: field
integer :: nx ! ldimension of the field
integer :: ny
real(dp) :: dx
real(dp) :: dy
real(dp), dimension(:,:), allocatable :: data
end type field
Building the code
If there’s terminal output to discuss, show something like:
nvc++ -g -O3 -fopenmp -Wall -I../common -c main.cpp -o main.o
nvc++ -g -O3 -fopenmp -Wall -I../common -c core.cpp -o core.o
nvc++ -g -O3 -fopenmp -Wall -I../common -c setup.cpp -o setup.o
nvc++ -g -O3 -fopenmp -Wall -I../common -c utilities.cpp -o utilities.o
nvc++ -g -O3 -fopenmp -Wall -I../common -c io.cpp -o io.o
nvc++ -g -O3 -fopenmp -Wall -I../common main.o core.o setup.o utilities.o io.o ../common/pngwriter.o -o heat_serial -lpng
Running the code
To show a sample command line, use this approach
./heat_serial 800 800 1000
Keypoints
TODO summarize the learning outcome
TODO