This Bash script is designed to automate the generation of wrapper libraries for various CUDA-related libraries, which are commonly used in GPU-accelerated computing. These wrappers seem to integrate with Score-P, a performance analysis and tracing framework. The script processes libraries like libcudart.so
, libcublas.so
, and others to facilitate performance instrumentation or runtime monitoring of CUDA applications. Here's a detailed breakdown:
该 Bash 脚本旨在自动生成各种 CUDA 相关库的包装器库,这些库通常用于 GPU 加速计算。这些包装器似乎与Score-P(一个性能分析和跟踪框架)集成。该脚本处理libcudart.so 、 libcublas.so等库,以促进 CUDA 应用程序的性能检测或运行时监控。以下是详细的细分:
-
Wrapper Libraries Creation:
- Uses the
scorep-libwrap-init
tool to generate Score-P wrapper libraries for CUDA libraries. - Enables capturing calls to CUDA libraries for debugging, profiling, or performance analysis.
- Uses the
-
Custom Adjustments:
- Edits wrapper source files and build configurations to include specific headers and modify compilation flags (e.g., adding
-fPIC
for position-independent code).
- Edits wrapper source files and build configurations to include specific headers and modify compilation flags (e.g., adding
-
Instruments Specific CUDA Libraries:
- Covers libraries such as:
libcudart.so
: Runtime API for CUDA.libcublas.so
: Basic Linear Algebra Subprograms (BLAS).libcufft.so
: Fast Fourier Transform (FFT).libcurand.so
: Random number generation.libcudnn.so
: Deep neural network support.libcusparse.so
: Sparse matrix operations.libnvToolsExt.so
: Profiling and debugging tools.libnccl.so
: Multi-GPU communication.
- Covers libraries such as:
-
Directory Setup:
- Creates a
wrapper
directory for holding generated wrappers.
- Creates a
-
Environment Variables:
- Defines paths to CUDA Toolkit, cuDNN, and NCCL libraries:
CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-10.0/targets/x86_64-linux CUDNN_ROOT_DIR=/work/opt/cuda/cudnn-10.0-linux-x64-v7.6.5.32 NCCL_ROOT_DIR=/work/opt/cuda/nccl_2.5.6-1+cuda10.0_x86_64
- Defines paths to CUDA Toolkit, cuDNN, and NCCL libraries:
For each CUDA library:
-
Executes
scorep-libwrap-init
:scorep-libwrap-init --name ${LIBN} -x c++ \ --cppflags "-I${CUDA_TOOLKIT_ROOT_DIR}/include/" \ --ldflags "-L${CUDA_TOOLKIT_ROOT_DIR}/lib/" \ --libs "-l${LIBN}" --update wrapper/wrap_${LIBN}
- Generates initial wrapper sources and build files for the target library.
-
Customizes source code (
libwrap.h
,.filter
files) and the Makefile:- Includes appropriate CUDA headers like
cublas_v2.h
forcublas
,cudnn.h
forcudnn
, etc. - Edits filtering rules to exclude certain symbols (e.g.,
cuda*
,curandGenerateBinomial*
).
- Includes appropriate CUDA headers like
-
Builds the wrapper:
make libscorep_libwrap_${LIBN}_runtime.la
Some libraries require additional modifications:
- For
libcudart.so
, it adds a customset_launch_func
to handle kernel launches. - For
libcufft.so
, includescufft.h
andcufftXt.h
.
The script generates a series of dynamic libraries (.la
files) in the wrapper
directory, such as:
libscorep_libwrap_cudart_runtime.la
libscorep_libwrap_cublas_runtime.la
libscorep_libwrap_cufft_runtime.la
... and so on.
These libraries allow Score-P to monitor and trace GPU-related operations in programs that use these CUDA libraries.
-
Performance Profiling:
- Developers can profile CUDA-based applications to analyze bottlenecks or resource usage.
-
Debugging and Instrumentation:
- The generated wrappers enable fine-grained debugging of CUDA calls.
-
Integration with HPC Environments:
- Supports performance analysis for GPU-heavy workloads in high-performance computing (HPC) clusters.
-
Documentation:
- Add comments to clarify what specific modifications in each
sed
command are meant to achieve.
- Add comments to clarify what specific modifications in each
-
Portability:
- Replace hardcoded paths (e.g.,
/usr/local/cuda-10.0/
) with more configurable options or environment checks.
- Replace hardcoded paths (e.g.,
-
Error Handling:
- Include error checks after key commands (
mkdir
,scorep-libwrap-init
,make
).
- Include error checks after key commands (
This script is highly specialized and targets developers working with GPU performance optimization or debugging using CUDA and Score-P.
这段 Bash 脚本旨在自动生成针对各种 CUDA 相关库的封装库(wrapper libraries),这些库通常用于 GPU 加速计算。封装库似乎与 Score-P 集成,这是一种性能分析和追踪框架。脚本处理诸如 libcudart.so
、libcublas.so
等库,以便为 CUDA 应用程序提供性能检测或运行时监控功能。以下是详细的分解:
-
创建封装库:
- 使用
scorep-libwrap-init
工具为 CUDA 库生成 Score-P 封装库。 - 使其能够捕获对 CUDA 库的调用,用于调试、性能分析或运行时监控。
- 使用
-
自定义调整:
- 编辑封装源码文件和构建配置,例如包含特定头文件、修改编译标志(如添加
-fPIC
支持位置无关代码)。
- 编辑封装源码文件和构建配置,例如包含特定头文件、修改编译标志(如添加
-
处理特定的 CUDA 库:
- 涵盖的库包括:
libcudart.so
:CUDA 的运行时 API。libcublas.so
:基本线性代数子程序(BLAS)。libcufft.so
:快速傅里叶变换(FFT)。libcurand.so
:随机数生成。libcudnn.so
:深度神经网络支持。libcusparse.so
:稀疏矩阵运算。libnvToolsExt.so
:性能分析和调试工具。libnccl.so
:多 GPU 通信。
- 涵盖的库包括:
-
目录创建:
- 创建
wrapper
目录,用于存放生成的封装库。
- 创建
-
环境变量定义:
- 定义 CUDA Toolkit、cuDNN 和 NCCL 库的路径:
CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-10.0/targets/x86_64-linux CUDNN_ROOT_DIR=/work/opt/cuda/cudnn-10.0-linux-x64-v7.6.5.32 NCCL_ROOT_DIR=/work/opt/cuda/nccl_2.5.6-1+cuda10.0_x86_64
- 定义 CUDA Toolkit、cuDNN 和 NCCL 库的路径:
对于每个 CUDA 库:
-
执行
scorep-libwrap-init
:scorep-libwrap-init --name ${LIBN} -x c++ \ --cppflags "-I${CUDA_TOOLKIT_ROOT_DIR}/include/" \ --ldflags "-L${CUDA_TOOLKIT_ROOT_DIR}/lib/" \ --libs "-l${LIBN}" --update wrapper/wrap_${LIBN}
- 为目标库生成初始的封装源码和构建文件。
-
自定义源码(如
libwrap.h
和.filter
文件)以及 Makefile:- 包含适当的 CUDA 头文件,例如针对
cublas
的cublas_v2.h
,针对cudnn
的cudnn.h
等。 - 编辑过滤规则以排除某些符号(例如
cuda*
、curandGenerateBinomial*
)。
- 包含适当的 CUDA 头文件,例如针对
-
编译封装库:
make libscorep_libwrap_${LIBN}_runtime.la
某些库需要额外的修改:
- 对于
libcudart.so
,添加了自定义的set_launch_func
以处理内核启动。 - 对于
libcufft.so
,包含了cufft.h
和cufftXt.h
。
脚本在 wrapper
目录中生成一系列动态库(.la
文件),例如:
libscorep_libwrap_cudart_runtime.la
libscorep_libwrap_cublas_runtime.la
libscorep_libwrap_cufft_runtime.la
... 等。
这些库允许 Score-P 监控和跟踪程序中与 GPU 相关的操作。
-
性能分析:
- 开发者可以分析 CUDA 应用程序的性能瓶颈或资源使用情况。
-
调试与监控:
- 生成的封装库支持对 CUDA 调用的细粒度调试。
-
与高性能计算环境集成:
- 支持在高性能计算(HPC)集群中分析 GPU 密集型工作负载的性能。
-
文档:
- 添加注释,说明每个
sed
命令的具体修改目的。
- 添加注释,说明每个
-
移植性:
- 将硬编码路径(如
/usr/local/cuda-10.0/
)替换为可配置选项或环境检查。
- 将硬编码路径(如
-
错误处理:
- 在关键命令(如
mkdir
、scorep-libwrap-init
、make
)后添加错误检查。
- 在关键命令(如
此脚本高度专业化,适用于使用 CUDA 和 Score-P 进行 GPU 性能优化或调试的开发者。