【发布时间】:2019-11-29 12:55:44
【问题描述】:
我一直在尝试使用共享内存添加数字,因此如下所示:
线程0:共享内存变量sharedMemT[0]加1
线程1:给共享内存变量sharedMemT[0]加1
同步线程并将 sharedMemT[0] 存储到 output[0]
但结果是……1??
@cuda.jit()
def add(output):
sharedMemT = cuda.shared.array(shape=(1), dtype=int32)
sharedMemT[0] = 0
cuda.syncthreads()
sharedMemT[0] += 1
cuda.syncthreads()
output[0] = sharedMemT[0]
out = np.array([0])
add[1, 2](out)
print(out) # results in [1]
【问题讨论】:
标签: python cuda shared-memory numba