Skip to content

Commit d0d3e07

Browse files
author
Diptorup Deb
authored
Merge pull request #1099 from chudur-budur/refac/config-for-docs
Refactor config.py (for docs)
2 parents 59bb27e + 3b52cf6 commit d0d3e07

30 files changed

+108
-87
lines changed

numba_dpex/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def parse_sem_version(version_string: str) -> Tuple[int, int, int]:
100100

101101
# Re-export types itself
102102
import numba_dpex.core.types as types # noqa E402
103-
from numba_dpex import config # noqa E402
103+
from numba_dpex.core import config # noqa E402
104104
from numba_dpex.core.kernel_interface.indexers import ( # noqa E402
105105
NdRange,
106106
Range,

numba_dpex/core/caching.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from numba.core.caching import CacheImpl, IndexDataCacheFile
99

10-
from numba_dpex import config
10+
from numba_dpex.core import config
1111

1212

1313
class _CacheImpl(CacheImpl):

numba_dpex/core/codegen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from numba.core import utils
1010
from numba.core.codegen import CPUCodegen, CPUCodeLibrary
1111

12-
from numba_dpex import config
12+
from numba_dpex.core import config
1313

1414
SPIR_TRIPLE = {32: " spir-unknown-unknown", 64: "spir64-unknown-unknown"}
1515

numba_dpex/core/compiler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from numba.core import types as numba_types
99
from numba.core.compiler_lock import global_compiler_lock
1010

11-
from numba_dpex import config
11+
from numba_dpex.core import config
1212
from numba_dpex.core.exceptions import (
1313
KernelHasReturnValueError,
1414
UnreachableError,

numba_dpex/config.py renamed to numba_dpex/core/config.py

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,44 @@
1010

1111

1212
def _readenv(name, ctor, default):
13-
"""Original version from numba/core/config.py
14-
class _EnvReloader():
15-
...
16-
def process_environ():
17-
def _readenv(): ...
13+
"""Read/write values from/into system environment variable list.
14+
15+
This function is used to read and write values from (and into) system `env`.
16+
This is adapted from `process_environ()` function of `_EnvLoader` class in
17+
`numba/core/config.py`.
18+
19+
Args:
20+
name (str): The name of the env variable.
21+
ctor (type): The type of the env variable.
22+
default (int,float,str): The default value of the env variable.
23+
24+
Returns:
25+
int,float,string: The environment variable value of the specified type.
1826
"""
27+
1928
value = os.environ.get(name)
2029
if value is None:
2130
return default() if callable(default) else default
2231
try:
2332
return ctor(value)
2433
except Exception:
2534
logging.exception(
26-
"environ %s defined but failed to parse '%s'" % (name, value)
35+
"env variable %s defined but failed to parse '%s'" % (name, value)
2736
)
2837
return default
2938

3039

3140
def __getattr__(name):
32-
"""Fallback to Numba config"""
41+
"""__getattr__ for numba_dpex's config module.
42+
43+
This will be used to fallback to numba's config.
44+
45+
Args:
46+
name (str): The name of the env variable.
47+
48+
Returns:
49+
int,float,str: The environment variable value from numba.
50+
"""
3351
return getattr(config, name)
3452

3553

@@ -44,6 +62,7 @@ def __getattr__(name):
4462

4563
# Emit debug info
4664
DEBUG = _readenv("NUMBA_DPEX_DEBUG", int, config.DEBUG)
65+
# The default value for the `debug` flag
4766
DEBUGINFO_DEFAULT = _readenv(
4867
"NUMBA_DPEX_DEBUGINFO", int, config.DEBUGINFO_DEFAULT
4968
)
@@ -58,21 +77,18 @@ def __getattr__(name):
5877
# a kernel decorated function
5978
DEBUG_KERNEL_LAUNCHER = _readenv("NUMBA_DPEX_DEBUG_KERNEL_LAUNCHER", int, 0)
6079

61-
# configs for caching
62-
# To see the debug messages for the caching.
63-
# Execute like:
64-
# NUMBA_DPEX_DEBUG_CACHE=1 python <code>
65-
DEBUG_CACHE = _readenv("NUMBA_DPEX_DEBUG_CACHE", int, 0)
66-
# This is a global flag to turn the caching on/off,
67-
# regardless of whatever has been specified in Dispatcher.
68-
# Useful for debugging. Execute like:
69-
# NUMBA_DPEX_ENABLE_CACHE=0 python <code>
70-
# to turn off the caching globally.
80+
# Flag to enable caching, set NUMBA_DPEX_ENABLE_CACHE=0 to turn it off.
7181
ENABLE_CACHE = _readenv("NUMBA_DPEX_ENABLE_CACHE", int, 1)
72-
# Capacity of the cache, execute it like:
73-
# NUMBA_DPEX_CACHE_SIZE=20 python <code>
74-
CACHE_SIZE = _readenv("NUMBA_DPEX_CACHE_SIZE", int, 128)
82+
# To specify the default cache size, 20 by default.
83+
CACHE_SIZE = _readenv("NUMBA_DPEX_CACHE_SIZE", int, 20)
84+
# Enable debugging of cahcing mechanism, set 1 to turn it on.
85+
DEBUG_CACHE = _readenv("NUMBA_DPEX_DEBUG_CACHE", int, 0)
86+
87+
# Flag to turn on the ConstantSizeStaticLocalMemoryPass in the kernel pipeline.
88+
# The pass is turned off by default.
89+
STATIC_LOCAL_MEM_PASS = _readenv("NUMBA_DPEX_STATIC_LOCAL_MEM_PASS", int, 0)
7590

91+
# Unused flags
7692
TESTING_SKIP_NO_DPNP = _readenv("NUMBA_DPEX_TESTING_SKIP_NO_DPNP", int, 0)
7793
TESTING_SKIP_NO_DEBUGGING = _readenv(
7894
"NUMBA_DPEX_TESTING_SKIP_NO_DEBUGGING", int, 1

numba_dpex/core/descriptor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from numba.core.cpu import CPUTargetOptions
99
from numba.core.descriptors import TargetDescriptor
1010

11-
from numba_dpex import config
11+
from numba_dpex.core import config
1212

1313
from .targets.dpjit_target import DPEX_TARGET_NAME, DpexTargetContext
1414
from .targets.kernel_target import (

numba_dpex/core/kernel_interface/dispatcher.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
from numba.core.types import Array as NpArrayType
1313
from numba.core.types import void
1414

15-
from numba_dpex import NdRange, Range, config
15+
from numba_dpex import NdRange, Range
16+
from numba_dpex.core import config
1617
from numba_dpex.core.caching import LRUCache, NullCache
1718
from numba_dpex.core.descriptor import dpex_kernel_target
1819
from numba_dpex.core.exceptions import (

numba_dpex/core/kernel_interface/func.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from numba.core import sigutils, types
66
from numba.core.typing.templates import AbstractTemplate, ConcreteTemplate
77

8-
from numba_dpex import config
8+
from numba_dpex.core import config
99
from numba_dpex.core.caching import LRUCache, NullCache
1010
from numba_dpex.core.compiler import compile_with_dpex
1111
from numba_dpex.core.descriptor import dpex_kernel_target

numba_dpex/core/kernel_interface/spirv_kernel.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77

88
from numba.core import ir
99

10-
from numba_dpex import config, spirv_generator
10+
from numba_dpex import spirv_generator
11+
from numba_dpex.core import config
1112
from numba_dpex.core.compiler import compile_with_dpex
1213
from numba_dpex.core.exceptions import UncompiledKernelError, UnreachableError
1314
from numba_dpex.core.targets.kernel_target import DpexKernelTargetContext

numba_dpex/core/parfors/kernel_builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from numba.parfors import parfor
2626

2727
import numba_dpex as dpex
28-
from numba_dpex import config
28+
from numba_dpex.core import config
2929

3030
from ..descriptor import dpex_kernel_target
3131
from ..types import DpnpNdArray, USMNdArray

0 commit comments

Comments
 (0)