无法识别的选项:使用 @jit(target="cuda") 时的 {'target'}

Jav*_*erM 2 python cuda numba

我使用 numba 库中的装饰器 @jit 优化了一些 python 代码。但是,我想指示 @jit 明确使用我的 GPU 设备。来自:@cuda.jit 和 @jit(target='gpu') 之间的区别,我知道我需要使用 @jit(target="cuda") 来做到这一点。

我尝试通过做这样的事情来做到这一点:

from numba import jit, cuda

@jit(target='cuda')  # The code runs normally without (target='cuda')
def function(args):
    # some code
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

KeyError: "Unrecognized options: {'target'}. Known options are dict_keys(['_nrt', 'boundscheck', 'debug', 'error_model', 'fastmath', 'forceinline', 'forceobj', 'inline', 'looplift', 'no_cfunc_wrapper', 'no_cpython_wrapper', 'no_rewrites', 'nogil', 'nopython', 'parallel', 'target_backend'])"
Run Code Online (Sandbox Code Playgroud)

我读过这篇文章:How to run numba.jitdecorated function on GPU? 但该解决方案不起作用。

我希望得到一些帮助,使 @jit(target='cuda') 工作而无需使用 @cuda.jit 重写代码,因为最后一个是用于在 Python 中编写 CUDA 内核并编译和运行它。

提前谢谢了!

小智 6

我遇到了类似的问题并通过更改为target解决target_backend

所以,我的装饰器就像@jit(target_backend="cuda")

这只是对我有用的快速修复,我没有进一步挖掘