本文整理汇总了Python中caffe2.python.workspace.NumCudaDevices方法的典型用法代码示例。如果您正苦于以下问题:Python workspace.NumCudaDevices方法的具体用法?Python workspace.NumCudaDevices怎么用?Python workspace.NumCudaDevices使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类caffe2.python.workspace
的用法示例。
在下文中一共展示了workspace.NumCudaDevices方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_device_option
# 需要导入模块: from caffe2.python import workspace [as 别名]
# 或者: from caffe2.python.workspace import NumCudaDevices [as 别名]
def get_device_option(gpu=None):
"""Constructs `core.DeviceOption` object
:param int gpu: Identifier of GPU to use or None for CPU.
:return: Instance of `core.DeviceOption`.
"""
dev_opt = None
if gpu is None:
dev_opt = core.DeviceOption(caffe2_pb2.CPU)
else:
assert workspace.has_gpu_support, "Workspace does not support GPUs"
assert gpu >= 0 and gpu < workspace.NumCudaDevices(),\
"Workspace does not provide this gpu (%d). "\
"Number of GPUs is %d" % (gpu, workspace.NumCudaDevices())
dev_opt = core.DeviceOption(caffe2_pb2.CUDA, gpu)
return dev_opt