Numba有一个exc
装饰器,可以将Python代码编译成可在GPU上运行的通用ufunc。
所以这里我有这样一个功能:
@guvectorize
但是,像这样运行它:
@guvectorize([(float32[:,:], float32[:], float32[:])], '(m, n), (f)->(f)', target='cuda')
def getVolSpaceGpu(intersectionPt, xflat, volSpace):
for i in range(len(intersectionPt)):
pt = intersectionPt[i]
nearestGrid = ((xgrid - pt[0])**2 + (ygrid - pt[1])**2 + (zgrid - pt[2])**2).argmin()
volSpace[nearestGrid] = volSpace[nearestGrid] + 1
return volSpace
其中global xgrid
global ygrid
global zgrid
global xflat
xgrid = np.arange(-10, 10, 0.1).astype('float32')
ygrid = np.arange(-10, 10, 0.1).astype('float32')
zgrid = np.arange(-1, 5, 0.1).astype('float32')
xgrid, ygrid,zgrid = np.meshgrid(xgrid,ygrid,zgrid)
xflat = xgrid.flatten()
volSpace = np.zeros_like(xflat)
ans = getVolSpaceGPU(intersectionPt, xflat, volSpace)
只是3D坐标数组(例如intersectionPt
,我收到以下错误:
intersectionPt = np.array([[1, 2, 3], [4, 5, 6]])
如何从这里继续?