5

FYI, I have 64 bit version of Python 2.7 and I followed the pycuda installation instruction to install pycuda.

And I don't have any problem running following script.

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)

But after that, when executing this statement,

mod = SourceModule("""
__global__ void doublify(float *a)
{
int idx = threadIdx.x + threadIdx.y * 4;
a[idx] *= 2;
}
""")

I got the error messages

CompileError: nvcc compilation of c:\users\xxxx\appdata\local\temp\tmpaoxt97\kernel.cu failed [command: nvcc --cubin -arch sm_21 -m64 -Ic:\python27\lib\site-packages\pycuda\cuda kernel.cu] [stderr: nvcc : fatal error : nvcc cannot find a supported version of Microsoft Visual Studio. Only the versions 2008, 2010, and 2012 are supported

But I have VS 2008 and VS 2010 installed on the machine and set path and nvcc profile as instructed. Anybody tell me what's going on?

UPDATE1: As cgohike pointed out, running following statements before the problematic statement will solve the problem.

import os
os.system("vcvarsamd64.bat")
Tae-Sung Shin
  • 20,215
  • 33
  • 138
  • 240

2 Answers2

3

Well, it was too early to call it final. Even with resolution from cgohike, I got the same error when I ran other script like this

import pycuda.gpuarray as gpuarray
import pycuda.driver as cuda
import pycuda.autoinit
import numpy
a_gpu = gpuarray.to_gpu(numpy.random.randn(4, 4))
print "a_gpu ="
print a_gpu
a_doubled = (2*a_gpu).get()
print
print "a_doubled ="
print a_doubled

And then I found this answer. So in my case, I added following line in nvcc.profile

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

After this, no more compiler error I got. Hope it helps others.

Community
  • 1
  • 1
Tae-Sung Shin
  • 20,215
  • 33
  • 138
  • 240
  • How to edit the nvcc.profile ? In my case it doesnt allow rewriting this file at all. I tried editing it after I copied the file in another folder other than the C:\Program files location and then pasting it again in the C:\Program files. When it gets saved over the line entered disappears. Do you by any chance know anything about this ? – Kanmani Oct 27 '17 at 06:08
2

Call "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" amd64 or "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" amd64 before python.exe. That will set all the necessary environment variables to use the 64 bit Visual Studio compiler from Python or the command line.

cgohlke
  • 9,142
  • 2
  • 33
  • 36