要访问Python中的GPU硬件规格? [英] Access GPU hardware specifications in Python?

查看:66
本文介绍了要访问Python中的GPU硬件规格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Numba或类似的Python CUDA来访问各种NVidia GPU规格.诸如可用设备内存,二级缓存大小,内存时钟频率等信息.

I want to access various NVidia GPU specifications using Numba or a similar Python CUDA pacakge. Information such as available device memory, L2 cache size, memory clock frequency, etc.

通过阅读

From reading this question, I learned I can access some of the information (but not all) through Numba's CUDA device interface.

from numba import cuda

device = cuda.get_current_device()
attribs = [s for s in dir(device) if s.isupper()]
for attr in attribs:
    print(attr, '=', getattr(device, attr))

在测试机上输出:

ASYNC_ENGINE_COUNT = 4
CAN_MAP_HOST_MEMORY = 1
COMPUTE_CAPABILITY = (5, 0)
MAX_BLOCK_DIM_X = 1024
MAX_BLOCK_DIM_Y = 1024
MAX_BLOCK_DIM_Z = 64
MAX_GRID_DIM_X = 2147483647
MAX_GRID_DIM_Y = 65535
MAX_GRID_DIM_Z = 65535
MAX_SHARED_MEMORY_PER_BLOCK = 49152
MAX_THREADS_PER_BLOCK = 1024
MULTIPROCESSOR_COUNT = 3
PCI_BUS_ID = 1
PCI_DEVICE_ID = 0
UNIFIED_ADDRESSING = 1
WARP_SIZE = 32

如您所见,我缺少列出的许多字段 TOTAL_CONSTANT_MEMORY , MAX_SHARED_MEMORY_PER_BLOCK MEMORY_CLOCK_RATE MAX_THREADS_PER_MULTI_PROCESSOR .

As you can see, I'm missing many fields listed here such as TOTAL_CONSTANT_MEMORY, MAX_SHARED_MEMORY_PER_BLOCK, MEMORY_CLOCK_RATE, and MAX_THREADS_PER_MULTI_PROCESSOR.

如何在Python中查看这些值?

How can I view these values in Python?

推荐答案

所有这些值都通过 __ getattr __ 此方法中一样访问它们.您需要的目录不是设备,而是枚举自身:

All these values are lazily set to device object via __getattr__ method. You can access them with similar like in this method. You need to dir not a device, but enums itself:

from numba.cuda.cudadrv import enums
from numba import cuda

device = cuda.get_current_device()
attribs= [name.replace("CU_DEVICE_ATTRIBUTE_", "") for name in dir(enums) if name.startswith("CU_DEVICE_ATTRIBUTE_")]
for attr in attribs:
    print(attr, '=', getattr(device, attr))

这篇关于要访问Python中的GPU硬件规格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆