Python chainer.backends.cuda.to_gpu() Examples

The following are 30 code examples of chainer.backends.cuda.to_gpu(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module chainer.backends.cuda , or try the search function .
Example #1
Source File: test_function_node.py    From chainer with MIT License 6 votes vote down vote up
def test_inconsistent_input_backends(self):
        class FunctionNode(chainer.FunctionNode):

            def forward(self, inputs):
                return inputs

        f = FunctionNode()

        # Cause inconsistency between inputs
        x1 = cuda.to_gpu(self.x1)

        x1 = chainer.Variable(x1)
        x2 = chainer.Variable(self.x2)

        with self.assertRaises(TypeError):
            f.apply((x1, x2)) 
Example #2
Source File: test_debug_print.py    From chainer with MIT License 6 votes vote down vote up
def test_forward_gpu(self):
        self.f.add_hook(self.h)
        self.f(chainer.Variable(cuda.to_gpu(self.x)),
               chainer.Variable(cuda.to_gpu(self.x)))
        expect = r'''^function\tDummyFunction
input data
<variable at 0x[0-9a-f]+>
- device: <CUDA Device 0>
- backend: <(type|class) 'cupy.core.core.ndarray'>
- shape: \(3L?, 5L?\)
- dtype: float32
- statistics: mean=[0-9.\-e]+, std=[0-9.\-e]+
- grad: None
<variable at 0x[0-9a-f]+>
- device: <CUDA Device 0>
- backend: <(type|class) 'cupy.core.core.ndarray'>
- shape: \(3L?, 5L?\)
- dtype: float32
- statistics: mean=[0-9.\-e]+, std=[0-9.\-e]+
- grad: None$
'''
        actual = self.io.getvalue()
        self.assertTrue(re.match(expect, actual), actual) 
Example #3
Source File: test_dilated_convolution_2d.py    From chainer with MIT License 5 votes vote down vote up
def test_col2im_consistency(self):
        col = conv.im2col_cpu(self.x, 3, 3, 2, 2, 2, 2, dy=2, dx=2)
        h, w = self.x.shape[2:]
        im_cpu = conv.col2im_cpu(col, 2, 2, 2, 2, h, w, dy=2, dx=2)
        im_gpu = conv.col2im_gpu(
            cuda.to_gpu(col), 2, 2, 2, 2, h, w, dy=2, dx=2)
        testing.assert_allclose(im_cpu, im_gpu.get()) 
Example #4
Source File: test_variable.py    From chainer with MIT License 5 votes vote down vote up
def test_repr_gpu(self):
        self.x.to_gpu()
        assert repr(self.x) == self.repr 
Example #5
Source File: test_dilated_convolution_2d.py    From chainer with MIT License 5 votes vote down vote up
def test_backward_gpu(self):
        with testing.assert_warns(DeprecationWarning):
            self.link.to_gpu()
        self.check_backward(cuda.to_gpu(self.x), cuda.to_gpu(self.gy)) 
Example #6
Source File: test_dilated_convolution_2d.py    From chainer with MIT License 5 votes vote down vote up
def test_im2col_consistency(self):
        col_cpu = conv.im2col_cpu(self.x, 3, 3, 2, 2, 2, 2, dy=2, dx=2)
        col_gpu = conv.im2col_gpu(
            cuda.to_gpu(self.x), 3, 3, 2, 2, 2, 2, dy=2, dx=2)
        testing.assert_allclose(col_cpu, col_gpu.get(), atol=0, rtol=0) 
Example #7
Source File: test_linear.py    From chainer with MIT License 5 votes vote down vote up
def test_backward_gpu(self):
        with testing.assert_warns(DeprecationWarning):
            self.link.to_gpu()
        self.check_backward(cuda.to_gpu(self.x), cuda.to_gpu(self.gy)) 
Example #8
Source File: test_linear.py    From chainer with MIT License 5 votes vote down vote up
def test_backward_gpu(self):
        with testing.assert_warns(DeprecationWarning):
            self.link.to_gpu()
        self.check_backward(cuda.to_gpu(self.x), cuda.to_gpu(self.gy)) 
Example #9
Source File: test_linear.py    From chainer with MIT License 5 votes vote down vote up
def test_forward_gpu(self):
        with testing.assert_warns(DeprecationWarning):
            self.link.to_gpu()
        self.check_forward(cuda.to_gpu(self.x)) 
Example #10
Source File: test_deformable_convolution_2d.py    From chainer with MIT License 5 votes vote down vote up
def test_backward_gpu(self):
        with testing.assert_warns(DeprecationWarning):
            self.link.to_gpu()
        self.check_backward(cuda.to_gpu(self.x),
                            cuda.to_gpu(self.gy)) 
Example #11
Source File: test_convolution_nd.py    From chainer with MIT License 5 votes vote down vote up
def test_im2col_consistency(self):
        col_cpu = conv_nd.im2col_nd_cpu(
            self.x, self.ksize, self.stride, self.pad)
        col_gpu = conv_nd.im2col_nd_gpu(
            cuda.to_gpu(self.x), self.ksize, self.stride, self.pad)
        testing.assert_allclose(col_cpu, col_gpu.get(), atol=0, rtol=0) 
Example #12
Source File: test_variable.py    From chainer with MIT License 5 votes vote down vote up
def test_repr_gpu(self):
        self.x.to_gpu()
        assert repr(self.x) == self.repr 
Example #13
Source File: test_variable.py    From chainer with MIT License 5 votes vote down vote up
def test_str_gpu(self):
        self.x.to_gpu()
        assert str(self.x) == self.str 
Example #14
Source File: test_variable.py    From chainer with MIT License 5 votes vote down vote up
def test_str_chainerx_gpu(self):
        self._skip_chainerx_unsupported_dtype()
        self.x.to_gpu()
        self.x.to_chx()
        assert str(self.x) == self.str 
Example #15
Source File: test_variable.py    From chainer with MIT License 5 votes vote down vote up
def test_repr_chainerx_gpu(self):
        self._skip_chainerx_unsupported_dtype()
        self.x.to_gpu()
        self.x.to_chx()
        assert repr(self.x) == self.repr 
Example #16
Source File: test_variable.py    From chainer with MIT License 5 votes vote down vote up
def test_str_gpu(self):
        self.x.to_gpu()
        assert str(self.x) == self.str 
Example #17
Source File: test_variable.py    From chainer with MIT License 5 votes vote down vote up
def test_repr_gpu(self):
        self.x.to_gpu()
        assert repr(self.x) == self.repr 
Example #18
Source File: test_variable.py    From chainer with MIT License 5 votes vote down vote up
def test_backward_gpu(self):
        self.check_backward(cuda.to_gpu(self.x)) 
Example #19
Source File: test_variable.py    From chainer with MIT License 5 votes vote down vote up
def test_gpu(self):
        self.check_item(cuda.to_gpu(self.x)) 
Example #20
Source File: test_variable.py    From chainer with MIT License 5 votes vote down vote up
def test_backward_gpu(self):
        self.check_backward(cuda.to_gpu(self.x)) 
Example #21
Source File: test_variable.py    From chainer with MIT License 5 votes vote down vote up
def test_forward_gpu(self):
        self.check_forward(cuda.to_gpu(self.x)) 
Example #22
Source File: test_variable.py    From chainer with MIT License 5 votes vote down vote up
def test_traceback_gpu(self):
        self.check_traceback(cuda.to_gpu(self.x)) 
Example #23
Source File: test_variable.py    From chainer with MIT License 5 votes vote down vote up
def test_shape_mismatch_unretain_gpu(self):
        self.check_shape_mismatch(cuda.to_gpu(self.x), False) 
Example #24
Source File: test_variable.py    From chainer with MIT License 5 votes vote down vote up
def test_dtype_mismatch_unretain_gpu(self):
        self.check_dtype_mismatch(cuda.to_gpu(self.x), False) 
Example #25
Source File: test_variable.py    From chainer with MIT License 5 votes vote down vote up
def test_dtype_mismatch_gpu(self):
        self.check_dtype_mismatch(cuda.to_gpu(self.x), True) 
Example #26
Source File: test_variable.py    From chainer with MIT License 5 votes vote down vote up
def test_type_mismatch_unretain_gpu(self):
        self.check_type_mismatch(cuda.to_gpu(self.x), False) 
Example #27
Source File: test_variable.py    From chainer with MIT License 5 votes vote down vote up
def test_type_mismatch_gpu(self):
        self.check_type_mismatch(cuda.to_gpu(self.x), True) 
Example #28
Source File: test_variable.py    From chainer with MIT License 5 votes vote down vote up
def test_set_creator_node_gpu(self):
        self.check_set_creator_node(cuda.to_gpu(self.x)) 
Example #29
Source File: test_variable.py    From chainer with MIT License 5 votes vote down vote up
def test_debug_print_gpu(self):
        v = chainer.Variable(self.arr)
        v.to_gpu(0)

        result = v.debug_print()
        assert 'device: <CUDA Device 0>' in result
        assert 'cupy.core.core.ndarray' in result

        self.check_debug_print(v, mean=float(cuda.cupy.mean(v.data)),
                               std=float(cuda.cupy.std(v.data))) 
Example #30
Source File: test_variable.py    From chainer with MIT License 5 votes vote down vote up
def test_addgrad_to_uninitialized_parameter_gpu_to_another_gpu(self):
        x = chainer.Parameter()
        y = chainer.Parameter(self.a)
        y.grad = self.b
        x.to_gpu(1)
        y.to_gpu(0)
        x.cleargrad()
        x.addgrad(y)
        cp = cuda.cupy
        assert isinstance(x.data, cp.ndarray)
        assert isinstance(x.grad, cp.ndarray)
        assert int(x.data.device) == 1
        assert int(x.grad.device) == 1
        cp.testing.assert_array_equal(x.grad, self.b)