Skip to content

Move variables from numba/core/config.py to numba_dppy/config.py #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions numba_dppy/config.py
Original file line number Diff line number Diff line change
@@ -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)
9 changes: 5 additions & 4 deletions numba_dppy/spirv_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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):
Expand All @@ -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'):
Expand Down Expand Up @@ -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:
Expand Down