简体   繁体   中英

CUDA 9.0 and pycuda, error:CompileError: nvcc compilation … kernel.cu failed

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;
}
""")

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

But it is still error.

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

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

But it doesn't help.

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

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

I hope this works for you.

Edit: you need to run a MSVS version compatible with CUDA. Ie 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM