主要内容

识别并选择GPU设备

这个例子展示了如何使用gpuDevice以确定并选择要使用的设备。

要确定计算机中有多少GPU设备可用,请使用gpuDeviceCount函数。

gpuDeviceCount (“可用”
ans = 2

当有多个设备时,第一个是默认的。属性可以检查它的属性gpuDeviceTable函数来确定是否要使用该函数。

gpuDeviceTable
ans =2×5表索引名称ComputeCapability DeviceAvailable DeviceSelected  _____ _____________ _________________ _______________ ______________ 1“泰坦RTX”“7.5”真的真的2”住宅区K620”“5.0”真的假的

如果第一个设备是您想要使用的设备,则可以继续。要在GPU上运行计算,请使用gpuArray启用的功能。有关更多信息,请参见在GPU上运行MATLAB函数

要使用另一个设备,打电话gpuDevice另一个设备的索引。

gpuDevice (2)
ans = CUDADevice with properties: Name: 'Quadro K620' Index: 2 ComputeCapability: '5.0' 金宝appSupportsDouble: 1 DriverVersion: 11 ToolkitVersion: 10.2000 MaxThreadsPerBlock: 1024 MaxShmemPerBlock: 49152 MaxThreadBlockSize: [1024 1024 64] MaxGridSize: [2.1475e+09 65535 65535] SIMDWidth: 32 TotalMemory: 2.1475e+09 AvailableMemory:1.6776e+09 MultiprocessorCount: 3 ClockRateKHz: 1124000 ComputeMode: 'Default' GPUOverlapsTransfers: 1 KernelExecutionTimeout: 1 CanMapHostMemory: 1 Device金宝appSupported: 1 DeviceAvailable: 1 DeviceSelected: 1

另请参阅

|||

相关的话题