python - 使用 numba 原子操作函数时遇到问题 (cuda.atomic.compare_and_swap)
问题描述
我正在尝试使用 Numba 为我的代码编写 cuda 内核。不知何故,我想在我的部分代码中使用原子操作,我写了一个测试内核来看看 cuda.atomic.compare_and_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)
这是一个非常幼稚的代码,我想我输入了变量的写入类型,但我得到了这个打字错误。它与 Numba 中的其他原子操作配合得很好。这是唯一对我不起作用的。有人可以帮我找出问题所在,还是有其他替代方法可以做到这一点?谢谢!
解决方案
推荐阅读
- kubernetes - Kubernetes:使用 nfs-client-provisioner 强制“$pvname”的值
- objective-c - 为什么我在实现委托以将值从子 swift 类传递给父目标 C 类时出错?
- r - XGboost 和 XGb.DMatrix
- python - 从类内部提取id
- java - 收到“java.lang.NullPointerException:获取android中的文件列表时出错
- axapta - 使用连接数据源自动将记录插入表单的两个数据源
- java - 具有继承和 JsonDeserialize 的 Lombok
- mongodb - 如何计算平均响应时间(不包括周末、节假日、非工作时间)MongoDB
- java - 如何使用 Cloudhopper SMPP 发送短信
- c++ - 为什么捕获变量会使 lambda 的类型独一无二?