Main Content

gpudeviceCount

存在的GPU设备数量

    描述

    例子

    n= gpudevicecount返回GPU设备驱动程序报告的本地计算机中存在的GPU设备的数量。计算驾驶员报告的所有设备,包括MATLAB中不支持的设备金宝app®以及在当前MATLAB会话中不可用的设备。

    例子

    n= gpudevicecount(countMode返回计算机中GPU设备的数量,根据countMode。使用此语法仅计数支持的GPU设备,或仅计算此MATLAB会话金宝app中可用的设备。

    例子

    [[n,,,,Indx] = gpudevicecount(___also returns the indices of the counted GPU devices for any of the previous syntaxes. Use this syntax when you want to select or examine the counted GPU devices.

    例子

    全部收缩

    确定计算机中可用的GPU设备的数量及其索引。

    [n,indx] = gpudevicecount
    n= 2 indx = 1 2

    查询使用GPU的属性gpudevicetable

    gpudevicetable
    ans = Index Name ComputeCapability DeviceAvailable DeviceSelected _____ __________________ _________________ _______________ ______________ 1 "TITAN RTX" "7.5" true false 2 "GeForce GTX 1080" "5.0" true true

    如果您可以访问多个GPU,则可以使用并行池在多个GPU上执行计算。

    To determine the number of GPUs that are available for use in MATLAB, use thegpudeviceCount功能。

    可用= gpudevicecount(“可用的”
    可用= 3

    与可用的GPU一样多的工人开始平行池。为了获得最佳性能,MATLAB默认情况下,MATLAB为每个工人分配了不同的GPU。

    Parpool('当地的',可用);
    使用“本地”配置文件开始并行池(PARPOOL)...连接到并行池(工人数:3)。

    To identify which GPU each worker is using, callgpudeviceinside anSPMD堵塞。这SPMDblock runsgpudeviceon every worker.

    SPMDgpudevice结尾

    使用平行语言功能,例如parforor帕菲瓦尔,将您的计算分发给平行池中的工人。如果您使用gpuarray在您的计算中启用了功能,这些功能在工人的GPU上运行。有关更多信息,请参阅在GPU上运行MATLAB功能。例如,请参阅在多个GPU上运行MATLAB功能

    完成计算后,关闭并行池。您可以使用GCP功能以获得当前的平行池。

    删除(GCP(GCP)('nocreate');

    If you want to use a different choice of GPUs, then you can usegpudeviceto select a particular GPU on each worker, using the GPU device index. You can obtain the index of each GPU device in your system using thegpudeviceCount功能。

    Suppose you have three GPUs available in your system, but you want to use only two for a computation. Obtain the indices of the devices.

    [[availableGPUs,gpuIndx] = gpuDeviceCount(“可用的”
    可用= 3
    gpuindx =1×31 2 3

    Define the indices of the devices you want to use.

    usegpus = [1 3];

    启动您的平行池。使用SPMD块和gpudeviceto associate each worker with one of the GPUs you want to use, using the device index. TheLabindex功能标识每个工人的索引。

    Parpool('当地的',numel(usegpus));
    使用“本地”配置文件开始并行池(PARPOOL)...连接到并行池(工人数:2)。
    SPMDgpudevice(useGPUs(labindex));结尾

    As a best practice, and for best performance, assign a different GPU to each worker.

    完成计算后,关闭并行池。

    删除(GCP(GCP)('nocreate');

    输入参数

    全部收缩

    设备计数模式,指定为以下之一:

    • "all"- 计数GPU设备驱动程序报告的所有GPU设备。计数包括在当前MATLAB会话中不可用的MATLAB和设备中不支持的设备。金宝app

    • “金宝app支持的”- 仅计算当前版本MATLAB支持的GPU设备。金宝app

    • “可用的”- 仅计算当前MATLAB会话中可用于使用的GPU设备。

    Example:“可用的”

    数据类型:char|细绳

    输出参数

    全部收缩

    Number of GPU devices, returned as a positive scalar.

    GPU设备的指标,作为数字vect返回or. Each element ofIndxis the device index of a counted GPU device. Use the device index to select or query the GPU device using thegpudevice功能。

    版本历史记录

    在R2010b中引入