问题
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))
Output on a test machine:
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
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
.
How can I view these values in Python?
回答1:
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))
来源:https://stackoverflow.com/questions/62457151/access-gpu-hardware-specifications-in-python