本文整理汇总了Python中chainer.backends.cuda.available方法的典型用法代码示例。如果您正苦于以下问题:Python cuda.available方法的具体用法?Python cuda.available怎么用?Python cuda.available使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类chainer.backends.cuda
的用法示例。
在下文中一共展示了cuda.available方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from chainer.backends import cuda [as 别名]
# 或者: from chainer.backends.cuda import available [as 别名]
def setUp(self):
x_shape_0 = 2
x_shape_1 = numpy.int64(3)
self.link = chainer.Link(x=((x_shape_0, x_shape_1), 'd'),
u=(None, 'd'))
with self.link.init_scope():
self.link.y = chainer.Parameter(shape=(2,))
self.link.v = chainer.Parameter()
self.p = numpy.array([1, 2, 3], dtype='f')
self.link.add_persistent('p', self.p)
self.link.name = 'a'
self.link.x.update_rule = chainer.UpdateRule()
self.link.x.update_rule.enabled = False
self.link.u.update_rule = chainer.UpdateRule()
if cuda.available:
self.current_device_id = cuda.cupy.cuda.get_device_id()
示例2: tearDown
# 需要导入模块: from chainer.backends import cuda [as 别名]
# 或者: from chainer.backends.cuda import available [as 别名]
def tearDown(self):
if cuda.available \
and cuda.cupy.cuda.get_device_id() != self.current_device_id:
cuda.Device(self.current_device_id).use()
示例3: pytest_runtest_teardown
# 需要导入模块: from chainer.backends import cuda [as 别名]
# 或者: from chainer.backends.cuda import available [as 别名]
def pytest_runtest_teardown(item, nextitem):
if cuda.available:
assert cuda.cupy.cuda.runtime.getDevice() == 0
# testing.run_module(__name__, __file__)
示例4: test_to_gpu_unavailable
# 需要导入模块: from chainer.backends import cuda [as 别名]
# 或者: from chainer.backends.cuda import available [as 别名]
def test_to_gpu_unavailable(self):
x = numpy.array([1])
if not cuda.available:
with self.assertRaises(RuntimeError):
cuda.to_gpu(x)
示例5: __init__
# 需要导入模块: from chainer.backends import cuda [as 别名]
# 或者: from chainer.backends.cuda import available [as 别名]
def __init__(self):
self.chainer_version = chainer.__version__
self.chainerx_available = chainerx.is_available()
self.numpy_version = numpy.__version__
self.platform_version = platform.platform()
if cuda.available:
self.cuda_info = cuda.cupyx.get_runtime_info()
else:
self.cuda_info = None
if intel64.is_ideep_available():
self.ideep_version = intel64.ideep.__version__
else:
self.ideep_version = None
示例6: get_array_module
# 需要导入模块: from chainer.backends import cuda [as 别名]
# 或者: from chainer.backends.cuda import available [as 别名]
def get_array_module(*args):
"""Gets an appropriate NumPy-compatible module to process arguments
This function will return their data arrays' array module for
:class:`~chainer.Variable` arguments.
Args:
args: Values to determine whether NumPy, CuPy, or ChainerX should be
used.
Returns:
module: :mod:`numpy`, :mod:`cupy`, or :mod:`chainerx` is returned based
on the types of the arguments.
"""
is_chainerx_available = chainerx.is_available()
if is_chainerx_available or cuda.available:
arrays = []
for arg in args:
# Unwrap arrays
if isinstance(arg, chainer.variable.Variable):
array = arg.data
else:
array = arg
if is_chainerx_available and isinstance(array, chainerx.ndarray):
return chainerx
arrays.append(array)
if cuda.available:
return cuda.cupy.get_array_module(*arrays)
return numpy
示例7: do_setup
# 需要导入模块: from chainer.backends import cuda [as 别名]
# 或者: from chainer.backends.cuda import available [as 别名]
def do_setup(deterministic=True):
if cuda.available:
cuda.cupy.testing.random.do_setup(deterministic)
else:
_numpy_do_setup(deterministic)
示例8: do_teardown
# 需要导入模块: from chainer.backends import cuda [as 别名]
# 或者: from chainer.backends.cuda import available [as 别名]
def do_teardown():
if cuda.available:
cuda.cupy.testing.random.do_teardown()
else:
_numpy_do_teardown()
# In some tests (which utilize condition.repeat or condition.retry),
# setUp/tearDown is nested. _setup_random() and _teardown_random() do their
# work only in the outermost setUp/tearDown pair.