Module2
Module2
PROFILING
Dr. Volker Weinberg | LRZ
MODULE OVERVIEW
Topics to be covered
The -fast flag instructs the compiler to optimize the code to the best of its abilities
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
Nsight Systems -
Analyze application
algorithm system-wide
Nsight Compute -
Debug/optimize CUDA
kernel
Nsight Graphics -
Debug/optimize graphics
workloads
This material is released by NVIDIA Corporation under the Creative Commons Attribution 4.0 International (CC BY 4.0)
Thread/core
migration
Processes
and
threads Thread state
CUDA and
OpenGL API trace
cuDNN and
cuBLAS trace
Multi-GPU
This material is released by NVIDIA Corporation under the Creative Commons Attribution 4.0 International (CC BY 4.0)
PROFILING SEQUENTIAL CODE
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,
check for correctness and then
analyze it again.
Optimize your code to improve
observed speed-up from
parallelization.
Optimize Parallelize
PROFILING SEQUENTIAL CODE
Step 1: Run Your Code Terminal Window
$ pgcc –fast jacobi.c laplace2d.c
Record the time it takes for your $ ./a.out
sequential program to run. 0, 0.250000
100, 0.002397
200, 0.001204
300, 0.000804
Note the final results to verify
400, 0.000603
correctness later.
500, 0.000483
600, 0.000403
700, 0.000345
Always run a problem that is 800, 0.000302
representative of your real jobs. 900, 0.000269
total: 39.432648 s
PROFILING SEQUENTIAL CODE
Step 2: Profile Your Code Lab Code: Laplace Heat Transfer
Obtain detailed information about how
the code ran. Total Runtime: 39.43 seconds
To profile a serial application with NVIDIA Nsight Systems, we use NVIDIA Tools Extension
(NVTX) API functions in addition to collecting backtraces while sampling.
PROFILING SEQUENTIAL CODE
NVIDIA Tools Extension API (NVTX) library
What is it?
A C-based Application Programming Interface (API) for annotating events
Can be easily integrated to the application
Can be used with NVIDIA Nsight Systems
Why?
Allows manual instrumentation of the application
Allows additional information for profiling (e.g: tracing of CPU events and time ranges)
How?
Import the header only C library nvToolsExt.h
Wrap the code region or a specific function with nvtxRangePush() and nvtxRangPop()
#include <string.h> -t Selects the APIs to be traced (nvtx in this example)
#include <stdio.h>
#include <stdlib.h>
#include <omp.h> --status if true, generates summary of statistics after the collection
#include "laplace2d.h"
#include <nvtx3/nvToolsExt.h> -b Selects the backtrace method to use while sampling. The option dwarf
int main(int argc, char** argv) uses DWARF's CFI (Call Frame Information).
{
const int n = 4096; --force-overwrite if true, overwrites the existing results
const int m = 4096;
const int iter_max = 1000;
-o sets the output (qdrep) filename
const double tol = 1.0e-6;
double error = 1.0;
nvtxRangePushA("init");
initialize(A, Anew, m, n);
nvtxRangePop();
double st = omp_get_wtime();
int iter = 0;
nvtxRangePushA("while");
while ( error > tol && iter < iter_max )
{
nvtxRangePushA("calc");
error = calcNext(A, Anew, m, n);
nvtxRangePop();
nvtxRangePushA("swap");
swap(A, Anew, m, n);
nvtxRangePop();
Timeline view
(charts and the hierarchy on the top pane)
Analysis Summary
Timeline view
(event view and function table on the bottom pane)
PROFILING SEQUENTIAL
CODE Enlarge view!
Using Nsight Systems
right click in
selected region
and Zoom into
selection!
PROFILING SEQUENTIAL
CODE
Using Nsight Systems
PROFILING SEQUENTIAL
CODE
Viewing captured NVTX events and time
ranges via Nsight Systems GUI
From the Timeline view, right click on the “NVTX” from
the top pane and choose “Show in Events View”.
From the bottom pane, you can now see name of the
events captured with the duration.
PLEASE START LAB NOW!
CSC_OPENACC_AMBASSADOR_MAY22
TRAINING SETUP
LRZ_OPENACC_AMBASSADOR_MY22
TRAINING SETUP
TRAINING SETUP
TRAINING SETUP
TRAINING SETUP
TRAINING SETUP
TRAINING SETUP
TRAINING SETUP
To be able to visualise Nsight System profiler output during the course, please install
Nsight System latest version on your local system before the course. The software
can be downloaded from https://developer.nvidia.com/nsight-systems.
PROFILING MULTICORE CODE
PROFILING MULTICORE CODE
What is multicore?
Parallel
This material is released by NVIDIA Corporation under the Creative Commons Attribution 4.0 International (CC BY 4.0)
#include <math.h>
#include <stdlib.h>
Parallel
Sequential
PROFILING PARALLEL
CODE
Viewing timeline via Nsight Systems
We will simulate the distribution of 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
heat until a minimum change value
is achieved, or until we exceed a
maximum number of iterations.
LAPLACE HEAT TRANSFER
Introduction to lab code - technical
We will take the average of the 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
neighboring cells, and record it in
Anew.
0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
The swap function will copy the
contents of Anew to A
LAPLACE HEAT TRANSFER
Introduction to lab code
A Anew
Build and run the example code using the NVIDIA’s HPC compiler
Use Nsight Systems to understand where the program spends its time
THANK YOU