gpt4 book ai didi

python - 运行 Numbapro CUDA 代码后计算机死机

转载 作者:行者123 更新时间:2023-12-01 05:24:57 36 4
gpt4 key购买 nike

谁能向我解释一下为什么每次我运行这段代码时我的电脑都会死机?

from numbapro import cuda
import numpy as np
from timeit import default_timer as time

n = 100
dtype = np.float32

@cuda.jit('void(float32[:,:], float32[:], float32[:])')
def cu_matrix_vector(A, b, c):
y, x = cuda.grid(2)

if x < n and y < n:
c[y] = 0.0
for i in range(n):
c[y] += A[y, i] * b[i]


A = np.array(np.random.random((n, n)), dtype=dtype)
B = np.array(np.random.random((n, 1)), dtype=dtype)
C = np.empty_like(B)

blockDim = 32, 8
gridDim = (n + blockDim[0] - 1)/blockDim[0], (n + blockDim[1] - 1)/blockDim[1]

print 'blockDim = (%d,%d)' %blockDim

s = time()
stream = cuda.stream()
with stream.auto_synchronize():
dA = cuda.to_device(A,stream)
dB = cuda.to_device(B,stream)
dC = cuda.to_device(C,stream)
cu_matrix_vector[(bpg, bpg), (tpb, tpb),stream](dA, dB, dC)
dC.to_host(stream)

e = time()
tcuda = e - s

print tcuda

输入代码后,我的电脑死机了。我不知道为什么。我感谢所有提前提供的帮助。

最佳答案

数组 B 不应该是二维数组:

B = np.array(np.random.random((n, 1)), dtype=dtype)

它应该是一维的:

B = np.array(np.random.random(n), dtype=dtype)

关于卡住,我假设您使用的是 OSX。 CUDA 驱动程序应在内核启动错误时返回错误代码,但在 OSX 上,显示管理器似乎会卡住。

关于python - 运行 Numbapro CUDA 代码后计算机死机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21555763/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com