我正在做一个PyCuda代码,我想获得图形卡的属性(如warp的大小,每个块的最大线程数等)。
所以我去了这个页面:https://documen.tician.de/pycuda/driver.html
我看到了这个:
然后我在我的代码中写了以下内容:
import time
import numpy as np
from pycuda import driver, compiler, gpuarray, tools
import math
# -- initialize the device
import pycuda.autoinit
print(pycuda.driver.device_attribute.WARP_SIZE)
但是打印返回:WARP_SIZE
实际上,他返回一个包含“WARP_SIZE”的str,而不是表示warp大小的整数。
我做错了什么?
答案 0 :(得分:4)
您要打印的是需要传递给设备接口以检索该属性的枚举。你想要这样的东西:
import time
import numpy as np
from pycuda import driver, compiler, gpuarray, tools
import math
# -- initialize the device
import pycuda.autoinit
dev = pycuda.autoinit.device
print(dev.get_attribute(pycuda.driver.device_attribute.WARP_SIZE))
print(dev.get_attribute(pycuda.driver.device_attribute.MAX_BLOCK_DIM_X))
这样做:
$ python device_attr.py
32
1024