当前位置: 首页>>代码示例>>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;未经允许,请勿转载。