简体   繁体   English

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

[英]Computer freezes after running Numbapro CUDA code

Can anyone explain to me why everytime I run this code, my computer freeze? 谁能向我解释为什么每次我运行此代码时,计算机都会冻结?

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

After hitting the code, my computer freezes. 碰到代码后,我的电脑死机了。 I'm not sure why. 我不知道为什么。 I appreciate all the help in advance. 我先感谢所有帮助。

Array B should not be a 2D array: 数组B不应为2D数组:

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

It should be 1D: 应该是一维的:

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

Regarding the freezing, I assume you are using OSX. 关于冻结,我假设您正在使用OSX。 The CUDA driver should return an error code upon kernel launch error but, on OSX, it seems like the display manager will freeze. CUDA驱动程序应在内核启动错误时返回错误代码,但在OSX上,似乎显示管理器将冻结。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM