我正在我的spyder(python3)上尝试这段代码。
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)
但无法运行代码。
ExecError:错误调用'nvcc --version':[Errno 2]没有这样的文件或 目录:'nvcc':'nvcc'
我的nvcc - 版本是
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2016 NVIDIA Corporation
Built on Tue_Jan_10_13:22:03_CST_2017
Cuda compilation tools, release 8.0, V8.0.61
哪个nvcc
/usr/local/cuda-8.0/bin/nvcc
哪个spyder
/家庭/ anaconda3 /斌/ Spyder的
$ conda
/家庭/ anaconda3 / bin中/康达
设备查询:
./deviceQuery Starting...
CUDA Device Query (Runtime API) version (CUDART static linking)
Detected 1 CUDA Capable device(s)
Device 0: "GeForce 940MX"
CUDA Driver Version / Runtime Version 9.0 / 8.0
echo $ PATH
/home/anaconda3/bin:/usr/local/cuda-8.0/bin:/home/bin:/home/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/local/go/bin
我试过在终端上运行代码。然后它运行,但是从sourceModule行本身它显示错误。
"/home/anaconda3/lib/python3.6/site-packages/pycuda-2017.1-py3.6-linux-x86_64.egg/pycuda/compiler.py", line 255, in compile
return compile_plain(source, options, keep, nvcc, cache_dir, target)
File "/home/anaconda3/lib/python3.6/site-packages/pycuda-2017.1-py3.6-linux-x86_64.egg/pycuda/compiler.py", line 137, in compile_plain
stderr=stderr.decode("utf-8", "replace"))
pycuda.driver.CompileError: nvcc compilation of /tmp/tmpbdkxu33o/kernel.cu failed
[command: nvcc --cubin -arch sm_50 -I/home/anaconda3/lib/python3.6/site-packages/pycuda-2017.1-py3.6-linux-x86_64.egg/pycuda/cuda kernel.cu]
[stderr:
In file included from /usr/local/cuda-8.0/bin/..//include/cuda_runtime.h:78:0,
from <command-line>:0:
/usr/local/cuda-8.0/bin/..//include/host_config.h:119:2: error: #error -- unsupported GNU version! gcc versions later than 5 are not supported!
#error -- unsupported GNU version! gcc versions later than 5 are not supported!
^~~~~
]
此外,我已经尝试过我的Jupiter笔记本和其他Cuda安装的系统。但无法确定问题所在。任何帮助都很明显。
答案 0 :(得分:1)
通过终端处理python2虚拟环境。