【问题标题】:How to check torch gpu compatibility without initializing CUDA?如何在不初始化 CUDA 的情况下检查 Torch gpu 兼容性?
【发布时间】:2021-10-09 12:44:07
【问题描述】:

尽管有最新的 cuda 版本,但较旧的 GPU 似乎不支持 torch。

在我的情况下,崩溃有以下错误:

/home/maxs/dev/mdb/venv38/lib/python3.8/site-packages/torch/cuda/__init__.py:83: UserWarning: 
    Found GPU%d %s which is of cuda capability %d.%d.
    PyTorch no longer supports this GPU because it is too old.
    The minimum cuda capability supported by this library is %d.%d.
    
  warnings.warn(old_gpu_warn.format(d, name, major, minor, min_arch // 10, min_arch % 10))
WARNING:lightwood-16979:Exception: CUDA error: no kernel image is available for execution on the device
CUDA kernel errors might be asynchronously reported at some other API call,so the stacktrace below might be incorrect.
For debugging consider passing CUDA_LAUNCH_BLOCKING=1. when training model: <lightwood.model.neural.Neural object at 0x7f9c34df1e80>
Process LearnProcess-1:13:
Traceback (most recent call last):
  File "/home/maxs/dev/mdb/venv38/sources/lightwood/lightwood/model/helpers/default_net.py", line 59, in forward
    output = self.net(input)
  File "/home/maxs/dev/mdb/venv38/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1051, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/maxs/dev/mdb/venv38/lib/python3.8/site-packages/torch/nn/modules/container.py", line 139, in forward
    input = module(input)
  File "/home/maxs/dev/mdb/venv38/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1051, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/maxs/dev/mdb/venv38/lib/python3.8/site-packages/torch/nn/modules/linear.py", line 96, in forward
    return F.linear(input, self.weight, self.bias)
  File "/home/maxs/dev/mdb/venv38/lib/python3.8/site-packages/torch/nn/functional.py", line 1847, in linear
    return torch._C._nn.linear(input, weight, bias)
RuntimeError: CUDA error: no kernel image is available for execution on the device
CUDA kernel errors might be asynchronously reported at some other API call,so the stacktrace below might be incorrect.
For debugging consider passing CUDA_LAUNCH_BLOCKING=1.

尽管发生了以下情况:

assert torch.cuda.is_available() == True
torch.version.cuda == '10.2'

我如何检查不支持 Torch 的旧 GPU 实际上尝试/捕获张量到 gpu 的传输?传输初始化 cuda,这会浪费 2GB 内存,这是我无法承受的,因为我将在数十个进程中运行此检查,然后由于初始化,所有这些都会额外浪费 2GB 内存。

【问题讨论】:

  • 问题在于 PyTorch 开发人员不为较旧的 GPU 构建,从概念上讲是为了节省空间,即使它们受支持。您可以构建自己的支持您需要使用的所有 GPU,然后问题变得没有实际意义

标签: python tensorflow pytorch gpu


【解决方案1】:

根据torch.cuda.__init__ 中实际上引发错误的代码,以下检查似乎有效:

import torch
from torch.cuda import device_count, get_device_capability

def is_cuda_compatible():
    compatible_device_count = 0
    if torch.version.cuda is not None:
        for d in range(device_count()):
            capability = get_device_capability(d)
            major = capability[0]
            minor = capability[1]
            current_arch = major * 10 + minor
            min_arch = min((int(arch.split("_")[1]) for arch in torch.cuda.get_arch_list()), default=35)
            if (not current_arch < min_arch
                    and not torch._C._cuda_getCompiledVersion() <= 9000):
                compatible_device_count += 1

    if compatible_device_count > 0:
        return True
    return False

不确定它是否 100% 正确,但将其放在这里以供反馈,以防其他人需要。

【讨论】:

    猜你喜欢
    • 2021-03-31
    • 2020-09-19
    • 1970-01-01
    • 2012-12-28
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 2017-02-20
    • 2022-11-10
    相关资源
    最近更新 更多