1 year ago

#345957

test-img

Tuna Yüce

Getting "nvcc preprocessing ... failed error" - Pycuda

I am trying to use PyCuda right now. I followed the tutorial on the official page and this code is working perfectly in my environment.

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;
  }
  """)
  
func = mod.get_function("doublify")
func(a_gpu, block=(4,4,1))

a_doubled = numpy.empty_like(a)
cuda.memcpy_dtoh(a_doubled, a_gpu)
print(a_doubled)
print(a)

Output:
[[ 1.098445    0.8321258   1.2041918   2.530517  ]
 [-2.3432384   2.3117933   2.7848036   4.025257  ]
 [ 1.3831481  -0.436876   -2.0395236   0.7690674 ]
 [-1.2118376   1.2235037  -0.89722884  2.9550834 ]]

[[ 0.5492225   0.4160629   0.6020959   1.2652586 ]
 [-1.1716192   1.1558967   1.3924018   2.0126286 ]
 [ 0.69157404 -0.218438   -1.0197618   0.3845337 ]
 [-0.6059188   0.61175185 -0.44861442  1.4775417 ]]

The problem is I am getting this error:

  File "C:\Users\arasu\AppData\Local\Temp/ipykernel_22084/2324443706.py", line 12, in <module>
    """)

  File "C:\Users\arasu\anaconda3\envs\hda\lib\site-packages\pycuda\compiler.py", line 358, in __init__
    include_dirs,

  File "C:\Users\arasu\anaconda3\envs\hda\lib\site-packages\pycuda\compiler.py", line 298, in compile
    return compile_plain(source, options, keep, nvcc, cache_dir, target)

  File "C:\Users\arasu\anaconda3\envs\hda\lib\site-packages\pycuda\compiler.py", line 87, in compile_plain
    checksum.update(preprocess_source(source, options, nvcc).encode("utf-8"))

  File "C:\Users\arasu\anaconda3\envs\hda\lib\site-packages\pycuda\compiler.py", line 59, in preprocess_source
    "nvcc preprocessing of %s failed" % source_path, cmdline, stderr=stderr

CompileError: nvcc preprocessing of C:\Users\arasu\AppData\Local\Temp\tmpsvfxijmf.cu failed

While trying to run this code. What am I missing here?

import pycuda.driver as cuda
import pycuda.autoinit
from pycuda.compiler import SourceModule

mod = SourceModule("""
  #include <stdio.h>
  __global__ void myfirst_kernel()
  {
    printf("Hello,PyCUDA!!!");
  }
  """)

function = mod.get_function("myfirst_kernel")
function(block=(1,1,1))

I checked my cuda versions and checked the visual studio environment variable and they all seemed normal to me. The thing I do not understand is, how is the first code is working if there is a problem here.

python

compiler-errors

anaconda

nvcc

pycuda

0 Answers

Your Answer

Accepted video resources