From 129bf7897cb1b6e1d275394b0bc19843aace9be2 Mon Sep 17 00:00:00 2001 From: Sergey Pokhodenko Date: Wed, 18 Nov 2020 16:02:36 +0300 Subject: [PATCH] Move variables from numba/core/config.py to numba_dppy/config.py Variables in module numba_dppy.config are renamed. They do not use `DPPY_` prefix: SAVE_DPPL_IR_FILES -> SAVE_IR_FILES Environament variables should have `NUMBA_DPPY_` prefix: NUMBA_SAVE_DPPL_IR_FILES -> NUMBA_DPPY_SAVE_IR_FILES NUMBA_SPIRV_VAL -> NUMBA_DPPY_SPIRV_VAL --- numba_dppy/config.py | 30 ++++++++++++++++++++++++++++++ numba_dppy/spirv_generator.py | 9 +++++---- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/numba_dppy/config.py b/numba_dppy/config.py index d1393daf0f..880d18d7b5 100644 --- a/numba_dppy/config.py +++ b/numba_dppy/config.py @@ -1,6 +1,36 @@ +import os + + try: import dpctl dppy_present = dpctl.has_sycl_platforms() and dpctl.has_gpu_queues() except: dppy_present = False + + +def _readenv(name, ctor, default): + """Original version from numba\core\config.py + class _EnvReloader(): + ... + def process_environ(): + def _readenv(): ... + """ + value = os.environ.get(name) + if value is None: + return default() if callable(default) else default + try: + return ctor(value) + except Exception: + warnings.warn( + "environ %s defined but failed to parse '%s'" % (name, value), + RuntimeWarning, + ) + return default + + +# Save intermediate files being generated by DPPY +SAVE_IR_FILES = _readenv("NUMBA_DPPY_SAVE_IR_FILES", int, 0) + +# Turn SPIRV-VALIDATION ON/OFF switch +SPIRV_VAL = _readenv("NUMBA_DPPY_SPIRV_VAL", int, 0) diff --git a/numba_dppy/spirv_generator.py b/numba_dppy/spirv_generator.py index cee4672ded..5bac98e014 100644 --- a/numba_dppy/spirv_generator.py +++ b/numba_dppy/spirv_generator.py @@ -7,6 +7,7 @@ import tempfile from numba import config +from numba_dppy import config as dppy_config from numba_dppy.target import LINK_ATOMIC @@ -61,7 +62,7 @@ def generate(self, ipath, opath): # b) hoist all allocas to the enty block of the module check_call(["opt","-O1","-o",ipath+'.bc',ipath]) check_call(["llvm-spirv","-o",opath,ipath+'.bc']) - if config.SAVE_DPPL_IR_FILES == 0: + if dppy_config.SAVE_IR_FILES == 0: os.unlink(ipath + '.bc') def link(self, opath, binaries): @@ -84,12 +85,12 @@ def __init__(self, context): def __del__(self): # Remove all temporary files for afile in self._tempfiles: - if config.SAVE_DPPL_IR_FILES != 0: + if dppy_config.SAVE_IR_FILES != 0: print(afile) else: os.unlink(afile) # Remove directory - if config.SAVE_DPPL_IR_FILES == 0: + if dppy_config.SAVE_IR_FILES == 0: os.rmdir(self._tmpdir) def _create_temp_file(self, name, mode='wb'): @@ -136,7 +137,7 @@ def finalize(self): self._cmd.link(spirv_path, binary_paths) # Validate the SPIR-V code - if config.SPIRV_VAL == 1: + if dppy_config.SPIRV_VAL == 1: try: self._cmd.validate(ipath=spirv_path) except CalledProcessError: