Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I know the maximum number of threads per block in python code with either numba or tensorflow installed?

Is there any code in python with either numba or tensorflow installed? For example, if I would like to know the GPU memory info, I can simply use:

from numba import cuda
gpus = cuda.gpus.lst
for gpu in gpus:
    with gpu:
        meminfo = cuda.current_context().get_memory_info()
        print("%s, free: %s bytes, total, %s bytes" % (gpu, meminfo[0], meminfo[1]))

in numba. But I can not find any code that gives me the maximum threads per block info. I would like the code to detect the maximum number of threads per block and further calculate the specified number of blocks in each direction.

like image 954
ZHANG Juenjie Avatar asked Nov 02 '25 17:11

ZHANG Juenjie


2 Answers

from numba import cuda
gpu = cuda.get_current_device()
print("name = %s" % gpu.name)
print("maxThreadsPerBlock = %s" % str(gpu.MAX_THREADS_PER_BLOCK))
print("maxBlockDimX = %s" % str(gpu.MAX_BLOCK_DIM_X))
print("maxBlockDimY = %s" % str(gpu.MAX_BLOCK_DIM_Y))
print("maxBlockDimZ = %s" % str(gpu.MAX_BLOCK_DIM_Z))
print("maxGridDimX = %s" % str(gpu.MAX_GRID_DIM_X))
print("maxGridDimY = %s" % str(gpu.MAX_GRID_DIM_Y))
print("maxGridDimZ = %s" % str(gpu.MAX_GRID_DIM_Z))
print("maxSharedMemoryPerBlock = %s" % str(gpu.MAX_SHARED_MEMORY_PER_BLOCK))
print("asyncEngineCount = %s" % str(gpu.ASYNC_ENGINE_COUNT))
print("canMapHostMemory = %s" % str(gpu.CAN_MAP_HOST_MEMORY))
print("multiProcessorCount = %s" % str(gpu.MULTIPROCESSOR_COUNT))
print("warpSize = %s" % str(gpu.WARP_SIZE))
print("unifiedAddressing = %s" % str(gpu.UNIFIED_ADDRESSING))
print("pciBusID = %s" % str(gpu.PCI_BUS_ID))
print("pciDeviceID = %s" % str(gpu.PCI_DEVICE_ID))

These appear to be all the attributes that are currently supported. I found the list here, which matches the enum values in the CUDA docs, so extending that is fairly trivial. I added CU_DEVICE_ATTRIBUTE_TOTAL_CONSTANT_MEMORY = 9, for example, and that now works as expected.

If I find time this weekend I'll try to round those out, get the docs updated, and submit a PR.

like image 188
user3691497 Avatar answered Nov 04 '25 10:11

user3691497


Is there any code in python with either numba or tensorflow installed?

Not that I can find. The numba device class appears to have facilities to retrieve device attributes:

In [9]: ddd=numba.cuda.get_current_device()

In [10]: print(ddd)
<CUDA device 0 'b'GeForce GTX 970''>

In [11]: print(ddd.attributes)
{}

but at least in the numba version I am using (0.31.0), the dictionary does not appear to be populated. Otherwise, it does not appear that any of the conventional driver API functionality for retrieving either device or compiled function properties are exposed by numba at this stage.

like image 44
2 revstalonmies Avatar answered Nov 04 '25 09:11

2 revstalonmies



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!