你可以使用这个功能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
Run Code Online (Sandbox Code Playgroud)
(注意:您可以通过简单的点引用访问不同的属性,例如,ans.MultiprocessorCount将给出7.)
另请参阅以下页面:
我刚刚在没有安装CUDA驱动程序的计算机上测试了这个.我得到的是以下异常(实际上是由current()GPUDevice类的方法引发的):
...'
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.
Run Code Online (Sandbox Code Playgroud)
出于这个原因,我建议首先围绕gpuDevice一个try-catch块,只有当它成功时,继续进行检查parallel.gpu.GPUDevice.isAvailable(1).
我的答案还没有涵盖的情况,例如具有多个GPU的设置(例如非CUDA板载1 +附加CUDA卡)或没有CUDA GPU的系统,但安装了CUDA驱动程序.对于多GPU情况,您还应该使用以下方法:
parallel.gpu.GPUDevice.count和parallel.gpu.GPUDevice.select(idx).