Sanju HPC 9,10
Sanju HPC 9,10
PRACTICAL-09
AIM:
Analise the code using Nvidia-Profilers.
WHAT IS A PROFILER:
A profiler is a performance analysis tool that helps developers understand how their program
executes. It provides insights into execution time, memory usage, thread activity, and other
critical metrics. Profilers are essential for optimizing performance in high-performance
computing applications.
INTRODUCTION TO NVPROF:
nvprof is a command-line profiler provided by NVIDIA for CUDA applications. It allows
developers to collect and analyze performance data for programs running on NVIDIA GPUs.
nvprof enables efficient debugging and optimization of CUDA code by providing details on
kernel execution, memory transfers, and utilization metrics.
FEATURES OF NVPROF:
• Provides detailed kernel execution timing and memory usage statistics.
• Allows analysis of memory transfer between host and device.
• Supports collecting metrics such as occupancy, compute efficiency, and memory
throughput.
• Compatible with CUDA-enabled devices and applications.
• Generates reports for further analysis using NVIDIA Visual Profiler (Nsight Systems).
32 | P a g e
FACULTY OF ENGINEERING & TECHNOLOGY
HIGH PERFORMANCE COMPUTING (303105356)
BTECH 3RD YEAR 6TH SEMESTER
ENROLLMENT NUMBER: 2203031240285
Compilation:
!nvcc -o x p1.cu
Execution:
!./x
33 | P a g e
FACULTY OF ENGINEERING & TECHNOLOGY
HIGH PERFORMANCE COMPUTING (303105356)
BTECH 3RD YEAR 6TH SEMESTER
ENROLLMENT NUMBER: 2203031240285
CONCLUSION:
Using nvprof, the performance and behavior of CUDA programs can be analyzed
effectively. Profiling helps identify bottlenecks and optimize execution time, memory
transfers, and resource utilization, leading to more efficient CUDA applications.
34 | P a g e
FACULTY OF ENGINEERING & TECHNOLOGY
HIGH PERFORMANCE COMPUTING (303105356)
BTECH 3RD YEAR 6TH SEMESTER
ENROLLMENT NUMBER: 2203031240285
PRACTICAL-10
WHAT IS PTHREAD:
Pthreads, or POSIX threads, is a standardized C library for multithreading. It allows parallel
programming by creating multiple threads, enabling efficient execution of concurrent processes
within a program.
%%writefile pthread.c
#include <pthread.h>
#include <stdio.h>
#define NUM_THREADS 5
35 | P a g e
FACULTY OF ENGINEERING & TECHNOLOGY
HIGH PERFORMANCE COMPUTING (303105356)
BTECH 3RD YEAR 6TH SEMESTER
ENROLLMENT NUMBER: 2203031240285
int rc;
int t;
for(t = 0; t < NUM_THREADS; t++) {
printf("In main: creating thread %d\n", t);
rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t);
if (rc) {
printf("ERROR; return code from pthread_create() is %d\n", rc);
}
}
pthread_exit(NULL);
}
!./pthread
36 | P a g e