【问题标题】:Matlab GPU computingMatlab GPU计算
【发布时间】:2014-09-12 13:07:19
【问题描述】:

我想要一个代码来检查我设计的软件 (GUI) 是否使用 CUDA-Core 显卡 (Nvidia) 在计算机上运行。所以在得到'true;从中受益,我的软件激活了一些加速过程的功能。

谢谢。

【问题讨论】:

    标签: matlab cuda gpu nvidia


    【解决方案1】:

    您可以使用函数gpuDevice。对我来说,我得到以下输出:

    ans = 
    
    CUDADevice with properties:
    
                      Name: 'GeForce GTX 660 Ti'
                     Index: 1
         ComputeCapability: '3.0'
            SupportsDouble: 1
             DriverVersion: 6
            ToolkitVersion: 5.5000
        MaxThreadsPerBlock: 1024
          MaxShmemPerBlock: 49152
        MaxThreadBlockSize: [1024 1024 64]
               MaxGridSize: [2.1475e+09 65535 65535]
                 SIMDWidth: 32
               TotalMemory: 2.1475e+09
                FreeMemory: 1.7126e+09
       MultiprocessorCount: 7
              ClockRateKHz: 1019500
               ComputeMode: 'Default'
      GPUOverlapsTransfers: 1
    KernelExecutionTimeout: 1
          CanMapHostMemory: 1
           DeviceSupported: 1
            DeviceSelected: 1
    

    (注意:您可以通过简单的点引用访问不同的属性,例如ans.MultiprocessorCount 将给出7。)

    另请参阅以下页面:

    1. MATLAB Central article

    2. Help #1 - GPUDevice class

    3. Help #2 - Identify and Select a GPU Device

    编辑

    我刚刚在没有安装 CUDA 驱动程序的计算机上对此进行了测试。我得到的是以下异常(实际上是由 GPUDevice 类的current() 方法抛出的):

    ...'
    Error using gpuDevice (line 26)
    There is a problem with the CUDA driver associated with this GPU device. See www.mathworks.com/gpudriver to find and install the latest
    supported driver.
    
    Caused by:
        The CUDA driver could not be loaded. The library name used was 'nvcuda.dll'. The error was:
        The specified module could not be found.
    

    出于这个原因,我建议首先gpuDevice 周围加上一个try-catch 块,并且只有在它成功的情况下,才继续进行parallel.gpu.GPUDevice.isAvailable(1) 之类的检查。

    我的回答仍然没有涵盖某些情况,例如具有多个 GPU 的设置(例如非 CUDA 板载一个 + 附加 CUDA 卡)或没有 CUDA GPU 但具有 CUDA 的系统安装的驱动程序。对于多 GPU 情况,您还应该使用以下方法: parallel.gpu.GPUDevice.countparallel.gpu.GPUDevice.select(idx)

    【讨论】:

    • 感谢您的回答 ;-)
    • 从您编辑的信息中,当我们使用try-catch 时,我们应该在catch 部分插入什么?我不希望我的程序返回异常或类似的东西。
    • 我想你应该使用可以在一个或多个 CPU 上运行的等效代码(使用matlabpoolparfor 等等)。
    • 更多信息:我的程序中有一个复选框。当系统中有GPU计算时是Enable,当系统中没有CODA-Core显卡时是Disable,所以我只想检查系统中CODA-Core`显卡的可用性.
    • 那么问题是什么?如何正确设置复选框的值? (我不明白为什么用户应该能够手动更改它,除非他想强制 CPU 计算)
    猜你喜欢
    • 2019-08-06
    • 1970-01-01
    • 2014-10-10
    • 2015-08-21
    • 2018-08-19
    • 2011-11-23
    • 2012-03-22
    • 1970-01-01
    • 2015-04-14
    相关资源
    最近更新 更多