matlab - GPU上计算导致驱动程序错误 "stopped responding"

标签 matlab cuda parallel-processing nvidia matlab-gpu

我这里有一个无意义的小脚本,我正在 MATLAB R2013b 中执行它:

clear all;

n = 2000;
times = 50;
i = 0;

tCPU = tic;

disp 'CPU::'
A = rand(n, n);
B = rand(n, n);
disp '::Go'
for i = 0:times
    CPU = A * B;
end

tCPU = toc(tCPU);
tGPU = tic;

disp 'GPU::'
A = gpuArray(A);
B = gpuArray(B);
disp '::Go'
for i = 0:times
    GPU =  A * B ; 
end
tGPU = toc(tGPU);

fprintf('On CPU: %.2f sec\nOn GPU: %.2f sec\n', tCPU, tGPU);

不幸的是,执行后我收到一条来自 Windows 的消息:“显示驱动程序停止工作并已恢复。”。

enter image description here

我认为这意味着 Windows 没有从我的显卡驱动程序或其他东西获得响应。脚本返回且没有错误:

>> test
CPU::
::Go
GPU::
::Go
On CPU: 11.01 sec
On GPU: 2.97 sec

但是无论 GPU 是否耗尽内存,在我重新启动之前 MATLAB 都无法使用 GPU 设备。如果我不重新启动 MATLAB,我只会收到来自 CUDA 的消息:

>> test
Warning: An unexpected error occurred during CUDA
execution. The CUDA error was:
CUDA_ERROR_LAUNCH_TIMEOUT 
> In test at 1 
Warning: An unexpected error occurred during CUDA
execution. The CUDA error was:
CUDA_ERROR_LAUNCH_TIMEOUT 
> In test at 1 
Warning: An unexpected error occurred during CUDA
execution. The CUDA error was:
CUDA_ERROR_LAUNCH_TIMEOUT 
> In test at 1 
Warning: An unexpected error occurred during CUDA
execution. The CUDA error was:
CUDA_ERROR_LAUNCH_TIMEOUT 
> In test at 1 
CPU::
::Go
GPU::
Error using gpuArray
An unexpected error occurred during CUDA execution.
The CUDA error was:
the launch timed out and was terminated

Error in test (line 21)
A = gpuArray(A);

有人知道如何避免这个问题或者我在这里做错了什么吗?

如果需要,我的 GPU 设备:

>> gpuDevice

ans = 

  CUDADevice with properties:

                      Name: 'GeForce GTX 660M'
                     Index: 1
         ComputeCapability: '3.0'
            SupportsDouble: 1
             DriverVersion: 6
            ToolkitVersion: 5
        MaxThreadsPerBlock: 1024
          MaxShmemPerBlock: 49152
        MaxThreadBlockSize: [1024 1024 64]
               MaxGridSize: [2.1475e+09 65535 65535]
                 SIMDWidth: 32
               TotalMemory: 2.1475e+09
                FreeMemory: 1.9037e+09
       MultiprocessorCount: 2
              ClockRateKHz: 950000
               ComputeMode: 'Default'
      GPUOverlapsTransfers: 1
    KernelExecutionTimeout: 1
          CanMapHostMemory: 1
           DeviceSupported: 1
            DeviceSelected: 1

最佳答案

关键信息是 gpuDevice 输出的这一部分:

KernelExecutionTimeout: 1

这意味着主机显示驱动程序在您运行计算作业的 GPU 上处于事件状态。 NVIDIA 显示驱动程序包含一个看门狗定时器,它会终止任何花费超过预定义时间的任务,而不将控制权交还给驱动程序以进行屏幕刷新。这是为了防止出现长时间运行或卡住的计算作业通过卡住显示而导致计算机无响应的情况。 Matlab 脚本的运行时间显然超出了显示驱动程序看门狗定时器的限制。一旦发生这种情况,设备上保存的计算上下文将被破坏,Matlab 无法再使用该设备进行操作。您也许可以通过调用 reset 来重新初始化上下文。 ,我猜它会在幕后运行 cudaDeviceReset()

互联网上有很多有关此看门狗定时器的信息 - 例如 this Stack Overflow question 。如何修改此超时的解决方案取决于您的操作系统和硬件。避免这种情况的最简单方法是不在显示 GPU 上运行 CUDA 代码,或者增加计算作业的粒度,以便没有任何操作的运行时间超过超时限制。或者只是编写更快的代码...

关于matlab - GPU上计算导致驱动程序错误 "stopped responding",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21971484/

相关文章:

matlab - 带有附加参数的函数的 Fortran 最小化

c++ - 在 CUDA 设备代码和主机代码中创建模板类对象时未解析的外部函数

c++ - CUDA内核作为类的成员函数

python - "too many resources for launch"的解释

r - 并行和串行处理的系统时间

MATLAB GUI 访问句柄

matlab - 如何导入带有行标题和列标题的数据

arrays - 根据为 x 设置的条件将 x-y 数据 reshape 为子数组

python - python中的并行处理

c# - 并行图像处理伪影