如何使用 Visual Profiler 分析 PyCuda 代码?
当我创建一个新会话并告诉 Visual Profiler 启动我的 python/pycuda 脚本时,我收到以下错误消息: Execution run #1 of program '' failed, exit code: 255
这些是我的首选项:
- 启动:
python "/pathtopycudafile/mysuperkernel.py"
- 工作目录:
"/pathtopycudafile/mysuperkernel.py"
- 参数:
[empty]
我在 Ubuntu 10.10 下使用 CUDA 4.0。 64位。分析已编译的示例有效。
ps 我知道这样的问题 如何在 Linux 中分析 PyCuda 代码?,但似乎是一个不相关的问题。
最小示例
pycudaexample.py:
import pycuda.autoinit
import pycuda.driver as drv
import numpy
from pycuda.compiler import SourceModule
mod = SourceModule("""
__global__ void multiply_them(float *dest, float *a, float *b)
{
const int i = threadIdx.x;
dest[i] = a[i] * b[i];
}
""")
multiply_them = mod.get_function("multiply_them")
a = numpy.random.randn(400).astype(numpy.float32)
b = numpy.random.randn(400).astype(numpy.float32)
dest = numpy.zeros_like(a)
multiply_them(
drv.Out(dest), drv.In(a), drv.In(b),
block=(400,1,1), grid=(1,1))
pycuda.autoinit.context.detach()
示例设置
错误消息
When I create a new session and tell the Visual Profiler to launch my python/pycuda scripts I get following error message: Execution run #1 of program '' failed, exit code: 255
These are my preferences:
- Launch:
python "/pathtopycudafile/mysuperkernel.py"
- Working Directory:
"/pathtopycudafile/mysuperkernel.py"
- Arguments:
[empty]
I use CUDA 4.0 under Ubuntu 10.10. 64Bit. Profiling compiled examples works.
p.s. I am aware of SO question How to profile PyCuda code in Linux?, but seems to be an unrelated problem.
Minimal example
pycudaexample.py:
import pycuda.autoinit
import pycuda.driver as drv
import numpy
from pycuda.compiler import SourceModule
mod = SourceModule("""
__global__ void multiply_them(float *dest, float *a, float *b)
{
const int i = threadIdx.x;
dest[i] = a[i] * b[i];
}
""")
multiply_them = mod.get_function("multiply_them")
a = numpy.random.randn(400).astype(numpy.float32)
b = numpy.random.randn(400).astype(numpy.float32)
dest = numpy.zeros_like(a)
multiply_them(
drv.Out(dest), drv.In(a), drv.In(b),
block=(400,1,1), grid=(1,1))
pycuda.autoinit.context.detach()
Example settings
Error message
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您为计算分析器指定可执行文件的方式有问题。如果我在发布的代码顶部添加一个 hash bang 行:
然后授予 python 文件可执行权限,则计算分析器会毫无怨言地运行代码,我会得到以下结果:
There is something wrong with the way you are specifying the executable to the compute profiler. If I put a hash bang line at the top of your posted code:
and then give the python file executable permissions, the compute profiler runs the code without complaint and I get this:
您可以使用两种方法。
启动脚本解释器
启动可执行脚本
请参阅@talonmies 答案
There are two methods that you can use.
Launch the Script Interpreter
Launch a Executable Script
See @talonmies answer