Skip to content

Commit 00a771e

Browse files
authored
Move config variables from numba to numba_dppy (#15)
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
1 parent f0d9ebd commit 00a771e

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

numba_dppy/config.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,36 @@
1+
import os
2+
3+
14
try:
25
import dpctl
36

47
dppy_present = dpctl.has_sycl_platforms() and dpctl.has_gpu_queues()
58
except:
69
dppy_present = False
10+
11+
12+
def _readenv(name, ctor, default):
13+
"""Original version from numba\core\config.py
14+
class _EnvReloader():
15+
...
16+
def process_environ():
17+
def _readenv(): ...
18+
"""
19+
value = os.environ.get(name)
20+
if value is None:
21+
return default() if callable(default) else default
22+
try:
23+
return ctor(value)
24+
except Exception:
25+
warnings.warn(
26+
"environ %s defined but failed to parse '%s'" % (name, value),
27+
RuntimeWarning,
28+
)
29+
return default
30+
31+
32+
# Save intermediate files being generated by DPPY
33+
SAVE_IR_FILES = _readenv("NUMBA_DPPY_SAVE_IR_FILES", int, 0)
34+
35+
# Turn SPIRV-VALIDATION ON/OFF switch
36+
SPIRV_VAL = _readenv("NUMBA_DPPY_SPIRV_VAL", int, 0)

numba_dppy/spirv_generator.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import tempfile
88

99
from numba import config
10+
from numba_dppy import config as dppy_config
1011
from numba_dppy.target import LINK_ATOMIC
1112

1213

@@ -61,7 +62,7 @@ def generate(self, ipath, opath):
6162
# b) hoist all allocas to the enty block of the module
6263
check_call(["opt","-O1","-o",ipath+'.bc',ipath])
6364
check_call(["llvm-spirv","-o",opath,ipath+'.bc'])
64-
if config.SAVE_DPPL_IR_FILES == 0:
65+
if dppy_config.SAVE_IR_FILES == 0:
6566
os.unlink(ipath + '.bc')
6667

6768
def link(self, opath, binaries):
@@ -84,12 +85,12 @@ def __init__(self, context):
8485
def __del__(self):
8586
# Remove all temporary files
8687
for afile in self._tempfiles:
87-
if config.SAVE_DPPL_IR_FILES != 0:
88+
if dppy_config.SAVE_IR_FILES != 0:
8889
print(afile)
8990
else:
9091
os.unlink(afile)
9192
# Remove directory
92-
if config.SAVE_DPPL_IR_FILES == 0:
93+
if dppy_config.SAVE_IR_FILES == 0:
9394
os.rmdir(self._tmpdir)
9495

9596
def _create_temp_file(self, name, mode='wb'):
@@ -136,7 +137,7 @@ def finalize(self):
136137
self._cmd.link(spirv_path, binary_paths)
137138

138139
# Validate the SPIR-V code
139-
if config.SPIRV_VAL == 1:
140+
if dppy_config.SPIRV_VAL == 1:
140141
try:
141142
self._cmd.validate(ipath=spirv_path)
142143
except CalledProcessError:

0 commit comments

Comments
 (0)