本文整理匯總了Python中numba.cuda.jit方法的典型用法代碼示例。如果您正苦於以下問題:Python cuda.jit方法的具體用法?Python cuda.jit怎麽用?Python cuda.jit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類numba.cuda
的用法示例。
在下文中一共展示了cuda.jit方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: rasterio_windows
# 需要導入模塊: from numba import cuda [as 別名]
# 或者: from numba.cuda import jit [as 別名]
def rasterio_windows(totalWidth,totalHeight,subWidth,subHeight):
w_n=list(divide_chunks(list(range(totalWidth)), subWidth))
h_n=list(divide_chunks(list(range(totalHeight)), subHeight))
wins=[Window(w[0],h[0],len(w),len(h)) for h in h_n for w in w_n]
# print(wins)
print("raster windows amount:",len(wins))
return wins
# @njit(parallel=True)
# @cuda.jit(debug=True)
示例2: ArrayCoordi
# 需要導入模塊: from numba import cuda [as 別名]
# 或者: from numba.cuda import jit [as 別名]
def ArrayCoordi(rasterArray):
relativeCellCoords=np.indices(rasterArray.shape)
relativeCellCoords2D=np.stack(relativeCellCoords,axis=2).reshape(-1,2)
del relativeCellCoords
# print(relativeCellCoords2D_O)
return relativeCellCoords2D
#計算首尾坐標,用到三角函數
# @profile #內存監測所標識的函數
# @cuda.jit(debug=True)
# @njit(parallel=True)
#計算首尾坐標,用到三角函數
# @profile #內存監測所標識的函數
示例3: equalCircleDivide
# 需要導入模塊: from numba import cuda [as 別名]
# 或者: from numba.cuda import jit [as 別名]
def equalCircleDivide(originalCoordiArray,radious,lineProfileAmount):
# print(originalCoordiArray.shape)
angle_s=360/lineProfileAmount
angle_array=np.array([i*angle_s for i in range(lineProfileAmount)],dtype=np.float32)
#.astype(np.float16)
opposite=np.sin(np.radians(angle_array),dtype=np.float16)*radious
opposite=opposite.astype(np.float32)
# print(opposite.dtype)
yCoordi=np.add(opposite,originalCoordiArray[:,1].reshape(-1,1),dtype=np.float32)
del opposite
# print(yCoordi.dtype)
adjacent=np.cos(np.radians(angle_array),dtype=np.float16)*radious
xCoordi=np.add(adjacent,originalCoordiArray[:,0].reshape(-1,1),dtype=np.float32)
del adjacent,angle_array
# print(xCoordi.dtype)
CoordiArray=np.stack((xCoordi,yCoordi),axis=-1)
# print(CoordiArray.dtype)
# del xCoordi,yCoordi
return CoordiArray
#計算障礙角度和高度,以及SVF值。參考文獻:城區複雜下墊麵天空視域因子參數化方法——以北京鳥巢周邊地區為例
# @profile #內存監測所標識的函數
# @cuda.jit(debug=True)
# @njit(parallel=True)
示例4: SVF
# 需要導入模塊: from numba import cuda [as 別名]
# 或者: from numba.cuda import jit [as 別名]
def SVF(radious,equalDistance,ziList,j):
segment=radious/equalDistance
distanceList=np.array([i*segment for i in range(equalDistance+1)],dtype=np.float32)
distanceList=distanceList[1:]
ziListSub=ziList[:,:,1:]
ziListOrigin=ziList[:,:,0]
sinValues=np.true_divide(np.subtract(ziListSub,np.expand_dims(ziListOrigin, axis=2)),np.sqrt(np.add(np.power(distanceList,2),np.power(np.subtract(ziListSub,np.expand_dims(ziListOrigin, axis=2)),2))))
sinMaxValue=np.amax(sinValues,axis=2)
del sinValues
SVFValue=1-np.true_divide(np.sum(sinMaxValue, axis=1),sinMaxValue.shape[-1])
# SVFValueFn=os.path.join(saveFp,"SVFValue_%d"%(j))
# np.save(SVFValueFn, SVFValue)
# del SVFValue
# print("SVF Value saved:%d"%i)
# with open(os.path.join(saveFp,"SVFValue_filenames.txt"), "a") as text_file:
# text_file.write("%s\n"%SVFValueFn)
return SVFValue.astype(np.float32)
#數組延直線截麵提取單元值
# @profile #內存監測所標識的函數
# @cuda.jit(debug=True)
# @njit(parallel=True)
示例5: calc_nrst_dist_gpu
# 需要導入模塊: from numba import cuda [as 別名]
# 或者: from numba.cuda import jit [as 別名]
def calc_nrst_dist_gpu(gids,xs,ys,densities):
from numba import cuda, float64,float32
@cuda.jit
def calc_nrst_dist_cuda(gids,xs,ys,densities,nrst_dists,parent_gids,n):
'''
Numba Cuda code for calculate nearest point with higher density.
gids: identifier of geometry
xs: lons' array
ys: lats' array
densities: densities' array
nrst_dists: results of the nearest distance
parent_gids: results of gid of the nearest point with higher density
n: array size
'''
i=cuda.grid(1)
if i<n:
xi=xs[i]
yi=ys[i]
density=densities[i]
nrst_dist=float32(1e100)
parent_gid=np.int(-1)
for j in range(n):
xd=xs[j]-xi
yd=ys[j]-yi
gidd=gids[j]
distpow2=xd**2+yd**2
if densities[j]>density and distpow2<nrst_dist:
nrst_dist=distpow2
parent_gid=gidd
nrst_dists[i]=math.sqrt(float64(nrst_dist))
parent_gids[i]=parent_gid
n=xs.shape[0]
xs=np.ascontiguousarray((xs-xs.min()).astype(np.float32))
ys=np.ascontiguousarray((ys-ys.min()).astype(np.float32))
threadsperblock = 1024
blockspergrid = np.int((n + (threadsperblock - 1)) / threadsperblock)
dev_nrst_dists=cuda.device_array(n)
dev_parent_gids=cuda.device_array_like(gids)
calc_nrst_dist_cuda[blockspergrid,threadsperblock](cuda.to_device(np.ascontiguousarray(gids))\
,cuda.to_device(xs),cuda.to_device(ys),cuda.to_device(np.ascontiguousarray(densities))\
,dev_nrst_dists,dev_parent_gids,n)
return (dev_nrst_dists.copy_to_host(),dev_parent_gids.copy_to_host())