我如何知道安装了 numba 或 tensorflow 的 python 代码中每个块的最大线程数?

ZHA*_*ie 2 python cuda numba tensorflow

python中是否有安装了numba或tensorflow的代码?例如,如果我想知道 GPU 内存信息,我可以简单地使用:

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]))
Run Code Online (Sandbox Code Playgroud)

在 numba。但是我找不到任何代码可以为我提供每个块信息的最大线程数。我希望代码能够检测每个块的最大线程数,并进一步计算每个方向上指定的块数。

小智 6

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))
Run Code Online (Sandbox Code Playgroud)

这些似乎是当前支持的所有属性。我在这里找到了列表,它与 CUDA 文档中的枚举值相匹配,因此扩展它是相当简单的。CU_DEVICE_ATTRIBUTE_TOTAL_CONSTANT_MEMORY = 9例如,我添加了,现在按预期工作。

如果我这个周末有时间,我会尝试解决这些问题,更新文档,并提交 PR。