Skip to main content
 首页 » 编程设计

python之如何在 Linux 中分析 PyCuda 代码

2025年05月04日10linjiqin

我有一个简单的(经过测试的)pycuda 应用程序,我正在尝试对其进行概要分析。我试过 NVidia 的 Compute Visual Profiler,它运行程序 11 次,然后发出此错误:

NV_Warning: Ignoring the invalid profiler config option: fb0_subp0_read_sectors 
Error : Profiler data file '/home/jguy/proj/gpu/tdbp/pyArch/temp_compute_profiler_0_0.csv' does not contain profiler output.This can happen when: 
a) Profiling is disabled during the entire run of the application. 
b) The application does not invoke any kernel launches or memory transfers. 
c) The application does not release resources (contexts, events, etc.). The program needs to be modified to properly free up all resources before termination. 

我还尝试运行“CUDA_PROFILE python scriptname.py arg1”。它创建了一个包含以下内容的文件:

NV_Warning: Ignoring the invalid profiler config option: instructions 
# CUDA_PROFILE_LOG_VERSION 2.0 
# CUDA_DEVICE 0 GeForce GTX 560 Ti 
# CUDA_PROFILE_CSV 1 
# TIMESTAMPFACTOR fffff7003e38fec8 
gpustarttimestamp,method,gputime,cputime,occupancy 

如果有用,我还设置了这些环境变量:

CUDA_PROFILE_CONFIG=temp_cuda_profiler.conf 
CUDA_PROFILE_CSV=1 
CUDA_PROFILE_LOG=profile.csv 
CUDA_PROFILE=1 

和 temp_cuda_profiler.conf 包含

gpustarttimestamp 
instructions 

谷歌搜索了一个小时左右。没有运气。感谢您提供的任何见解!

请您参考如下方法:

当使用 import pycuda.autoinit 时,在程序末尾有 pycuda.autoinit.context.detach() 很重要。这解决了问题。