use*_*358 3 python cuda gpu nvidia numba
我想使用 Numba 或类似的 Python CUDA 包访问各种 NVidia GPU 规范。可用设备内存、二级缓存大小、内存时钟频率等信息。
通过阅读这个问题,我了解到我可以通过 Numba 的 CUDA 设备接口访问一些信息(但不是全部)。
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))
Run Code Online (Sandbox Code Playgroud)
测试机上的输出:
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
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我缺少此处列出的许多字段,例如TOTAL_CONSTANT_MEMORY、、 和。MAX_SHARED_MEMORY_PER_BLOCKMEMORY_CLOCK_RATEMAX_THREADS_PER_MULTI_PROCESSOR
如何在 Python 中查看这些值?
__getattr__ 所有这些值都通过方法延迟设置为设备对象。您可以使用类似的方法访问它们。您需要的不是设备,而是枚举本身:
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))
Run Code Online (Sandbox Code Playgroud)