我尝试使用 Numba 并访问 GPU 以加速代码,但出现以下错误:
in jit raise NotImplementedError("bounds checking is not supported for CUDA")
NotImplementedError: bounds checking is not supported for CUDA
我看到提出了另一个问题,但没有完全说明或回答here https://stackoverflow.com/questions/60012614/notimplementederror-bounds-checking-is-not-supported-for-cuda。
当我看到矢量化代码(y = corr*x + np.sqrt(1.-corr**2)*z
)不起作用(同样的错误)。我也尝试过使用这个选项boundscheck
,但这并没有改变结果。
未指定时不会出现该错误target
,因为它会自动运行在 CPU 上(我猜)。
import numpy as np
from numba import jit
N = int(1e8)
@jit(nopython=True, target='cuda', boundscheck=False)
def Brownian_motions(T, N, corr):
x = np.random.normal(0, 1, size=(T,N))
z = np.random.normal(0, 1, size=(T,N))
y = np.zeros(shape=(T,N))
for i in range(T):
for j in range(N):
y[i,j] = corr*x[i,j] + np.sqrt(1.-corr**2)*z[i,j]
return(x,y)
x, y = Brownian_motions(T = 500, N = N, corr = -0.45)
请你帮助我好吗? Python 是 3.7.6,Numba 是 0.48.0。