当前位置: 首页>>代码示例>>Python>>正文


Python cuda.available方法代码示例

本文整理汇总了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() 
开发者ID:chainer,项目名称:chainer,代码行数:18,代码来源:test_link.py

示例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() 
开发者ID:chainer,项目名称:chainer,代码行数:6,代码来源:test_link.py

示例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__) 
开发者ID:chainer,项目名称:chainer,代码行数:8,代码来源:conftest.py

示例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) 
开发者ID:chainer,项目名称:chainer,代码行数:7,代码来源:test_cuda.py

示例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 
开发者ID:chainer,项目名称:chainer,代码行数:15,代码来源:_runtime_info.py

示例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 
开发者ID:chainer,项目名称:chainer,代码行数:32,代码来源:backend.py

示例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) 
开发者ID:chainer,项目名称:chainer,代码行数:7,代码来源:random.py

示例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. 
开发者ID:chainer,项目名称:chainer,代码行数:12,代码来源:random.py


注:本文中的chainer.backends.cuda.available方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。