简体   繁体   English

获取 CUDA_HOME 环境路径 PYTORCH

[英]Get CUDA_HOME environment path PYTORCH

I have cuda installed via anaconda on my system which has 2 GPUs which is getting recognized by my python.我通过 anaconda 在我的系统上安装了 cuda,该系统有 2 个 GPU,我的 python 可以识别这些 GPU。

import torch
torch.cuda.is_available()
true

However when I try to run a model via its C API, I m getting following error:但是,当我尝试通过其 C API 运行模型时,出现以下错误:

~/anaconda3/lib/python3.6/site-packages/torch/utils/cpp_extension.py in _join_cuda_home(*paths)
722     '''
723     if CUDA_HOME is None:
--> 724         raise EnvironmentError('CUDA_HOME environment variable is not set. '
725                                'Please set it to your CUDA install root.')
726     return os.path.join(CUDA_HOME, *paths)

OSError: CUDA_HOME environment variable is not set. Please set it to your CUDA install root.

https://lfd.readthedocs.io/en/latest/install_gpu.html page gives instruction to set up CUDA_HOME path if cuda is installed via their method. https://lfd.readthedocs.io/en/latest/install_gpu.html页面给出指令设置CUDA_HOME路径,如果通过他们的方法是安装CUDA。 Since I have installed cuda via anaconda I don't know which path to set.由于我已经通过 anaconda 安装了 cuda,我不知道要设置哪个路径。

I tried find method but it is returning me too many paths for cuda.我尝试了 find 方法,但它为我返回了太多的 cuda 路径。 Can somebody help me with the path for CUDA.有人可以帮助我了解 CUDA 的路径吗? Thanks in advance.提前致谢。

Solution to above issue!解决以上问题!

As cuda installed through anaconda is not the entire package.由于通过 anaconda 安装的 cuda 不是整个软件包。 Please install cuda drivers manually from Nvidia Website[ https://developer.nvidia.com/cuda-downloads ]请从 Nvidia 网站 [ https://developer.nvidia.com/cuda-downloads ] 手动安装 cuda 驱动程序

After installation of drivers, pytorch would be able to access the cuda path.安装驱动程序后,pytorch 将能够访问 cuda 路径。 You can test the cuda path using below sample code.您可以使用以下示例代码测试 cuda 路径。 Problem resolved!!!问题解决!!!

CHECK INSTALLATION:检查安装:

import os
print(os.environ.get('CUDA_PATH'))

OUTPUT:输出:

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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