Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access GPU hardware specifications in Python?

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?

like image 759
user174358 Avatar asked Oct 27 '25 04:10

user174358


1 Answers

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))

like image 107
prudenko Avatar answered Oct 29 '25 18:10

prudenko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!