Skip to content

Commit

Permalink
Merge pull request #1099 from chudur-budur/refac/config-for-docs
Browse files Browse the repository at this point in the history
Refactor config.py (for docs)
  • Loading branch information
Diptorup Deb authored Jan 18, 2024
2 parents 59bb27e + 3b52cf6 commit d0d3e07
Show file tree
Hide file tree
Showing 30 changed files with 108 additions and 87 deletions.
2 changes: 1 addition & 1 deletion numba_dpex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def parse_sem_version(version_string: str) -> Tuple[int, int, int]:

# Re-export types itself
import numba_dpex.core.types as types # noqa E402
from numba_dpex import config # noqa E402
from numba_dpex.core import config # noqa E402
from numba_dpex.core.kernel_interface.indexers import ( # noqa E402
NdRange,
Range,
Expand Down
2 changes: 1 addition & 1 deletion numba_dpex/core/caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from numba.core.caching import CacheImpl, IndexDataCacheFile

from numba_dpex import config
from numba_dpex.core import config


class _CacheImpl(CacheImpl):
Expand Down
2 changes: 1 addition & 1 deletion numba_dpex/core/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from numba.core import utils
from numba.core.codegen import CPUCodegen, CPUCodeLibrary

from numba_dpex import config
from numba_dpex.core import config

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

Expand Down
2 changes: 1 addition & 1 deletion numba_dpex/core/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from numba.core import types as numba_types
from numba.core.compiler_lock import global_compiler_lock

from numba_dpex import config
from numba_dpex.core import config
from numba_dpex.core.exceptions import (
KernelHasReturnValueError,
UnreachableError,
Expand Down
56 changes: 36 additions & 20 deletions numba_dpex/config.py → numba_dpex/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,44 @@


def _readenv(name, ctor, default):
"""Original version from numba/core/config.py
class _EnvReloader():
...
def process_environ():
def _readenv(): ...
"""Read/write values from/into system environment variable list.
This function is used to read and write values from (and into) system `env`.
This is adapted from `process_environ()` function of `_EnvLoader` class in
`numba/core/config.py`.
Args:
name (str): The name of the env variable.
ctor (type): The type of the env variable.
default (int,float,str): The default value of the env variable.
Returns:
int,float,string: The environment variable value of the specified type.
"""

value = os.environ.get(name)
if value is None:
return default() if callable(default) else default
try:
return ctor(value)
except Exception:
logging.exception(
"environ %s defined but failed to parse '%s'" % (name, value)
"env variable %s defined but failed to parse '%s'" % (name, value)
)
return default


def __getattr__(name):
"""Fallback to Numba config"""
"""__getattr__ for numba_dpex's config module.
This will be used to fallback to numba's config.
Args:
name (str): The name of the env variable.
Returns:
int,float,str: The environment variable value from numba.
"""
return getattr(config, name)


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

# Emit debug info
DEBUG = _readenv("NUMBA_DPEX_DEBUG", int, config.DEBUG)
# The default value for the `debug` flag
DEBUGINFO_DEFAULT = _readenv(
"NUMBA_DPEX_DEBUGINFO", int, config.DEBUGINFO_DEFAULT
)
Expand All @@ -58,21 +77,18 @@ def __getattr__(name):
# a kernel decorated function
DEBUG_KERNEL_LAUNCHER = _readenv("NUMBA_DPEX_DEBUG_KERNEL_LAUNCHER", int, 0)

# configs for caching
# To see the debug messages for the caching.
# Execute like:
# NUMBA_DPEX_DEBUG_CACHE=1 python <code>
DEBUG_CACHE = _readenv("NUMBA_DPEX_DEBUG_CACHE", int, 0)
# This is a global flag to turn the caching on/off,
# regardless of whatever has been specified in Dispatcher.
# Useful for debugging. Execute like:
# NUMBA_DPEX_ENABLE_CACHE=0 python <code>
# to turn off the caching globally.
# Flag to enable caching, set NUMBA_DPEX_ENABLE_CACHE=0 to turn it off.
ENABLE_CACHE = _readenv("NUMBA_DPEX_ENABLE_CACHE", int, 1)
# Capacity of the cache, execute it like:
# NUMBA_DPEX_CACHE_SIZE=20 python <code>
CACHE_SIZE = _readenv("NUMBA_DPEX_CACHE_SIZE", int, 128)
# To specify the default cache size, 20 by default.
CACHE_SIZE = _readenv("NUMBA_DPEX_CACHE_SIZE", int, 20)
# Enable debugging of cahcing mechanism, set 1 to turn it on.
DEBUG_CACHE = _readenv("NUMBA_DPEX_DEBUG_CACHE", int, 0)

# Flag to turn on the ConstantSizeStaticLocalMemoryPass in the kernel pipeline.
# The pass is turned off by default.
STATIC_LOCAL_MEM_PASS = _readenv("NUMBA_DPEX_STATIC_LOCAL_MEM_PASS", int, 0)

# Unused flags
TESTING_SKIP_NO_DPNP = _readenv("NUMBA_DPEX_TESTING_SKIP_NO_DPNP", int, 0)
TESTING_SKIP_NO_DEBUGGING = _readenv(
"NUMBA_DPEX_TESTING_SKIP_NO_DEBUGGING", int, 1
Expand Down
2 changes: 1 addition & 1 deletion numba_dpex/core/descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from numba.core.cpu import CPUTargetOptions
from numba.core.descriptors import TargetDescriptor

from numba_dpex import config
from numba_dpex.core import config

from .targets.dpjit_target import DPEX_TARGET_NAME, DpexTargetContext
from .targets.kernel_target import (
Expand Down
3 changes: 2 additions & 1 deletion numba_dpex/core/kernel_interface/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
from numba.core.types import Array as NpArrayType
from numba.core.types import void

from numba_dpex import NdRange, Range, config
from numba_dpex import NdRange, Range
from numba_dpex.core import config
from numba_dpex.core.caching import LRUCache, NullCache
from numba_dpex.core.descriptor import dpex_kernel_target
from numba_dpex.core.exceptions import (
Expand Down
2 changes: 1 addition & 1 deletion numba_dpex/core/kernel_interface/func.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from numba.core import sigutils, types
from numba.core.typing.templates import AbstractTemplate, ConcreteTemplate

from numba_dpex import config
from numba_dpex.core import config
from numba_dpex.core.caching import LRUCache, NullCache
from numba_dpex.core.compiler import compile_with_dpex
from numba_dpex.core.descriptor import dpex_kernel_target
Expand Down
3 changes: 2 additions & 1 deletion numba_dpex/core/kernel_interface/spirv_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

from numba.core import ir

from numba_dpex import config, spirv_generator
from numba_dpex import spirv_generator
from numba_dpex.core import config
from numba_dpex.core.compiler import compile_with_dpex
from numba_dpex.core.exceptions import UncompiledKernelError, UnreachableError
from numba_dpex.core.targets.kernel_target import DpexKernelTargetContext
Expand Down
2 changes: 1 addition & 1 deletion numba_dpex/core/parfors/kernel_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from numba.parfors import parfor

import numba_dpex as dpex
from numba_dpex import config
from numba_dpex.core import config

from ..descriptor import dpex_kernel_target
from ..types import DpnpNdArray, USMNdArray
Expand Down
2 changes: 1 addition & 1 deletion numba_dpex/core/parfors/parfor_lowerer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
get_parfor_outputs,
)

from numba_dpex import config
from numba_dpex.core import config
from numba_dpex.core.datamodel.models import (
dpex_data_model_manager as kernel_dmm,
)
Expand Down
2 changes: 1 addition & 1 deletion numba_dpex/core/passes/passes.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from numba.core.ir_utils import remove_dels
from numba.core.typed_passes import NativeLowering

from numba_dpex import config
from numba_dpex.core import config


@register_pass(mutates_CFG=True, analysis_only=False)
Expand Down
2 changes: 1 addition & 1 deletion numba_dpex/core/pipelines/kernel_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
WithLifting,
)

from numba_dpex import config
from numba_dpex.core import config
from numba_dpex.core.exceptions import UnsupportedCompilationModeError
from numba_dpex.core.passes.passes import (
ConstantSizeStaticLocalMemoryPass,
Expand Down
2 changes: 1 addition & 1 deletion numba_dpex/core/types/usm_ndarray_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from numba.np.numpy_support import from_dtype

from numba_dpex.core.types.dpctl_types import DpctlSyclQueue
from numba_dpex.utils import address_space
from numba_dpex.utils.constants import address_space


class USMNdArray(Array):
Expand Down
2 changes: 1 addition & 1 deletion numba_dpex/core/typing/typeof.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from numba.extending import typeof_impl
from numba.np import numpy_support

from numba_dpex.utils import address_space
from numba_dpex.utils.constants import address_space

from ..kernel_interface.indexers import NdRange, Range
from ..types.dpctl_types import DpctlSyclEvent, DpctlSyclQueue
Expand Down
23 changes: 12 additions & 11 deletions numba_dpex/core/utils/kernel_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
from numba.core.datamodel import DataModelManager
from numba.core.types.containers import UniTuple

from numba_dpex import config, utils
from numba_dpex import utils
from numba_dpex.core import config
from numba_dpex.core.exceptions import UnreachableError
from numba_dpex.core.runtime.context import DpexRTContext
from numba_dpex.core.types import USMNdArray
Expand Down Expand Up @@ -165,7 +166,7 @@ def _build_array_attr_arg( # pylint: disable=too-many-arguments

self._build_arg(
val=array_attr,
ty=array_attr_ty,
typ=array_attr_ty,
arg_list=arg_list,
args_ty_list=args_ty_list,
arg_num=arg_num,
Expand Down Expand Up @@ -193,14 +194,14 @@ def _build_unituple_member_arg( # pylint: disable=too-many-arguments
)

def _build_arg(
self, val, ty, arg_list, args_ty_list, arg_num
self, val, typ, arg_list, args_ty_list, arg_num
): # pylint: disable=too-many-arguments
"""Stores the kernel arguments and the kernel argument types into
arrays that will be passed to DPCTLQueue_SubmitRange.
Args:
val: An LLVM IR Value that will be stored into the arguments array
ty: A Numba type that will be converted to a DPCTLKernelArgType
typ: A Numba type that will be converted to a DPCTLKernelArgType
enum and stored into the argument types list array
arg_list: An LLVM IR Value array that stores the kernel arguments
args_ty_list: An LLVM IR Value array that stores the
Expand All @@ -222,19 +223,19 @@ def _build_arg(
)
self.builder.store(val, kernel_arg_dst)
self.builder.store(
numba_type_to_dpctl_typenum(self.context, ty), kernel_arg_ty_dst
numba_type_to_dpctl_typenum(self.context, typ), kernel_arg_ty_dst
)

def _build_complex_arg(
self, val, ty, arg_list, args_ty_list, arg_num
self, val, typ, arg_list, args_ty_list, arg_num
): # pylint: disable=too-many-arguments
"""Creates a list of LLVM Values for an unpacked complex kernel
argument.
"""
self._build_array_attr_arg(
array_val=val,
array_attr_pos=0,
array_attr_ty=ty,
array_attr_ty=typ,
arg_list=arg_list,
args_ty_list=args_ty_list,
arg_num=arg_num,
Expand All @@ -243,7 +244,7 @@ def _build_complex_arg(
self._build_array_attr_arg(
array_val=val,
array_attr_pos=1,
array_attr_ty=ty,
array_attr_ty=typ,
arg_list=arg_list,
args_ty_list=args_ty_list,
arg_num=arg_num,
Expand All @@ -268,7 +269,7 @@ def _build_array_arg( # pylint: disable=too-many-arguments
nullptr = self._build_nullptr()
self._build_arg(
val=nullptr,
ty=types.int64,
typ=types.int64,
arg_list=arg_list,
args_ty_list=args_ty_list,
arg_num=arg_num,
Expand All @@ -278,7 +279,7 @@ def _build_array_arg( # pylint: disable=too-many-arguments
nullptr = self._build_nullptr()
self._build_arg(
val=nullptr,
ty=types.int64,
typ=types.int64,
arg_list=arg_list,
args_ty_list=args_ty_list,
arg_num=arg_num,
Expand Down Expand Up @@ -318,7 +319,7 @@ def _build_array_arg( # pylint: disable=too-many-arguments
# kernel we always pass in a nullptr
self._build_arg(
val=nullptr,
ty=types.int64,
typ=types.int64,
arg_list=arg_list,
args_ty_list=args_ty_list,
arg_num=arg_num,
Expand Down
5 changes: 2 additions & 3 deletions numba_dpex/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from numba.core import decorators, sigutils
from numba.core.target_extension import jit_registry, target_registry

from numba_dpex.core import config
from numba_dpex.core.kernel_interface.dispatcher import JitKernel
from numba_dpex.core.kernel_interface.func import (
compile_func,
Expand All @@ -16,8 +17,6 @@
from numba_dpex.core.pipelines.dpjit_compiler import get_compiler
from numba_dpex.core.targets.dpjit_target import DPEX_TARGET_NAME

from .config import USE_MLIR


def kernel(
func_or_sig=None,
Expand Down Expand Up @@ -156,7 +155,7 @@ def dpjit(*args, **kws):
)
del kws["pipeline_class"]

use_mlir = kws.pop("use_mlir", bool(USE_MLIR))
use_mlir = kws.pop("use_mlir", bool(config.USE_MLIR))

kws.update({"nopython": True})
kws.update({"parallel": True})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ def gen(context, builder, sig, args):
atomic_ref_dtype,
],
)
fn = cgutils.get_or_insert_function(
func = cgutils.get_or_insert_function(
builder.module,
llvmir.FunctionType(retty, spirv_fn_arg_types),
mangled_fn_name,
)
fn.calling_convention = CC_SPIR_FUNC
func.calling_convention = CC_SPIR_FUNC
spirv_memory_semantics_mask = get_memory_semantics_mask(
atomic_ref_ty.memory_order
)
Expand All @@ -112,7 +112,7 @@ def gen(context, builder, sig, args):
args[1],
]

builder.call(fn, fn_args)
builder.call(func, fn_args)

return sig, gen

Expand Down
Loading

0 comments on commit d0d3e07

Please sign in to comment.