當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。