我正在尝试使用Numba为我的代码编写cuda内核。不知何故,我想在我的部分代码中使用原子操作,并编写了一个测试内核来查看cuda.atomic.compare\u和\u swap是如何工作的。文件上写着:
from numba import cuda
import numpy as np
@cuda.jit
def atomicCAS(N,out1):
idx = cuda.threadIdx.x + cuda.blockIdx.x * cuda.blockDim.x
if idx >= N:
return
A = out1[idx:]
cuda.atomic.compare_and_swap(A,idx,0)
N = 1024
out1 = np.arange(N)
out1 = np.zeros(N)
dout1 = cuda.to_device(out1)
tpb = 32
bpg = int(np.ceil(N/tpb))
atomicCAS[bpg,tpb](N,dout1)
hout1 = dout1.copy_to_host()
然后我得到一个错误:
TypingError: Invalid use of Function(<class 'numba.cuda.stubs.atomic.compare_and_swap'>) with argument(s) of type(s): (array(float64, 1d, A), int64, Literal[int](0))
* parameterized
In definition 0:
All templates rejected with literals.
In definition 1:
All templates rejected without literals.
This error is usually caused by passing an argument of a type that is unsupported by the named function.
[1] During: resolving callee type: Function(<class 'numba.cuda.stubs.atomic.compare_and_swap'>)
[2] During: typing of call at /home/qinyu/test.py (20)
这是一个相当幼稚的代码,我想我输入了write类型的变量,但是我得到了这个typingerror。它与麻木的其他原子操作配合得很好。这是唯一一个不适合我的。有人能帮我解决这个问题吗?或者有其他的方法吗?谢谢
错误消息中的关键是:
仅CUDA atomicCAS supports integer types。不能传递浮点类型
相关问题 更多 >
编程相关推荐