繁体   English   中英

如何在RStudio中用GPU激活R的手电筒package

[英]How to activate R's torch package with GPU in RStudio

我想在这里运行教程。 https://blogs.rstudio.com/ai/posts/2020-09-29-introducing-torch-for-r/

安装后

install.packages("torch")

然后当我在我的 RStudio 中激活它时,出现以下错误

> library(torch)

Attaching package: ‘torch’

The following object is masked from ‘package:reticulate’:

    as_iterator

> Sys.setenv(CUDA="/usr/local/cuda-10.2") 
> torch_tensor(1, device = "cuda")
Error: PyTorch is not linked with support for cuda devices
Exception raised from getDeviceGuardImpl at ../c10/core/impl/DeviceGuardImplInterface.h:319 (most recent call first):
frame #0: c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) + 0x6b (0x7fc04426c9cb in /home/ubuntu/R/x86_64-pc-linux-gnu-library/4.1/torch/lib/./libc10.so)
frame #1: c10::detail::torchCheckFail(char const*, char const*, unsigned int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) + 0xce (0x7fc04426837e in /home/ubuntu/R/x86_64-pc-linux-gnu-library/4.1/torch/lib/./libc10.so)
frame #2: <unknown function> + 0x120448d (0x7fc000b3d48d in /home/ubuntu/R/x86_64-pc-linux-gnu-library/4.1/torch/lib/./libtorch_cpu.so)
frame #3: at::native::to(at::Tensor const&, c10::optional<c10::ScalarType>, c10::optional<c10::Layout>, c10::optional<c10::Device>, c10::optional<bool>, bool, bool, c10::optional<c10::MemoryFormat>

我希望它返回:

torch_tensor 
 1
[ CUDAFloatType{1} ]

我知道我的机器中有几个 CUDA 引擎:

$ ls -lhSt /usr/local/
total 60K
drwxr-xr-x 17 root root 4.0K Sep 29 15:49 share
drwxr-xr-x  4 root root 4.0K Feb 19  2022 bin
drwxr-xr-x  7 root root 4.0K Dec 26  2021 lib
drwxr-xr-x  3 root root 4.0K Dec 26  2021 include
drwxr-xr-x  3 root root 4.0K Oct 19  2021 dcgm
drwxr-xr-x 18 root root 4.0K Oct 19  2021 cuda-10.0
lrwxrwxrwx  1 root root   20 Oct 19  2021 cuda -> /usr/local/cuda-10.0
drwxr-xr-x 20 root root 4.0K Oct 19  2021 cuda-10.2
drwxr-xr-x 19 root root 4.0K Oct 19  2021 cuda-10.1
drwxr-xr-x 25 root root 4.0K Oct 19  2021 cuda-11.0
drwxr-xr-x 19 root root 4.0K Oct 19  2021 cuda-11.1
drwxr-xr-x  4 root root 4.0K Oct 19  2021 init
drwxr-xr-x  3 root root 4.0K Oct 19  2021 etc
lrwxrwxrwx  1 root root    9 Feb 25  2021 man -> share/man
drwxr-xr-x  2 root root 4.0K Feb 25  2021 games
drwxr-xr-x  2 root root 4.0K Feb 25  2021 sbin
drwxr-xr-x  2 root root 4.0K Feb 25  2021 src

$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Nov__3_21:07:56_CDT_2017
Cuda compilation tools, release 9.1, V9.1.85

或者

$ nvidia-smi
Mon Jan 23 21:34:31 2023
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 470.161.03   Driver Version: 470.161.03   CUDA Version: 11.4

但为什么它不起作用? 有什么办法解决?

torch version 0.91仅支持 CUDA 库列表中的cuda-10.2库。 为确保正确安装,需要在安装过程中指定此版本。

第 1 步:初始安装

source("https://raw.githubusercontent.com/mlverse/torch/master/R/install.R")
install.packages("torch")

第 2 步:使用 CUDA 10.2 重新安装

library(torch)
install_torch(type = "10.2")

第三步:验证CUDA识别

torch_tensor(1, device = "cuda")
#torch_tensor 
# 1
#[ CUDAFloatType{1} ]

或者,您可以使用命令watch -n0.1 nvidia-smi来确认 CUDA 已被识别。

暂无
暂无

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

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