@cuda.jit
def kurt_gpu(weight,var_np,out):
sA = cuda.shared.array(shape=1024, dtype=float32)
tid = cuda.threadIdx.x
inc = tid // weight.shape[0]
mul = 1024 // weight.shape[0]
w = int(cuda.blockIdx.x * mul + inc)
x = cuda.blockIdx.y
y = cuda.blockIdx.z
z = tid % weight.shape[0]
cuda.syncthreads()
if w < weight.shape[0]:
m = float32(0)
for n in range(var_np.shape[1]):
m += weight[w]*weight[x]*weight[y]*weight[z]*var_np[w,n]*var_np[x,n]*var_np[y,n]*var_np[z,n]
m /= var_np.shape[1]
sA[tid] = m
else:
sA[tid] = 0
cuda.syncthreads()
s = int(cuda.blockDim.x/2)
while s > 0:
if tid < s:
sA[tid] += sA[tid + s]
cuda.syncthreads()
s >>= 1
if tid == 0:
out[cuda.blockIdx.x,x,y] = sA[0]
@jit(nopython=False)def wrap2(): mul = int(1024/b.shape[0]) threadsperblock= mul*b.shape[0] bX = (int(b.shape[0]/mul)+1,b.shape[0],b.shape[0]) out = cuda.device_array(bX) kurt_gpu[bX,threadsperblock](b,c,out) out_host = out.copy_to_host() return out_host.sum()
a = np.random.rand(60,40)b = np.random.rand(60)c=a-np.expand_dims(a.mean(axis=-1),axis=-1)
` if w < weight.shape[0]:
m = float32(0)
for n in range(var_np.shape[1]):
m += weight[w]*weight[x]*weight[y]*weight[z]*var_np[w,n]*var_np[x,n]*var_np[y,n]*var_np[z,n]
m /= var_np.shape[1]
sA[tid] = m
else:
sA[tid] = 0
if w < weight.shape[0]: m = float32(0) for n in range(var_np.shape[1]): m += weight[w]*weight[x]*weight[y]*weight[z]*var_np[w,n]*var_np[x,n]*var_np[y,n]*var_np[z,n] m /= var_np.shape[1] sA[tid] = m
if w > weight.shape[0]: sA[tid] = 0 if w == weight.shape[0]: sA[tid] = 0
s = int(cuda.blockDim.x/2)
while s > 0:
if tid < s:
sA[tid] += sA[tid + s]
cuda.syncthreads()
s >>= 1
if tid == 0:
out[cuda.blockIdx.x,x,y] = sA[0]
--
You received this message because you are subscribed to the Google Groups "Numba Public Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to numba-users...@continuum.io.
To post to this group, send email to numba...@continuum.io.
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/numba-users/c07416f6-bd23-4900-973a-54bc2f3cf540%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.