Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Applications
Compiler Programming
Libraries
Directives Languages
programming model {
<serial code>
#pragma acc kernels
designed for performance {
<parallel code>
}
and portability. }
OpenACC Directives
Manage #pragma acc data copyin(a,b) copyout(c)
Data {
Incremental
Movement ...
#pragma acc parallel
Single source
{
Initiate #pragma acc loop gang vector Interoperable
Parallel for (i = 0; i < n; ++i) {
Execution c[i] = a[i] + b[i]; Performance portable
...
Optimize
} CPU, GPU, Manycore
}
Loop
...
Mappings
}
OPENACC
▪ OpenACC is meant to
be easy to use, and
easy to learn
int main(){ The programmer will
give hints to the ▪ Programmer remains
<sequential code> compiler. in familiar C, C++, or
Compiler
Fortran
#pragma acc kernels Hint ▪ No reason to learn
{
<parallel code> The compiler low-level details of the
} parallelizes the code. hardware.
}
OPENACC
132
104
67
32
Project Contributors
GAUSSIAN 16
Mike Frisch, Ph.D.
President and
CEO
Gaussian, Inc.
Using OpenACC allowed us to continue
Roberto Gomperts development of ourBrent
Michael Frisch fundamental
Leback Gio
NVIDIA Gaussian NVIDIA/PGI
algorithms and software capabilities
Gaussian, Inc. simultaneously with the GPU-related
340 Quinnipiac St. Bldg. 40
Wallingford, CT 06492 USA work.
GaussianInis athe end,
registered we could
trademark of Gaussian,useInc.the
All other trademarks and
the properties of their respective holders. Specif cations subject to change witho
custserv@gaussian.com same code
Copyright © 2017,base
Gaussian,forInc.SMP, cluster/
All rights reserved.
network and GPU parallelism. PGI's
compilers were essential to the success
of our efforts.
VASP
Prof. Georg Kresse
Computational Materials Physics
University of Vienna
▪ A pragma in C/C++ gives instructions to the compiler on how to compile the code.
Compilers that do not understand a particular pragma can freely ignore it.
▪ A directive in Fortran is a specially formatted comment that likewise instructions the
compiler in it compilation of the code and can be freely ignored.
▪ “acc” informs the compiler that what will come is an OpenACC directive
▪ Directives are commands in OpenACC for altering our code.
▪ Clauses are specifiers or additions to directives.
EXAMPLE CODE
LAPLACE HEAT TRANSFER
Introduction to lab code - visual Very Hot Room Temp
A(i-1,j) A(i+1,j)
A(i,j)
𝐴𝑘 (𝑖 − 1, 𝑗) + 𝐴𝑘 𝑖 + 1, 𝑗 + 𝐴𝑘 𝑖, 𝑗 − 1 + 𝐴𝑘 𝑖, 𝑗 + 1
𝐴𝑘+1 𝑖, 𝑗 =
A(i,j-1) 4
JACOBI ITERATION: C CODE
while ( err > tol && iter < iter_max ) {
err=0.0;
Iterate until converged
iter++;
}
25
PROFILE-DRIVEN DEVELOPMENT
OPENACC DEVELOPMENT CYCLE
▪ Analyze your code to determine
most likely places needing Analyze
parallelization or optimization.
▪ Parallelize your code by starting
with the most time consuming parts
and check for correctness.
▪ Optimize your code to improve
observed speed-up from
parallelization.
Optimize Parallelize
PROFILING SEQUENTIAL CODE
Profile Your Code Lab Code: Laplace Heat Transfer
Obtain detailed information about how
the code ran. Total Runtime: 39.43 seconds
loop
loop
#pragma acc parallel
{ gang gang
loop
loop
loop
for(int i = 0; i < N; i++)
{ gang gang
// Do Something
}
loop
loop
This loop will be gang gang
}
executed redundantly
on each gang
OPENACC PARALLEL DIRECTIVE
Expressing parallelism
+ Addition/Summation reduction(+:sum)
* Multiplication/Product reduction(*:product)
max Maximum value reduction(max:maximum)
min Minimum value reduction(min:minimum)
& Bitwise and reduction(&:val)
| Bitwise or reduction(|:val)
&& Logical and reduction(&&:val)
|| Logical or reduction(||:val)
BUILD AND RUN THE CODE
PGI COMPILER BASICS
pgcc, pgc++ and pgfortran
▪ The -Minfo flag will instruct the compiler to print feedback about the compiled code
▪ -Minfo=accel will give us information about what parts of the code were accelerated
via OpenACC
▪ -Minfo=opt will give information about all code optimizations
▪ -Minfo=all will give all code feedback, whether positive or negative
▪ The -ta flag enables building OpenACC code for a “Target Accelerator” (TA)
▪ -ta=multicore – Build the code to run across threads on a multicore CPU
▪ -ta=tesla:managed – Build the code for an NVIDIA (Tesla) GPU and manage the
data movement for me (more next week)
48
OPENACC SPEED-UP
Speed-up
3.50X
3.05X
3.00X
2.50X
Speed-Up
2.00X
1.50X
1.00X
1.00X
0.50X
0.00X
SERIAL MULTICORE
50
OPENACC SPEED-UP
Speed-up
40.00X
37.14X
35.00X
30.00X
25.00X
Speed-Up
20.00X
15.00X
10.00X
5.00X 3.05X
1.00X
0.00X
SERIAL MULTICORE NVIDIA TESLA V100
Next Week:
▪ Managing your data with OpenACC
OPENACC RESOURCES
Guides ● Talks ● Tutorials ● Videos ● Books ● Spec ● Code Samples ● Teaching Materials ● Events ● Success Stories ● Courses ● Slack ● Stack Overflow
FREE
Compilers
Compilers and Tools Events
https://www.openacc.org/tools https://www.openacc.org/events