Difference between revisions of "GPU Tutorial/Open MP"

From HPC Wiki
GPU Tutorial/Open MP
Jump to navigation Jump to search
m
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[Category:Tutorials|GPU Computing (Open Mp)]]<nowiki />
+
[[Category:Tutorials|GPU Computing (OpenMP)]]<nowiki />
{{DISPLAYTITLE:GPU Computing (Open MP)}}<nowiki />
+
{{DISPLAYTITLE:GPU Computing (OpenMP)}}<nowiki />
 
{{Syllabus Introduction to GPU Computing}}<nowiki />
 
{{Syllabus Introduction to GPU Computing}}<nowiki />
 
__TOC__
 
__TOC__
  
 +
This video discusses the SAXPY via OpenMP GPU offloading.
 
OpenMP 4.0 and later enables developers to program GPUs in C/C++ and Fortran by means of OpenMP directives. In this tutorial we present the basic OpenMP syntax for GPU offloading and give a step-by-step guide for implementing SAXPY with it.
 
OpenMP 4.0 and later enables developers to program GPUs in C/C++ and Fortran by means of OpenMP directives. In this tutorial we present the basic OpenMP syntax for GPU offloading and give a step-by-step guide for implementing SAXPY with it.
  
 
=== Video === <!--T:5-->
 
=== Video === <!--T:5-->
 +
 +
<youtube width="600" height="340" right>EPflqxk4rfk</youtube>
 +
 +
([[Media:GPU_tutorial_saxpy_openmp.pdf |Slides as pdf]])
  
 
=== Quiz === <!--T:5-->   
 
=== Quiz === <!--T:5-->   
Line 14: Line 19:
 
{
 
{
 
|type="()"}
 
|type="()"}
- `#pragma omp target gpu`
+
- <code>#pragma omp target gpu</code>
|| `#pragma omp target gpu` is a syntax error in OpenMP.
+
|| <code>#pragma omp target gpu</code> is a syntax error in OpenMP.
- `#pragma omp target acc`
+
- <code>#pragma omp target acc</code>
|| + `#pragma omp target acc` is a syntax error in OpenMP.
+
|| <code>#pragma omp target acc</code> is a syntax error in OpenMP.
+ `#pragma omp target`
+
+ <code>#pragma omp target</code>
|| Correct: `#pragma omp target` defines a target region, which is a block of computation that operates on GPU.
+
|| Correct: <code>#pragma omp target</code> defines a target region, which is a block of computation that operates on GPU.
 
</quiz>
 
</quiz>
 
{{hidden end}}
 
{{hidden end}}
Line 46: Line 51:
 
{
 
{
 
|type="()"}
 
|type="()"}
- `#pragma omp init teams`
+
- <code>#pragma omp init teams</code>
|| `#pragma omp init teams` is a syntax error in OpenMP.
+
|| <code>#pragma omp init teams</code> is a syntax error in OpenMP.
+ `#pragma omp teams`
+
+ <code>#pragma omp teams</code>
|| Correct: `#pragma omp teams` creates a league of teams for execution on GPU.
+
|| Correct: <code>#pragma omp teams</code> creates a league of teams for execution on GPU.
- `#pragma omp gpu teams`
+
- <code>#pragma omp gpu teams</code>
|| `#pragma omp init teams` is a syntax error in OpenMP.
+
|| <code>#pragma omp init teams</code> is a syntax error in OpenMP.
 
</quiz>
 
</quiz>
 
{{hidden end}}
 
{{hidden end}}
Line 61: Line 66:
 
{
 
{
 
|type="()"}
 
|type="()"}
- `#pragma omp distribute for`
+
- <code>#pragma omp distribute for</code>
|| `#pragma omp distribute for` is a syntax error in OpenMP.
+
|| <code>#pragma omp distribute for</code> is a syntax error in OpenMP.
- `#pragma omp parallel for`
+
- <code>#pragma omp parallel for</code>
|| `#pragma omp parallel for` only parallelizes the for-loop iterations amongst the threads in one team.
+
|| <code>#pragma omp parallel for</code> only parallelizes the for-loop iterations amongst the threads in one team.
+ `#pragma omp distribute parallel for`
+
+ <code>#pragma omp distribute parallel for</code>
|| Correct: `#pragma omp distribute parallel for` distributes the for-loop iterations across two levels of parallelism, which are the league of teams and the threads in each team.
+
|| Correct: <code>#pragma omp distribute parallel for</code> distributes the for-loop iterations across two levels of parallelism, which are the league of teams and the threads in each team.
 
</quiz>
 
</quiz>
 
{{hidden end}}
 
{{hidden end}}

Latest revision as of 16:22, 21 January 2022

Tutorial
Title: Introduction to GPU Computing
Provider: HPC.NRW

Contact: tutorials@hpc.nrw
Type: Multi-part video
Topic Area: GPU computing
License: CC-BY-SA
Syllabus

1. Introduction
2. Several Ways to SAXPY: CUDA C/C++
3. Several Ways to SAXPY: OpenMP
4. Several Ways to SAXPY: Julia
5. Several Ways to SAXPY: NUMBA

This video discusses the SAXPY via OpenMP GPU offloading. OpenMP 4.0 and later enables developers to program GPUs in C/C++ and Fortran by means of OpenMP directives. In this tutorial we present the basic OpenMP syntax for GPU offloading and give a step-by-step guide for implementing SAXPY with it.

Video

(Slides as pdf)

Quiz

1. Which one of the following OpenMP directives can create a target region on GPU?

#pragma omp target gpu
#pragma omp target acc
#pragma omp target


2. The OpenMP `map(to:...)` clause maps variables:

from host to device data environment before execution
from host to device data environment after execution
from device to host data environment before execution
from device to host data environment after execution


3. Which one of the following OpenMP directives can initialize a league of teams for execution on GPU?

#pragma omp init teams
#pragma omp teams
#pragma omp gpu teams


4. Which one of the following OpenMP directives can distribute iterations of for-loop across GPU threads in the teams?

#pragma omp distribute for
#pragma omp parallel for
#pragma omp distribute parallel for