获取“nvcc 预处理...失败错误”-Pycuda

问题描述 投票:0回答:1

我现在正在尝试使用 PyCuda。我按照官方页面上的教程进行操作,该代码在我的环境中完美运行。

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 ]]

问题是我收到此错误:

  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

尝试运行此代码时。我在这里缺少什么?

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

我检查了我的 cuda 版本并检查了 Visual Studio 环境变量,它们对我来说似乎都很正常。我不明白的是,如果这里有问题,第一个代码是如何工作的。

python compiler-errors anaconda nvcc pycuda
1个回答
0
投票

你解决了“nvcc preprocessing of .... .cu”的问题了吗?我遇到过这样的问题

© www.soinside.com 2019 - 2024. All rights reserved.