Beispiel #1
0
 def test_per_device(self):
     with cuda.Device(0):
         stream0 = cuda.Stream()
         with stream0:
             assert stream0 == cuda.get_current_stream()
             with cuda.Device(1):
                 assert stream0 != cuda.get_current_stream()
                 assert cuda.Stream.null == cuda.get_current_stream()
             assert stream0 == cuda.get_current_stream()
Beispiel #2
0
 def test_with_statement(self):
     stream1 = cuda.Stream()
     stream2 = cuda.Stream()
     assert cuda.Stream.null == cuda.get_current_stream()
     with stream1:
         assert stream1 == cuda.get_current_stream()
         with stream2:
             assert stream2 == cuda.get_current_stream()
         assert stream1 == cuda.get_current_stream()
     assert cuda.Stream.null == cuda.get_current_stream()
Beispiel #3
0
 def test_with_statement(self):
     stream1 = cuda.Stream()
     stream2 = cuda.Stream()
     self.assertEqual(cuda.Stream.null, cuda.get_current_stream())
     with stream1:
         self.assertEqual(stream1, cuda.get_current_stream())
         with stream2:
             self.assertEqual(stream2, cuda.get_current_stream())
         self.assertEqual(stream1, cuda.get_current_stream())
     self.assertEqual(cuda.Stream.null, cuda.get_current_stream())
Beispiel #4
0
 def test_with_statement(self):
     stream1 = cuda.Stream()
     stream2 = cuda.Stream()
     assert self.stream == cuda.get_current_stream()
     with stream1:
         assert stream1 == cuda.get_current_stream()
         with stream2:
             assert stream2 == cuda.get_current_stream()
         assert stream1 == cuda.get_current_stream()
     # self.stream is "forgotten"!
     assert cuda.Stream.null == cuda.get_current_stream()
Beispiel #5
0
 def check_del(self, null, ptds):
     stream = cuda.Stream(null=null, ptds=ptds).use()
     assert stream is cuda.get_current_stream()
     stream_ptr = stream.ptr
     x = from_data.array([1, 2, 3])
     del stream
     assert stream_ptr == cuda.get_current_stream().ptr
     cuda.Stream.null.use()
     assert cuda.Stream.null is cuda.get_current_stream()
     # Want to test cudaStreamDestory is issued, but
     # runtime.streamQuery(stream_ptr) causes SEGV. We cannot test...
     del x
Beispiel #6
0
 def check_del(self, null):
     stream = cuda.Stream(null=null).use()
     stream_ptr = stream.ptr
     x = from_data.array([1, 2, 3])
     del stream
     self.assertEqual(cuda.Stream.null, cuda.get_current_stream())
     # Want to test cudaStreamDestory is issued, but
     # runtime.streamQuery(stream_ptr) causes SEGV. We cannot test...
     del stream_ptr
     del x
Beispiel #7
0
 def test_copyto_multigpu(self, xp, dtype):
     # TODO(kmaehashi): tentatively add print for debug (#4673)
     print('current stream:', cuda.get_current_stream())
     print('current device:', cuda.runtime.getDevice())
     with cuda.Device(0):
         a = testing.shaped_arange((2, 3, 4), xp, dtype)
     with cuda.Device(1):
         b = xp.empty((2, 3, 4), dtype=dtype)
     xp.copyto(b, a)
     return b
Beispiel #8
0
    def setUp(self):
        if cuda.runtime.is_hip and self.stream_name == 'ptds':
            self.skipTest('HIP does not support PTDS')

        self._prev_stream = cuda.get_current_stream()

        if self.stream_name == 'null':
            self.stream = cuda.Stream.null
        elif self.stream_name == 'ptds':
            self.stream = cuda.Stream.ptds
        self.stream.use()
Beispiel #9
0
 def f2(barrier, errors):
     global s1
     tid = barrier.wait()
     try:
         barrier.wait()  # until t1 creates the stream
         s1.use()
         barrier.wait()  # until t1 uses the stream
         s1 = None
         gc.collect()
         barrier.wait()  # until t1 decrefs the stream
         assert cuda.get_current_stream() is not None
         cupy.arange(10)
         errors[tid] = False
     except Exception as e:
         print(f'error in {tid}: {e}')
Beispiel #10
0
 def test_mix_use_context(self):
     # See cupy/cupy#5143
     s1 = cuda.Stream()
     s2 = cuda.Stream()
     s3 = cuda.Stream()
     assert cuda.get_current_stream() == self.stream
     with s1:
         assert cuda.get_current_stream() == s1
         s2.use()
         assert cuda.get_current_stream() == s2
         with s3:
             assert cuda.get_current_stream() == s3
             del s2
         assert cuda.get_current_stream() == s1
     # self.stream is "forgotten"!
     assert cuda.get_current_stream() == cuda.Stream.null
Beispiel #11
0
 def test_use(self):
     stream1 = cuda.Stream().use()
     assert stream1 == cuda.get_current_stream()
     cuda.Stream.null.use()
     assert cuda.Stream.null == cuda.get_current_stream()
Beispiel #12
0
 def test_use(self):
     stream1 = cuda.Stream().use()
     assert stream1 == cuda.get_current_stream()
     self.stream.use()
     assert self.stream == cuda.get_current_stream()
Beispiel #13
0
 def test_use(self):
     stream1 = cuda.Stream().use()
     self.assertEqual(stream1, cuda.get_current_stream())
     cuda.Stream.null.use()
     self.assertEqual(cuda.Stream.null, cuda.get_current_stream())