當前位置: 首頁>>代碼示例>>Python>>正文


Python cuda.get_device_from_array方法代碼示例

本文整理匯總了Python中chainer.backends.cuda.get_device_from_array方法的典型用法代碼示例。如果您正苦於以下問題:Python cuda.get_device_from_array方法的具體用法?Python cuda.get_device_from_array怎麽用?Python cuda.get_device_from_array使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在chainer.backends.cuda的用法示例。


在下文中一共展示了cuda.get_device_from_array方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: backward

# 需要導入模塊: from chainer.backends import cuda [as 別名]
# 或者: from chainer.backends.cuda import get_device_from_array [as 別名]
def backward(self, inputs, grads):
        gpu = backend.get_array_module(*inputs) is cuda.cupy

        # TODO(unno): We can remove redundant gpu-cpu copy using
        # theano.sandbox.cuda.basic_ops.gpu_from_host
        args = [cuda.to_cpu(x) for x in inputs + grads]

        outputs = self.backward_func(*args)
        assert len(outputs) == len(inputs)

        if gpu:
            # TODO(unno): We can remove redundant gpu-cpu copy using
            # theano.sandbox.cuda.CudaNdarray.gpudata
            device = cuda.get_device_from_array(inputs)
            outputs = [cuda.to_gpu(x, device) for x in outputs]

        results = []
        for o, i in zip(outputs, inputs):
            if i.dtype.kind != 'f':
                o = None
            elif o.dtype != i.dtype:
                o = o.astype(i.dtype)
            results.append(o)
        return tuple(results) 
開發者ID:chainer,項目名稱:chainer,代碼行數:26,代碼來源:theano_function.py

示例2: test_get_device_from_array_for_numpy_int

# 需要導入模塊: from chainer.backends import cuda [as 別名]
# 或者: from chainer.backends.cuda import get_device_from_array [as 別名]
def test_get_device_from_array_for_numpy_int(self):
        assert cuda.get_device_from_array(numpy.int64(0)) is cuda.DummyDevice 
開發者ID:chainer,項目名稱:chainer,代碼行數:4,代碼來源:test_cuda.py

示例3: test_get_device_for_empty_array

# 需要導入模塊: from chainer.backends import cuda [as 別名]
# 或者: from chainer.backends.cuda import get_device_from_array [as 別名]
def test_get_device_for_empty_array(self):
        x = cuda.get_device_from_array(cuda.cupy.array([]).reshape((0, 10)))
        # TODO(okuta): Only check `assert x == cuda.Device(0)`
        #              when cupy/cupy#946 is merged
        assert x == cuda.Device(0) or x == cuda.DummyDevice 
開發者ID:chainer,項目名稱:chainer,代碼行數:7,代碼來源:test_cuda.py

示例4: test_get_device_warning

# 需要導入模塊: from chainer.backends import cuda [as 別名]
# 或者: from chainer.backends.cuda import get_device_from_array [as 別名]
def test_get_device_warning(self):
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter('always')
            cuda.get_device(cuda.cupy.array([1]))

        assert len(w) == 1
        assert w[0].category is DeprecationWarning
        assert ('get_device is deprecated. Please use get_device_from_id'
                ' or get_device_from_array instead.' in str(w[0].message)) 
開發者ID:chainer,項目名稱:chainer,代碼行數:11,代碼來源:test_cuda.py

示例5: test_get_device_from_array

# 需要導入模塊: from chainer.backends import cuda [as 別名]
# 或者: from chainer.backends.cuda import get_device_from_array [as 別名]
def test_get_device_from_array(self):
        arr = cuda.cupy.array([0])
        assert cuda.get_device_from_array(arr) == cuda.Device(0) 
開發者ID:chainer,項目名稱:chainer,代碼行數:5,代碼來源:test_cuda.py

示例6: __init__

# 需要導入模塊: from chainer.backends import cuda [as 別名]
# 或者: from chainer.backends.cuda import get_device_from_array [as 別名]
def __init__(self, array):
        super(Parameter, self).__init__()
        self.add_param('W', array.shape, dtype=array.dtype)
        self.W.array = array
        if isinstance(array, cuda.ndarray):
            self.to_gpu(cuda.get_device_from_array(array)) 
開發者ID:chainer,項目名稱:chainer,代碼行數:8,代碼來源:parameter.py

示例7: forward

# 需要導入模塊: from chainer.backends import cuda [as 別名]
# 或者: from chainer.backends.cuda import get_device_from_array [as 別名]
def forward(self, inputs):
        gpu = backend.get_array_module(*inputs) is cuda.cupy
        inputs = [cuda.to_cpu(x) for x in inputs]

        outputs = self.forward_func(*inputs)

        if gpu:
            # TODO(unno): We can remove redundant gpu-cpu copy using
            # theano.sandbox.cuda.CudaNdarray.gpudata
            device = cuda.get_device_from_array(inputs)
            outputs = [cuda.to_gpu(x, device) for x in outputs]

        return tuple(outputs) 
開發者ID:chainer,項目名稱:chainer,代碼行數:15,代碼來源:theano_function.py

示例8: concat_arrays

# 需要導入模塊: from chainer.backends import cuda [as 別名]
# 或者: from chainer.backends.cuda import get_device_from_array [as 別名]
def concat_arrays(arrays):
    # Convert `arrays` to numpy.ndarray or cupy.ndarray
    xp = cuda.get_array_module(arrays[0])
    with cuda.get_device_from_array(arrays[0]):
        return xp.concatenate(arrays) 
開發者ID:chainer,項目名稱:models,代碼行數:7,代碼來源:eval.py

示例9: __call__

# 需要導入模塊: from chainer.backends import cuda [as 別名]
# 或者: from chainer.backends.cuda import get_device_from_array [as 別名]
def __call__(self, rule, param):
        g = param.grad
        with cuda.get_device_from_array(g):
            g *= self.rate 
開發者ID:chainer,項目名稱:chainercv,代碼行數:6,代碼來源:gradient_scaling.py

示例10: init_state

# 需要導入模塊: from chainer.backends import cuda [as 別名]
# 或者: from chainer.backends.cuda import get_device_from_array [as 別名]
def init_state(self, param):
        xp = backend.get_array_module(param.data)
        with cuda.get_device_from_array(param.data):
            self.state['m'] = xp.zeros_like(param.data)
            self.state['v'] = xp.zeros_like(param.data)

        # For iDeep
        if isinstance(param.data, intel64.mdarray):
            self.state['m'] = intel64.ideep.array(
                self.state['m'], itype=intel64.ideep.wgt_array)
            self.state['v'] = intel64.ideep.array(
                self.state['v'], itype=intel64.ideep.wgt_array) 
開發者ID:Bartzi,項目名稱:kiss,代碼行數:14,代碼來源:radam.py

示例11: _check_array

# 需要導入模塊: from chainer.backends import cuda [as 別名]
# 或者: from chainer.backends.cuda import get_device_from_array [as 別名]
def _check_array(array, name):
    xp = cuda.get_array_module(array)
    with cuda.get_device_from_array(array):
        if not array.dtype == xp.float32:
            warnings.warn('non FP32 dtype detected in {}'.format(name))
            array = array.astype(xp.float32)
        if not (array.flags.c_contiguous or array.flags.f_contiguous):
            warnings.warn('non contiguous array detected in {}'.format(name))
            array = xp.ascontiguousarray(array)
    return array 
開發者ID:cybertronai,項目名稱:pytorch-sso,代碼行數:12,代碼來源:_utility.py


注:本文中的chainer.backends.cuda.get_device_from_array方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。