GPU 不使用 python 计算

问题描述 投票:0回答:1

配备 RTX3070 的 ACER 笔记本电脑。安装了 CUDA、cuDNN、Tensorflow。

Tensorflow 检测 GPU。 CUDA 测试脚本检测 GPU 并显示 GPU 统计信息。

尝试运行此 jit 脚本来测试 GPU 计算,但出现错误。任何帮助将不胜感激。

谢谢

**Script:**
from numba import jit, cuda
import numpy as np
# to measure exec time
from timeit import default_timer as timer


# normal function to run on cpu
def func(a):
    for i in range(10000000):
        a[i] += 1

    # function optimized to run on gpu


@jit(target_backend='cuda')
def func2(a):
    for i in range(10000000):
        a[i] += 1


if __name__ == "__main__":
    n = 10000000
    a = np.ones(n, dtype=np.float64)

    start = timer()
    func(a)
    print("without GPU:", timer() - start)

    start = timer()
    func2(a)
    print("with GPU:", timer() - start)


**Error:**

"C:\Program Files\Python310\python.exe" E:\Programming\Projects\CUDA\TestingGPU.py 
without GPU: 1.1927146000000448
Traceback (most recent call last):
  File "E:\Programming\Projects\CUDA\TestingGPU.py", line 30, in <module>
    func2(a)
  File "C:\Users\Faheem\AppData\Roaming\Python\Python310\site-packages\numba\core\dispatcher.py", line 442, in _compile_for_args
    raise e
  File "C:\Users\Faheem\AppData\Roaming\Python\Python310\site-packages\numba\core\dispatcher.py", line 375, in _compile_for_args
    return_val = self.compile(tuple(argtypes))
  File "C:\Users\Faheem\AppData\Roaming\Python\Python310\site-packages\numba\core\dispatcher.py", line 905, in compile
    cres = self._compiler.compile(args, return_type)
  File "C:\Users\Faheem\AppData\Roaming\Python\Python310\site-packages\numba\core\dispatcher.py", line 80, in compile
    status, retval = self._compile_cached(args, return_type)
  File "C:\Users\Faheem\AppData\Roaming\Python\Python310\site-packages\numba\core\dispatcher.py", line 94, in _compile_cached
    retval = self._compile_core(args, return_type)
  File "C:\Users\Faheem\AppData\Roaming\Python\Python310\site-packages\numba\core\dispatcher.py", line 103, in _compile_core
    self.targetdescr.options.parse_as_flags(flags, self.targetoptions)
  File "C:\Users\Faheem\AppData\Roaming\Python\Python310\site-packages\numba\core\options.py", line 41, in parse_as_flags
    opt._apply(flags, options)
  File "C:\Users\Faheem\AppData\Roaming\Python\Python310\site-packages\numba\core\options.py", line 66, in _apply
    raise KeyError(m)
KeyError: "Unrecognized options: {'target_backend'}. Known options are dict_keys(['_dbg_extend_lifetimes', '_dbg_optnone', '_nrt', 'boundscheck', 'debug', 'error_model', 'fastmath', 'forceinline', 'forceobj', 'inline', 'looplift', 'no_cfunc_wrapper', 'no_cpython_wrapper', 'no_rewrites', 'nogil', 'nopython', 'parallel'])"

Process finished with exit code 1
python-3.x numba jit
1个回答
0
投票

谢谢您的回复。我查看了您提供的有关设置 target / target_backend 的网址。就我而言,我只是完全删除了目标并且它起作用了。这是代码:

之前的代码

@jit(target_backend=cuda)
def func2(a):
    for i in range(100000000):
        a[i] += 1

修改代码

@jit
def func2(a):
    for i in range(100000000):
        a[i] += 1

它起作用了。 CPU 和 GPU 计算输出为: 不带GPU:11.673872300001676 带GPU:0.19822520000161603 进程已完成,退出代码为 0

© www.soinside.com 2019 - 2024. All rights reserved.