Skip to content

Commit 2e81acb

Browse files
Improve tests code (#57)
* change the test_prange * fix all tests and examples * Replace DPPLTestCase with DPPYTestCase * Fix typos * To update all the tests in numba_dppy/tests/dppl * Use explicit device selection in the examples * Replace dppl with dppy * Fix int64 to long long conversion on windows * Fixed test_with_dppy_context_cpu * Remove unused imports in tests Co-authored-by: Pokhodenko <sergey.pokhodenko@intel.com>
1 parent d84fcb4 commit 2e81acb

25 files changed

+52
-189
lines changed

numba_dppy/testing.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,13 @@
1-
from __future__ import print_function, absolute_import, division
2-
31
import contextlib
42
import sys
53

64
from numba.core import config
75
import unittest
86
from numba.tests.support import (
97
captured_stdout,
10-
SerialMixin,
118
redirect_c_stdout,
129
)
1310

14-
class DPPYTestCase(SerialMixin, unittest.TestCase):
15-
def setUp(self):
16-
#init()
17-
#TODO
18-
pass
19-
def tearDown(self):
20-
#reset()
21-
#TODO
22-
pass
23-
24-
class DPPYTextCapture(object):
25-
def __init__(self, stream):
26-
self._stream = stream
27-
28-
def getvalue(self):
29-
return self._stream.read()
30-
31-
class PythonTextCapture(object):
32-
def __init__(self, stream):
33-
self._stream = stream
34-
35-
def getvalue(self):
36-
return self._stream.getvalue()
3711

3812
@contextlib.contextmanager
3913
def captured_dppy_stdout():

numba_dppy/tests/test_arg_accessor.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
from __future__ import print_function, division, absolute_import
2-
31
import numpy as np
42

53
import numba_dppy, numba_dppy as dppy
6-
from numba_dppy.testing import unittest
7-
from numba_dppy.testing import DPPYTestCase
4+
import unittest
85
import dpctl
96

107

@@ -33,7 +30,7 @@ def call_kernel(global_size, local_size,
3330

3431

3532
@unittest.skipUnless(dpctl.has_cpu_queues(), 'test only on CPU system')
36-
class TestDPPYArgAccessorCPU(DPPYTestCase):
33+
class TestDPPYArgAccessorCPU(unittest.TestCase):
3734
def test_arg_with_accessor(self):
3835
C = np.ones_like(A)
3936
with dpctl.device_context("opencl:cpu") as cpu_queue:
@@ -50,7 +47,7 @@ def test_arg_without_accessor(self):
5047

5148

5249
@unittest.skipUnless(dpctl.has_gpu_queues(), 'test only on GPU system')
53-
class TestDPPYArgAccessorGPU(DPPYTestCase):
50+
class TestDPPYArgAccessorGPU(unittest.TestCase):
5451
def test_arg_with_accessor(self):
5552
C = np.ones_like(A)
5653
with dpctl.device_context("opencl:gpu") as gpu_queue:

numba_dppy/tests/test_arg_types.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
from __future__ import print_function, division, absolute_import
2-
31
import numpy as np
42

53
import numba_dppy, numba_dppy as dppy
6-
from numba_dppy.testing import unittest
7-
from numba_dppy.testing import DPPYTestCase
4+
import unittest
85
import dpctl
96

107

@@ -24,7 +21,7 @@ def call_mul_device_kernel(global_size, A, B, test):
2421

2522

2623
@unittest.skipUnless(dpctl.has_cpu_queues(), 'test only on CPU system')
27-
class TestDPPYArrayArgCPU(DPPYTestCase):
24+
class TestDPPYArrayArgCPU(unittest.TestCase):
2825
def test_integer_arg(self):
2926
x = np.int32(2)
3027
with dpctl.device_context("opencl:cpu") as cpu_queue:
@@ -59,7 +56,7 @@ def check_bool_kernel(A, test):
5956

6057

6158
@unittest.skipUnless(dpctl.has_gpu_queues(), 'test only on GPU system')
62-
class TestDPPYArrayArgGPU(DPPYTestCase):
59+
class TestDPPYArrayArgGPU(unittest.TestCase):
6360
def test_integer_arg(self):
6461
x = np.int32(2)
6562
with dpctl.device_context("opencl:gpu") as gpu_queue:

numba_dppy/tests/test_atomic_op.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
from __future__ import print_function, division, absolute_import
2-
31
import numpy as np
42

53
import numba
64
import numba_dppy, numba_dppy as dppy
7-
from numba_dppy.testing import unittest
8-
from numba_dppy.testing import DPPYTestCase
5+
import unittest
96
import dpctl
107

118
def atomic_add_int32(ary):
@@ -125,7 +122,7 @@ def call_fn_for_datatypes(fn, result, input, global_size):
125122

126123
@unittest.skipUnless(dpctl.has_gpu_queues(), 'test only on GPU system')
127124
@unittest.skipUnless(numba_dppy.ocl.atomic_support_present(), 'test only when atomic support is present')
128-
class TestAtomicOp(DPPYTestCase):
125+
class TestAtomicOp(unittest.TestCase):
129126
def test_atomic_add_global(self):
130127
@dppy.kernel
131128
def atomic_add(B):

numba_dppy/tests/test_barrier.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
from __future__ import print_function, division, absolute_import
2-
31
import numpy as np
42

5-
from numba_dppy.testing import unittest
6-
from numba_dppy.testing import DPPYTestCase
3+
import unittest
74
from numba import float32
85
import numba_dppy, numba_dppy as dppy
96
import dpctl

numba_dppy/tests/test_black_scholes.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
from __future__ import print_function, division, absolute_import
2-
31
import numpy as np
42
import math
53
import time
64

75
import numba_dppy, numba_dppy as dppy
8-
from numba_dppy.testing import unittest
9-
from numba_dppy.testing import DPPYTestCase
6+
import unittest
107
import dpctl
118

129

@@ -49,7 +46,7 @@ def randfloat(rand_var, low, high):
4946

5047

5148
@unittest.skipUnless(dpctl.has_gpu_queues(), 'test only on GPU system')
52-
class TestDPPYBlackScholes(DPPYTestCase):
49+
class TestDPPYBlackScholes(unittest.TestCase):
5350
def test_black_scholes(self):
5451
OPT_N = 400
5552
iterations = 2

numba_dppy/tests/test_caching.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
1-
from __future__ import print_function
2-
from timeit import default_timer as time
3-
41
import sys
52
import numpy as np
63
import numba_dppy, numba_dppy as dppy
74
import dpctl
8-
from numba_dppy.testing import unittest
9-
from numba_dppy.testing import DPPYTestCase
5+
import unittest
106

117

128
def data_parallel_sum(a, b, c):
139
i = dppy.get_global_id(0)
1410
c[i] = a[i] + b[i]
1511

1612

17-
class TestCaching(DPPYTestCase):
13+
class TestCaching(unittest.TestCase):
1814
def test_caching_kernel(self):
1915
global_size = 10
2016
N = global_size

numba_dppy/tests/test_device_array_args.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
#! /usr/bin/env python
2-
from __future__ import print_function
3-
from timeit import default_timer as time
4-
52
import sys
63
import numpy as np
74
import numba_dppy, numba_dppy as dppy
85
import dpctl
9-
from numba_dppy.testing import unittest
10-
from numba_dppy.testing import DPPYTestCase
6+
import unittest
117

128
@dppy.kernel
139
def data_parallel_sum(a, b, c):
@@ -24,7 +20,7 @@ def data_parallel_sum(a, b, c):
2420

2521

2622
@unittest.skipUnless(dpctl.has_cpu_queues(), 'test only on CPU system')
27-
class TestDPPYDeviceArrayArgsGPU(DPPYTestCase):
23+
class TestDPPYDeviceArrayArgsGPU(unittest.TestCase):
2824
def test_device_array_args_cpu(self):
2925
c = np.ones_like(a)
3026

@@ -35,7 +31,7 @@ def test_device_array_args_cpu(self):
3531

3632

3733
@unittest.skipUnless(dpctl.has_gpu_queues(), 'test only on GPU system')
38-
class TestDPPYDeviceArrayArgsCPU(DPPYTestCase):
34+
class TestDPPYDeviceArrayArgsCPU(unittest.TestCase):
3935
def test_device_array_args_gpu(self):
4036
c = np.ones_like(a)
4137

numba_dppy/tests/test_dpctl_api.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
from __future__ import print_function, division, absolute_import
2-
3-
import numpy as np
4-
5-
from numba_dppy.testing import unittest
6-
from numba_dppy.testing import DPPYTestCase
1+
import unittest
72
import dpctl
83

94

105
@unittest.skipUnless(dpctl.has_gpu_queues(), 'test only on GPU system')
11-
class TestDPCTLAPI(DPPYTestCase):
6+
class TestDPCTLAPI(unittest.TestCase):
127
def test_dpctl_api(self):
138
with dpctl.device_context("opencl:gpu") as gpu_queue:
149
dpctl.dump()

numba_dppy/tests/test_dpnp_functions.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#! /usr/bin/env python
2-
from __future__ import print_function
32
from timeit import default_timer as time
43

54
import sys
@@ -8,8 +7,8 @@
87
import numba_dppy
98
import numba_dppy as dppy
109
import dpctl
11-
from numba_dppy.testing import unittest
12-
from numba_dppy.testing import DPPYTestCase
10+
import unittest
11+
1312

1413

1514
def test_for_different_datatypes(fn, test_fn, dims, arg_count, tys, np_all=False, matrix=None):
@@ -83,15 +82,14 @@ def test_for_dimensions(fn, test_fn, dims, tys, np_all=False):
8382

8483
def ensure_dpnp():
8584
try:
86-
# import dpnp
8785
from numba_dppy.dpnp_glue import dpnp_fptr_interface as dpnp_glue
8886
return True
8987
except:
9088
return False
9189

9290

9391
@unittest.skipUnless(ensure_dpnp() and dpctl.has_gpu_queues(), 'test only when dpNP and GPU is available')
94-
class Testdpnp_functions(DPPYTestCase):
92+
class Testdpnp_functions(unittest.TestCase):
9593

9694
N = 10
9795

0 commit comments

Comments
 (0)