cuda_pinned_places

paddle.fluid. cuda_pinned_places ( device_count=None ) [源代码]

该接口创建 device_countfluid.CUDAPinnedPlace ( fluid. CUDAPinnedPlace ) 对象,并返回所创建的对象列表。

如果 device_countNone,实际设备数目将由当前任务中使用的GPU设备数决定。用户可通过以下2种方式设置任务可用的GPU设备:

  • 设置环境变量 FLAGS_selected_gpus ,例如 export FLAGS_selected_gpus='0,1'

  • 设置环境变量 CUDA_VISIBLE_DEVICES ,例如 export CUDA_VISIBLE_DEVICES='0,1'

关于如何设置任务中使用的GPU设备,具体请查看 fluid. cuda_places

参数:

  • device_count (int,可选) - 设备数目。默认值为 None

返回: fluid.CUDAPinnedPlace 对象列表。

返回类型:list[fluid.CUDAPinnedPlace]

代码示例

  1. import paddle.fluid as fluid
  2. # 1)不设置任何环境变量,默认使用所有的GPU,8卡的机器则将创建8个CUDAPinnedPlace
  3. # 2)export FLAGS_selected_gpus='0,1',则创建2个CUDAPinnedPlace
  4. cuda_pinned_places = fluid.cuda_pinned_places()
  5. # 3)创建1个CUDAPinnedPlace
  6. cuda_pinned_places = fluid.cuda_pinned_places(1)