Skip to content

Commit 1d4248c

Browse files
author
Diptorup Deb
committed
An experimental target for features under developments.
1 parent fe619d0 commit 1d4248c

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

numba_dpex/experimental/target.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# SPDX-FileCopyrightText: 2023 Intel Corporation
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
"""A new target descriptor that includes experimental features that should
6+
eventually move into the numba_dpex.core.
7+
"""
8+
9+
from functools import cached_property
10+
11+
from numba.core.descriptors import TargetDescriptor
12+
13+
from numba_dpex.core.descriptor import DpexTargetOptions
14+
from numba_dpex.core.targets.kernel_target import (
15+
DPEX_KERNEL_TARGET_NAME,
16+
DpexKernelTargetContext,
17+
DpexKernelTypingContext,
18+
)
19+
20+
21+
class DpexExpKernelTypingContext(DpexKernelTypingContext):
22+
"""Experimental typing context class extending the DpexKernelTypingContext
23+
by overriding super class functions for new experimental types.
24+
25+
A new experimental type may require updating type inference for that type
26+
when it is used as an argument, value or attribute in a JIT compiled
27+
function. All such experimental functionality should be added here till they
28+
are stable enough to be migrated to DpexKernelTypingContext.
29+
"""
30+
31+
32+
# pylint: disable=W0223
33+
# FIXME: Remove the pylint disablement once we add an override for
34+
# get_executable
35+
class DpexExpKernelTargetContext(DpexKernelTargetContext):
36+
"""Experimental target context class extending the DpexKernelTargetContext
37+
by overriding super class functions for new experimental types.
38+
39+
A new experimental type may require specific ways for handling the lowering
40+
to LLVM IR. All such experimental functionality should be added here till
41+
they are stable enough to be migrated to DpexKernelTargetContext.
42+
"""
43+
44+
45+
class DpexExpKernelTarget(TargetDescriptor):
46+
"""
47+
Implements a target descriptor for numba_dpex.kernel decorated functions.
48+
"""
49+
50+
options = DpexTargetOptions
51+
52+
@cached_property
53+
def _toplevel_target_context(self):
54+
"""Lazily-initialized top-level target context, for all threads."""
55+
return DpexExpKernelTargetContext(
56+
self.typing_context, self._target_name
57+
)
58+
59+
@cached_property
60+
def _toplevel_typing_context(self):
61+
"""Lazily-initialized top-level typing context, for all threads."""
62+
return DpexExpKernelTypingContext()
63+
64+
@property
65+
def target_context(self):
66+
"""
67+
The target context used by the Dpex compiler pipeline.
68+
"""
69+
return self._toplevel_target_context
70+
71+
@property
72+
def typing_context(self):
73+
"""
74+
The typing context for used by the Dpex compiler pipeline.
75+
"""
76+
return self._toplevel_typing_context
77+
78+
79+
# A global instance of the DpexKernelTarget with the experimental features
80+
dpex_exp_kernel_target = DpexExpKernelTarget(DPEX_KERNEL_TARGET_NAME)

0 commit comments

Comments
 (0)