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()
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()
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())
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()
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
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
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
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()
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}')
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
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()
def test_use(self): stream1 = cuda.Stream().use() assert stream1 == cuda.get_current_stream() self.stream.use() assert self.stream == cuda.get_current_stream()
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())