CUDA Program Analysis

Nvidia Visio profiler

usage

nvprof [options] [application] [application-arguments]

usage mode

  • summary mode
nvprof matrixMul
  • track gpu trace
nvprof --print-gpu-trace matrixMul
  • track API trace

    nvprof --print-api-trace matrixMul

    Note: API trace can be turned off, if not needed, by using –profile-api-trace none. This reduces some of the profiling overhead, especially when the kernels are short.

  • Event/metric Summary Mode

nvprof --events warps_launched,local_load --metrics ipc matrixMul
  • some userul events and metrics
  • events

    • gld_inst_32bit
    • gst_*
    • global_load
    • global_store
    • local_*
    • warp_launched
    • active_cycles
    • *_warps/ctas
    • tex0_cache_sector_queries
    • tex1_
  • metrics

    • ipc
    • gld_transactions_per_request
    • gst_*
    • gld_efficiency
    • sm_efficiency
    • l2_read_transactions
    • l2_tex_transactions
    • l2_utilization
  • example

nvprof --events warps_launched,local_load --metrics ipc matrixMul
  • Event/metric Trace Mode
nvprof --aggregate-mode off --events local_load --print-gpu-trace matrixMul

other important options

  • –dependency-analysis
  • Timeline
nvprof --export-profile timeline.prof <app> <app args>
  • Metrics And Events
    The second use case is to collect events or metrics for all kernels in an application for
    which you have already collected a timeline. Collecting events or metrics for all kernels will significantly change the overall
    performance characteristics of the application because all kernel executions will be serialized on the GPU.
    Even though overall application performance is changed, the event or metric values
    for individual kernels will be correct and so you can merge the collected event and metric values
    onto a previously collected timeline to get an accurate picture of the applications behavior.
  nvprof --metrics achieved_occupancy,executed_ipc -o metrics.prof <app> <app args>
  • Analysis For Individual Kernel
nvprof --kernels <kernel specifier> --analysis-metrics -o analysis.prof <app> <app args>

metric reference

http://docs.nvidia.com/cuda/profiler-users-guide/index.html#metrics-reference

simple compile app

.cu -> .ptx -> .cubin ->exe

you can use “nvcc -keep” to preserve the middle compiled files
–ptxas-option=-v to see verbose compilation output

​ - number of registers used
- shared memory bytes
- local memory in bytes

cuobjdump

​ a disassemble tool

​ static inst

cuda timing functions

eg.

cudaEvent_t start,stop;

float elapsed ;

cudaEventCreate(&start);

cudaEventCreate(& stop);

cudaEventRecord(start,0);

fool_kernel<<<grid,block>>>();

cudaEventRecord(stop,0);

cudaEventSynchronize(stop);

cudaEventElapsedTime(&elapsed,start,stop);//返回ms,精确在0.5ms,不是很精确

printf("elapsed time %f (seconds) \n",elapsed/1000);

### CUDA 安装过程中缺少 SA 的解决方案 在安装 CUDA 工具包的过程中,如果遇到缺少 `SA`(Static Analyzer)的情况,通常是因为某些组件未被正确安装或者路径设置不完整。以下是针对该问题的具体分析和解决方法: #### 1. **确认 CUDA 版本兼容性** 确保所使用的 CUDA 版本与操作系统以及 GPU 驱动程序完全匹配。不同版本的 CUDA 对应不同的支持范围[^2]。例如,在 Windows 平台上,较新的 CUDA 版本可能需要更高版本的操作系统或特定驱动。 #### 2. **重新运行 CUDA 安装器并选择完整的选项** 有时,默认安装模式不会包含所有的工具链,特别是静态分析器 (`SA`) 组件。可以通过以下方式解决问题: - 删除现有的 CUDA 安装。 - 使用管理员权限再次启动 CUDA 安装向导。 - 在自定义安装界面中勾选所有可用的功能模块,尤其是涉及开发工具的部分,如 Static Analysis Tools 或者其他扩展功能[^1]。 #### 3. **手动复制必要文件至目标目录** 当通过标准流程无法获取所需资源时,可尝试从官方提供的补丁包或其他独立分发渠道下载缺失项,并将其放置于适当位置。比如文中提到的方法——将 `\CUDAVisualStudioIntegration\extras\visual_studio_integration\CudaProjectVsWizards` 文件夹迁移至 Visual Studio 的 Extensions 路径下完成集成操作。 #### 4. **验证环境变量配置准确性** 检查系统的 PATH 变量是否已经包含了新安装好的 CUDA binaries 和 libraries 地址;如果没有,则需手工添加进去。典型形式如下所示: ```bash set PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\vX.Y\bin;%PATH% ``` #### 5. **利用 Nsight Debugging 插件增强体验** 为了更好地调试基于 CUDA 构建的应用程序,建议额外部署 NVIDIA 提供的相关辅助软件产品,像 Nsight Visual Studio Edition 就是一个不错的选择。它不仅能够提升工作效率还能帮助识别潜在性能瓶颈等问题所在之处。 #### 示例代码片段展示如何加载 PyTorch 中分布式训练所需的设备可见性设定: ```python import os os.environ['CUDA_VISIBLE_DEVICES'] = '0,1' ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值