Skip to content
This repository was archived by the owner on Jan 25, 2023. It is now read-only.

Commit 9666627

Browse files
authored
Added separate dispatcher (#42)
1 parent 48740e3 commit 9666627

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

numba/core/cpu_dispatcher.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,8 @@ class CPUDispatcher(dispatcher.Dispatcher):
66
targetdescr = cpu_target
77

88
def __init__(self, py_func, locals={}, targetoptions={}, impl_kind='direct', pipeline_class=compiler.Compiler):
9-
if ('parallel' in targetoptions and isinstance(targetoptions['parallel'], dict) and
10-
'offload' in targetoptions['parallel'] and targetoptions['parallel']['offload'] == True):
11-
import numba.dppl_config as dppl_config
12-
if dppl_config.dppl_present:
13-
from numba.dppl.compiler import DPPLCompiler
14-
dispatcher.Dispatcher.__init__(self, py_func, locals=locals,
15-
targetoptions=targetoptions, impl_kind=impl_kind, pipeline_class=DPPLCompiler)
16-
else:
17-
print("---------------------------------------------------------------------------")
18-
print("WARNING : offload=True option ignored. Ensure OpenCL drivers are installed.")
19-
print("---------------------------------------------------------------------------")
20-
dispatcher.Dispatcher.__init__(self, py_func, locals=locals,
21-
targetoptions=targetoptions, impl_kind=impl_kind, pipeline_class=pipeline_class)
22-
else:
23-
dispatcher.Dispatcher.__init__(self, py_func, locals=locals,
24-
targetoptions=targetoptions, impl_kind=impl_kind, pipeline_class=pipeline_class)
9+
dispatcher.Dispatcher.__init__(self, py_func, locals=locals,
10+
targetoptions=targetoptions, impl_kind=impl_kind, pipeline_class=pipeline_class)
2511

2612

2713
dispatcher_registry['cpu'] = CPUDispatcher

numba/core/decorators.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from numba.stencils.stencil import stencil
1313
from numba.core import config, extending, sigutils, registry, cpu_dispatcher
1414

15-
1615
_logger = logging.getLogger(__name__)
1716

1817

@@ -151,6 +150,11 @@ def bar(x, y):
151150
else:
152151
target = options.pop('_target', 'cpu')
153152

153+
parallel_option = options.get('parallel')
154+
if isinstance(parallel_option, dict) and parallel_option.get('offload') is True:
155+
from numba.dppl import dppl_offload_dispatcher
156+
target = '__dppl_offload_gpu__'
157+
154158
options['boundscheck'] = boundscheck
155159

156160
# Handle signature
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from numba.core import dispatcher, compiler
2+
from numba.core.registry import cpu_target, dispatcher_registry
3+
import numba.dppl_config as dppl_config
4+
5+
6+
class DpplOffloadDispatcher(dispatcher.Dispatcher):
7+
targetdescr = cpu_target
8+
9+
def __init__(self, py_func, locals={}, targetoptions={}, impl_kind='direct', pipeline_class=compiler.Compiler):
10+
if dppl_config.dppl_present:
11+
from numba.dppl.compiler import DPPLCompiler
12+
targetoptions['parallel'] = True
13+
dispatcher.Dispatcher.__init__(self, py_func, locals=locals,
14+
targetoptions=targetoptions, impl_kind=impl_kind, pipeline_class=DPPLCompiler)
15+
else:
16+
print("---------------------------------------------------------------------")
17+
print("WARNING : DPPL pipeline ignored. Ensure OpenCL drivers are installed.")
18+
print("---------------------------------------------------------------------")
19+
dispatcher.Dispatcher.__init__(self, py_func, locals=locals,
20+
targetoptions=targetoptions, impl_kind=impl_kind, pipeline_class=pipeline_class)
21+
22+
dispatcher_registry['__dppl_offload_gpu__'] = DpplOffloadDispatcher

0 commit comments

Comments
 (0)