首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >"nvcc致命:在路径中找不到编译器'cl.exe‘“

"nvcc致命:在路径中找不到编译器'cl.exe‘“
EN

Stack Overflow用户
提问于 2016-11-29 01:51:26
回答 2查看 9.8K关注 0票数 2

OS: win10

VS: visual stadio2015 64位

CUDA: CUDA8.0

python: python2.7.12 64位(pycuda)

我跟踪了这个网站,https://documen.tician.de/pycuda/tutorial.html#getting-started

代码语言:javascript
运行
复制
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)#transfer the data to the GPU

#executing a kernel
#function: write code to double each entry in a_gpu.
#we write the corresponding CUDA C code, and feed it into the constructor of pycuda.compiler.SourceModule
mod = SourceModule("""
    __global__ void doublify(float *a)
    {
        int idx = threadIdx.x + threadIdx.y*4;
        a[idx] *= 2;
    }
    """)

#If there aren’t any errors, the code is now compiled and loaded onto the device. We find a reference to our pycuda.driver.Function and call it, specifying a_gpu as the argument, and a block size of 4x4:
func = mod.get_function("doublify")
func(a_gpu, block=(4,4,1))

#Finally, we fetch the data back from the GPU and display it, together with the original a:
a_doubled = numpy.empty_like(a)
cuda.memcpy_dtoh(a_doubled, a_gpu)
print a_doubled
print a

但是,错误失败了:

代码语言:javascript
运行
复制
Traceback (most recent call last):
  File "G:/myworkspace/python2.7/cuda/test.py", line 24, in <module>
    """)
  File "D:\python2.7\lib\site-packages\pycuda\compiler.py", line 265, in __init__
    arch, code, cache_dir, include_dirs)
  File "D:\python2.7\lib\site-packages\pycuda\compiler.py", line 255, in compile
    return compile_plain(source, options, keep, nvcc, cache_dir, target)
  File "D:\python2.7\lib\site-packages\pycuda\compiler.py", line 137, in compile_plain
    stderr=stderr.decode("utf-8", "replace"))
CompileError: nvcc compilation of c:\users\gl\appdata\local\temp\tmp8poxqp\kernel.cu failed
[command: nvcc --cubin -arch sm_50 -m64 -Id:\python2.7\lib\site-packages\pycuda\cuda kernel.cu]
[stdout:
nvcc fatal   : Cannot find compiler 'cl.exe' in PATH

]

有人说要将cl.exe的dir添加到环境中。我做了,但错误是一样的。我是CUDA的新手。我怎样才能解决这个问题?有什么建议?

我做了“公民”,adviced建议:

将路径添加到cl.exe,D:\vs2015\VC\bin。

INCLUDE = C:\Program (x86)\Windows \10\Include\10.0.10240.0\ucrt。

LIB = C:\Program (x86)\Windows \10\Lib\10.0.10240.0\ucrt\x64(我在我的计算机中找不到C:\Program (x86)\Windows \10\Lib\10.0.10240.0\um\x64)。

有一个新的错误如下:

代码语言:javascript
运行
复制
raceback (most recent call last):
  File "G:\myworkspace\python2.7\cuda\test.py", line 24, in <module>
    """)
  File "D:\python2.7\lib\site-packages\pycuda\compiler.py", line 265, in __init__
    arch, code, cache_dir, include_dirs)
  File "D:\python2.7\lib\site-packages\pycuda\compiler.py", line 255, in compile
    return compile_plain(source, options, keep, nvcc, cache_dir, target)
  File "D:\python2.7\lib\site-packages\pycuda\compiler.py", line 147, in compile_plain
    + (stdout+stderr).decode("utf-8", "replace"), stacklevel=4)
  File "D:\python2.7\lib\idlelib\run.py", line 36, in idle_showwarning_subproc
    message, category, filename, lineno, line))
  File "D:\python2.7\lib\idlelib\PyShell.py", line 65, in idle_formatwarning
    s += "%s: %s\n" % (category.__name__, message)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 147-168: ordinal not in range(128)

现在我正在解决这个问题,可能是因为我没有添加C:\Program (x86)\Windows \10\Lib\10.0.10240.0\um\x64?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-11-30 05:42:53

我在.py中添加了这些代码

代码语言:javascript
运行
复制
import sys
reload(sys)
sys.setdefaultencoding('utf8')

然后运行,没有错误。

票数 1
EN

Stack Overflow用户

发布于 2017-12-19 19:06:16

您还可以在您的python文件中添加到cl.exe的路径。缺点是,如果MSVS版本更改,您将不得不对其进行更改。

示例:

代码语言:javascript
运行
复制
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版本。也就是说,库达v9.0不支持MSVS2017,而CUDA v9.1只支持15.4版本,而不是后期版本。通过从Visual的本机工具命令提示符运行nvcc.exe来尝试它是否工作。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40856535

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档