无法编译简单的PyCuda OSX应用程序

0 投票
1 回答
706 浏览
提问于 2025-04-18 09:22

我按照这里的PyCuda安装说明进行了操作:http://wiki.tiker.net/PyCuda/Installation/Mac

我正在尝试编译以下代码:

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))

print dest-a*b

但是我遇到了以下错误:

> python test.py

Traceback (most recent call last):
  File "test.py", line 12, in <module>
    """)
  File "/Library/Python/2.7/site-packages/pycuda-2013.1.1-py2.7-macosx-10.9-intel.egg/pycuda/compiler.py", line 251, in __init__
    arch, code, cache_dir, include_dirs)
  File "/Library/Python/2.7/site-packages/pycuda-2013.1.1-py2.7-macosx-10.9-intel.egg/pycuda/compiler.py", line 241, in compile
    return compile_plain(source, options, keep, nvcc, cache_dir)
  File "/Library/Python/2.7/site-packages/pycuda-2013.1.1-py2.7-macosx-10.9-intel.egg/pycuda/compiler.py", line 132, in compile_plain
    stderr=stderr.decode("utf-8", "replace"))
pycuda.driver.CompileError: nvcc compilation of /var/folders/xr/m_rf4dp96mn2tb4yxlwcft7h0000gp/T/tmpqQcztC/kernel.cu failed
[command: nvcc --cubin -arch sm_30 -m64 -I/Library/Python/2.7/site-packages/pycuda-2013.1.1-py2.7-macosx-10.9-intel.egg/pycuda/cuda kernel.cu]
[stderr:
nvcc fatal   : Path to libdevice library not specified
]

我在谷歌上搜索了一下,找到了几个相关的讨论,但这些都没有解决我的问题;http://lists.tiker.net/pipermail/pycuda/2011-June/003244.html ...

谢谢大家!

1 个回答

1

问题是我没有从NVIDIA控制面板安装一个小更新。之后我更新了我的bash_profile,现在就可以正常工作了。嘿。

撰写回答