gpt4 book ai didi

python - Pycuda - 如何添加-ccbin clang-3.8

转载 作者:行者123 更新时间:2023-12-01 02:02:30 29 4
gpt4 key购买 nike

我目前正在尝试在 Debian 9 上使用 PyCUDA。我已经设法使 cuda 工作,如果我运行:

nvcc -ccbin clang-3.8 file.cu

我正确编译了该文件并且能够运行它。

但是,在我使用

安装了 pycuda 之后
apt-get install python-pycuda

并从他们的网站运行一个简单的示例:

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

但我收到以下错误:

CompileError                              Traceback (most recent call last)
<ipython-input-1-8e16128de7f2> in <module>()
10 dest[i] = a[i] * b[i];
11 }
---> 12 """)
13
14 multiply_them = mod.get_function("multiply_them")

/usr/lib/python2.7/dist-packages/pycuda/compiler.pyc in __init__(self, source, nvcc, options, keep, no_extern_c, arch, code, cache_dir, include_dirs)
263
264 cubin = compile(source, nvcc, options, keep, no_extern_c,
--> 265 arch, code, cache_dir, include_dirs)
266
267 from pycuda.driver import module_from_buffer

/usr/lib/python2.7/dist-packages/pycuda/compiler.pyc in compile(source, nvcc, options, keep, no_extern_c, arch, code, cache_dir, include_dirs, target)
253 options.append("-I"+i)
254
--> 255 return compile_plain(source, options, keep, nvcc, cache_dir, target)
256
257

/usr/lib/python2.7/dist-packages/pycuda/compiler.pyc in compile_plain(source, options, keep, nvcc, cache_dir, target)
135 raise CompileError("nvcc compilation of %s failed" % cu_file_path,
136 cmdline, stdout=stdout.decode("utf-8", "replace"),
--> 137 stderr=stderr.decode("utf-8", "replace"))
138
139 if stdout or stderr:

CompileError: nvcc compilation of /tmp/tmpVgfyrm/kernel.cu failed
[command: nvcc --cubin -arch sm_61 -I/usr/local/lib/python2.7/dist-packages/pycuda-2017.1.1-py2.7-linux-x86_64.egg/pycuda/cuda kernel.cu]
[stderr:
ERROR: No supported gcc/g++ host compiler found, but clang-3.8 is available.
Use 'nvcc -ccbin clang-3.8' to use that instead.
]

有人知道如何将 -ccbin clang-3.8 添加到 pycuda 吗?

最佳答案

根据 documentation ,您可以通过两种方式为 nvcc 指定编译器选项

  1. 通过 PYCUDA_DEFAULT_NVCC_FLAGS 环境变量设置默认编译器选项。
  2. 通过使用 options= 关键字传递的列表设置给定 SourceModule 的编译器选项

关于python - Pycuda - 如何添加-ccbin clang-3.8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49449355/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com