CUDA 9.0和pycuda,错误:CompileError:nvcc编译... kernel.cu失败 [英] CUDA 9.0 and pycuda, error:CompileError: nvcc compilation ... kernel.cu failed

查看:1315
本文介绍了CUDA 9.0和pycuda,错误:CompileError:nvcc编译... kernel.cu失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

import pycuda.driver as cuda
import pycuda.autoinit
from pycuda.compiler import SourceModule
import numpy
a = numpy.random.randn(4,4)
a = a.astype(numpy.float32)
a_gpu = cuda.mem_alloc(a.nbytes)
cuda.memcpy_htod(a_gpu, a)
mod = SourceModule("""
__global__ void doublify(float *a)
{
int idx = threadIdx.x + threadIdx.y*4;
a[idx] *= 2;
}
""")

我刚刚安装了CUDA 9.0和pycuda,我正在按照教程来运行第一个cuda程序. 但这总会导致错误:

I just installed CUDA 9.0 and pycuda, and I am following the tutorial to run the first cuda program. But it always turns out error:

CompileError:c:\ users \ rl74173 \ appdata \ local \ temp \ tmp6nww2c \ kernel.cu的nvcc编译失败

CompileError: nvcc compilation of c:\users\rl74173\appdata\local\temp\tmp6nww2c\kernel.cu failed

我做了一些研究,并从中找到了答案.所以我在运行之前添加了它:

I did some research and find some answers to this before. So I add this before running:

import os
os.system("vcvarsamd64.bat")

但这仍然是错误.

我还看到有人通过在nvcc.profile下方添加行来弄清楚

I also see someone figure it out by adding line below to nvcc.profile

COMPILER-BINDIR = C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64

我安装了Visual Studio Community 2017,因此我尝试了

I installed visual studio community 2017,so in my case, I tried

COMPILER-BINDIR = C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\atlmfc\lib\amd64

但这没有帮助.

推荐答案

好的,所以我为我修复了它.问题在于,运行vcvars64.bat sub 外壳中设置路径环境,然后将其关闭,因此设置的路径再次消失.

OK, so I fixed it for me. The problem is that running vcvars64.bat sets the path environment in a subshell... and then closes it, so the set path disappears again.

您想要的是自己更改路径:将路径添加到cl.exe编译器文件中.为此,我引用了这篇文章.就我而言,我必须在开始时将其添加到我的.py文件中:

What you want, is to change the path yourself: add the path to the cl.exe compiler file. For that, I referenced this post. In my case, I had to add this at the start to my .py file:

import os
if (os.system("cl.exe")):
    os.environ['PATH'] += ';'+r"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\bin\HostX64\x64"
if (os.system("cl.exe")):
    raise RuntimeError("cl.exe still not found, path probably incorrect")

我希望这对您有用.

您需要运行与CUDA兼容的MSVS版本. IE. CUDA v9.0不支持MSVS2017,而CUDA v9.1仅支持15.4版,不支持更高版本.通过从Visual Studio的本机工具命令提示符"中运行nvcc.exe来尝试使用它.

you need to run a MSVS version compatible with CUDA. I.e. CUDA v9.0 doesn't support MSVS2017 and CUDA v9.1 only supports version 15.4, not later versions. Try if it works by running nvcc.exe from the Native Tools Command Prompt for Visual Studio.

这篇关于CUDA 9.0和pycuda,错误:CompileError:nvcc编译... kernel.cu失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆