问题
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.
回答1:
Is there any code in python with either numba
or tensorflowinstalled?
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.
回答2:
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.
来源:https://stackoverflow.com/questions/48654403/how-do-i-know-the-maximum-number-of-threads-per-block-in-python-code-with-either