Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions numba_dppy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ def _readenv(): ...

# Turn SPIRV-VALIDATION ON/OFF switch
SPIRV_VAL = _readenv("NUMBA_DPPY_SPIRV_VAL", int, 0)

FALLBACK_ON_CPU = _readenv("NUMBA_DPPY_FALLBACK_ON_CPU", int, 1)
3 changes: 2 additions & 1 deletion numba_dppy/dppy_lowerer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1171,7 +1171,8 @@ def lower(self):
if numba_dppy.compiler.DEBUG:
print("Failed to lower parfor on DPPY-device. Due to:\n", e)
lowering.lower_extensions[parfor.Parfor].pop()
if (lowering.lower_extensions[parfor.Parfor][-1] == numba.parfors.parfor_lowering._lower_parfor_parallel):
if ((lowering.lower_extensions[parfor.Parfor][-1] == numba.parfors.parfor_lowering._lower_parfor_parallel) and
numba_dppy.config.FALLBACK_ON_CPU == 1):
self.cpu_lower.lower()
self.base_lower = self.cpu_lower
else:
Expand Down
72 changes: 72 additions & 0 deletions numba_dppy/tests/test_controllable_fallback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import numpy as np

import numba
import numba_dppy
from numba_dppy.testing import unittest
from numba_dppy.testing import DPPYTestCase
from numba.tests.support import captured_stderr
import dpctl


@unittest.skipUnless(dpctl.has_gpu_queues(), 'test only on GPU system')
class TestDPPYFallback(DPPYTestCase):
def test_dppy_fallback_true(self):
@numba.jit
def fill_value(i):
return i

def inner_call_fallback():
x = 10
a = np.empty(shape=x, dtype=np.float32)

for i in numba.prange(x):
a[i] = fill_value(i)

return a

numba_dppy.compiler.DEBUG = 1
with captured_stderr() as msg_fallback_true:
with dpctl.device_context("opencl:gpu") as gpu_queue:
dppy = numba.njit(parallel=True)(inner_call_fallback)
dppy_fallback_true = dppy()

ref_result = inner_call_fallback()
numba_dppy.compiler.DEBUG = 0

np.testing.assert_array_equal(dppy_fallback_true, ref_result)
self.assertTrue('Failed to lower parfor on DPPY-device' in msg_fallback_true.getvalue())

@unittest.expectedFailure
def test_dppy_fallback_false(self):
@numba.jit
def fill_value(i):
return i

def inner_call_fallback():
x = 10
a = np.empty(shape=x, dtype=np.float32)

for i in numba.prange(x):
a[i] = fill_value(i)

return a

try:
numba_dppy.compiler.DEBUG = 1
numba_dppy.config.FALLBACK_ON_CPU = 0
with captured_stderr() as msg_fallback_true:
with dpctl.device_context("opencl:gpu") as gpu_queue:
dppy = numba.njit(parallel=True)(inner_call_fallback)
dppy_fallback_false = dppy()

finally:
ref_result = inner_call_fallback()
numba_dppy.config.FALLBACK_ON_CPU = 1
numba_dppy.compiler.DEBUG = 0

not np.testing.assert_array_equal(dppy_fallback_false, ref_result)
not self.assertTrue('Failed to lower parfor on DPPY-device' in msg_fallback_true.getvalue())


if __name__ == '__main__':
unittest.main()