Skip to content

Commit d8dd46d

Browse files
author
Diptorup Deb
committed
Various improvements to the DpexTarget context.
- Implement refresh and a dpex target registry. - Initialize the dpjit dispacther and runtime sub-modules when dpex loads. - doxstrings etc.
1 parent 378abc9 commit d8dd46d

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-1
lines changed

numba_dpex/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55
"""
66
The numba-dpex extension module adds data-parallel offload support to Numba.
77
"""
8-
import numba.testing
98

9+
import numba_dpex.core.dpjit_dispatcher
1010
import numba_dpex.core.offload_dispatcher
1111

12+
# Initialize the _dpexrt_python extension
13+
import numba_dpex.core.runtime
14+
import numba_dpex.core.targets.dpjit_target
15+
1216
# Re-export types itself
1317
import numba_dpex.core.types as types
1418
from numba_dpex.core.kernel_interface.utils import *

numba_dpex/core/dpjit_dispatcher.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212

1313

1414
class DpjitDispatcher(dispatcher.Dispatcher):
15+
"""A dpex.djit-specific dispatcher.
16+
17+
The DpjitDispatcher sets the targetdescr string to "dpex" so that Numba's
18+
Dispatcher can lookup the global target_registry with that string and
19+
correctly use the DpexTarget context.
20+
21+
"""
22+
1523
targetdescr = dpex_target
1624

1725
def __init__(

numba_dpex/core/targets/dpjit_target.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
"""Defines the target and typing contexts for numba_dpex's dpjit decorator.
66
"""
77

8+
from numba.core import utils
9+
from numba.core.codegen import JITCPUCodegen
10+
from numba.core.compiler_lock import global_compiler_lock
811
from numba.core.cpu import CPUContext
12+
from numba.core.imputils import Registry, RegistryLoader
913
from numba.core.target_extension import CPU, target_registry
1014

1115

@@ -19,7 +23,38 @@ class Dpex(CPU):
1923
# permits lookup and reference in user space by the string "dpex"
2024
target_registry[DPEX_TARGET_NAME] = Dpex
2125

26+
# This is the function registry for the dpu, it just has one registry, this one!
27+
dpex_function_registry = Registry()
28+
2229

2330
class DpexTargetContext(CPUContext):
2431
def __init__(self, typingctx, target=DPEX_TARGET_NAME):
2532
super().__init__(typingctx, target)
33+
34+
@global_compiler_lock
35+
def init(self):
36+
self.is32bit = utils.MACHINE_BITS == 32
37+
self._internal_codegen = JITCPUCodegen("numba.exec")
38+
self.lower_extensions = {}
39+
# Initialize NRT runtime
40+
# rtsys.initialize(self)
41+
self.refresh()
42+
43+
@utils.cached_property
44+
def dpexrt(self):
45+
from numba_dpex.core.runtime.context import DpexRTContext
46+
47+
return DpexRTContext(self)
48+
49+
def refresh(self):
50+
registry = dpex_function_registry
51+
try:
52+
loader = self._registries[registry]
53+
except KeyError:
54+
loader = RegistryLoader(registry)
55+
self._registries[registry] = loader
56+
self.install_registry(registry)
57+
# Also refresh typing context, since @overload declarations can
58+
# affect it.
59+
self.typing_context.refresh()
60+
super().refresh()

numba_dpex/decorators.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@ def dpjit(*args, **kws):
166166
del kws["forceobj"]
167167
kws.update({"nopython": True})
168168
kws.update({"pipeline_class": OffloadCompiler})
169+
170+
# FIXME: When trying to use dpex's target context, overloads do not work
171+
# properly. We will turn on dpex target once the issue is fixed.
172+
173+
# kws.update({"_target": "dpex"})
174+
169175
return decorators.jit(*args, **kws)
170176

171177

0 commit comments

Comments
 (0)