def test_printfloat(self): jprintfloat = cuda.jit('void()', debug=False)(printfloat) with captured_cuda_stdout() as stdout: jprintfloat() # CUDA and the simulator use different formats for float formatting self.assertIn(stdout.getvalue(), ["0 23 34.750000 321\n", "0 23 34.75 321\n"])
def test_too_many_args(self): # Tests that we emit the format string and warn when there are more # than 32 arguments, in common with CUDA C/C++ printf - this is due to # a limitation in CUDA vprintf, see: # https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#limitations cufunc = cuda.jit(print_too_many) r = np.arange(33) with captured_cuda_stdout() as stdout: with warnings.catch_warnings(record=True) as w: cufunc[1, 1](r) # Check that the format string was printed instead of formatted garbage expected_fmt_string = ' '.join(['%lld' for _ in range(33)]) self.assertIn(expected_fmt_string, stdout.getvalue()) # Check for the expected warning about formatting more than 32 items for warning in w: warnobj = warning.message if isinstance(warnobj, NumbaWarning): expected = ('CUDA print() cannot print more than 32 items. ' 'The raw format string will be emitted by the ' 'kernel instead.') if warnobj.msg == expected: break else: self.fail('Expected a warning for printing more than 32 items')
def test_string(self): cufunc = cuda.jit('void()', debug=False)(printstring) with captured_cuda_stdout() as stdout: cufunc[1, 3]() out = stdout.getvalue() lines = sorted(out.splitlines(True)) expected = ['%d hop! 999\n' % i for i in range(3)] self.assertEqual(lines, expected)
def test_cuhello(self): jcuhello = cuda.jit('void()', debug=False)(cuhello) with captured_cuda_stdout() as stdout: jcuhello[2, 3]() # The output of GPU threads is intermingled, just sanity check it out = stdout.getvalue() expected = ''.join('%d 999\n' % i for i in range(6)) self.assertEqual(sorted(out), sorted(expected))
def test_string(self): cufunc = cuda.jit("void()", debug=False)(printstring) with captured_cuda_stdout() as stdout: cufunc[1, 3]() out = stdout.getvalue() lines = sorted(out.splitlines(True)) expected = ["%d hop! 999\n" % i for i in range(3)] self.assertEqual(lines, expected)
def test_cuhello(self): jcuhello = cuda.jit('void()', debug=False)(cuhello) with captured_cuda_stdout() as stdout: jcuhello[2, 3]() # The output of GPU threads is intermingled, but each print() # call is still atomic out = stdout.getvalue() lines = sorted(out.splitlines(True)) expected = ['-42\n'] * 6 + ['%d 999\n' % i for i in range(6)] self.assertEqual(lines, expected)
def test_cuhello(self): jcuhello = cuda.jit("void()", debug=False)(cuhello) with captured_cuda_stdout() as stdout: jcuhello[2, 3]() # The output of GPU threads is intermingled, but each print() # call is still atomic out = stdout.getvalue() lines = sorted(out.splitlines(True)) expected = ["-42\n"] * 6 + ["%d 999\n" % i for i in range(6)] self.assertEqual(lines, expected)
def test_printempty(self): cufunc = cuda.jit('void()', debug=False)(printempty) with captured_cuda_stdout() as stdout: cufunc() self.assertEqual(stdout.getvalue(), "\n")
def test_string(self): cufunc = cuda.jit('void()', debug=False)(printstring) with captured_cuda_stdout() as stdout: cufunc() self.assertEqual(stdout.getvalue(), "0 hop! 999\n")