Skip to content
This repository was archived by the owner on Jan 25, 2023. It is now read-only.

Commit 3ab57d4

Browse files
committed
Added installation inside setup.py
1 parent adf27a9 commit 3ab57d4

6 files changed

Lines changed: 43 additions & 17 deletions

File tree

‎numba/dppy/dppy_driver/driverapi.py‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
from cffi import FFI
22
import os
33
import sys
4+
from distutils import sysconfig
45

56

67
ffibuilder = FFI()
78

89
libDPGlueHome = os.path.dirname(os.path.realpath(__file__))
10+
dpgluelib_dir = os.getcwd() + "/builds/numba/dppy/dppy_driver"
11+
dpgluelib = "dpglue" + sysconfig.get_config_var('EXT_SUFFIX')[:-3]
12+
print("====== ", dpgluelib_dir, " === ", dpgluelib)
913

1014
BAD_ENV_PATH_ERRMSG = """
1115
DP_GLUE_HOME is set to '{0}' which is not a valid path to a
1216
dynamic link library for your system.
1317
"""
1418

15-
1619
def _raise_bad_env_path(path, extra=None):
1720
error_message = BAD_ENV_PATH_ERRMSG.format(path)
1821
if extra is not None:
@@ -24,16 +27,16 @@ def _raise_bad_env_path(path, extra=None):
2427
# if libDPGlueHome is None:
2528
# raise ValueError("FATAL: Set the DP_GLUE_HOME for "
2629
# "dp_glue.h and libDPGlueHome.so")
27-
28-
30+
'''
2931
if libDPGlueHome is not None:
3032
try:
3133
os.path.abspath(libDPGlueHome)
3234
except ValueError:
3335
_raise_bad_env_path(libDPGlueHome)
3436
35-
if not os.path.isfile(libDPGlueHome + "/libdpglue.a"):
36-
_raise_bad_env_path(libDPGlueHome + "/libdpglue.a")
37+
if os.path.isfile(libDPGlueHome + "/libdpglue.so"):
38+
_raise_bad_env_path(libDPGlueHome + "/libdpglue.so")
39+
'''
3740

3841
glue_h = ''.join(list(filter(lambda x: len(x) > 0 and x[0] != "#",
3942
open(libDPGlueHome + '/dp_glue.h', 'r')
@@ -50,9 +53,10 @@ def _raise_bad_env_path(path, extra=None):
5053
"""
5154
#include "dp_glue.h" // the C header of the library
5255
""",
53-
libraries=["dpglue", "OpenCL"],
56+
libraries=[dpgluelib, "OpenCL"],
5457
include_dirs=[libDPGlueHome],
55-
library_dirs=[libDPGlueHome]
58+
library_dirs=[dpgluelib_dir],
59+
extra_link_args=["-Wl,-rpath=" + dpgluelib_dir]
5660
) # library name, for the linker
5761

5862

‎numba/dppy/dppy_driver/spirv_generator.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def _raise_bad_env_path(msg, path, extra=None):
1717
_real_check_call = check_call
1818

1919
def check_call(*args, **kwargs):
20-
print("check_call:", *args, **kwargs)
20+
#print("check_call:", *args, **kwargs)
2121
return _real_check_call(*args, **kwargs)
2222

2323
class CmdLine(object):

‎numba/dppy/initialize.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import absolute_import, print_function
22
import llvmlite.binding as ll
33
import os
4+
from distutils import sysconfig
45

56

67
def init_jit():
@@ -10,9 +11,9 @@ def init_jit():
1011
def initialize_all():
1112
from numba.targets.registry import dispatcher_registry
1213
dispatcher_registry.ondemand['dppy'] = init_jit
13-
dir_path = (os.path.dirname(os.path.realpath(__file__)) +
14-
"/dppy_driver/libdpglue_so.so")
15-
ll.load_library_permanently(dir_path)
14+
dir_path = os.path.dirname(os.path.realpath(__file__)) + "/dppy_driver"
15+
dpgluelib = dir_path + "/libdpglue" + sysconfig.get_config_var('EXT_SUFFIX')
16+
ll.load_library_permanently(dpgluelib)
1617
ll.load_library_permanently('libOpenCL.so')
1718

1819
def _initialize_ufunc():

‎numba/dppy/target.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def load_additional_registries(self):
5151

5252
class GenericPointerModel(datamodel.PrimitiveModel):
5353
def __init__(self, dmm, fe_type):
54-
print("GenericPointerModel:", dmm, fe_type, fe_type.addrspace)
54+
#print("GenericPointerModel:", dmm, fe_type, fe_type.addrspace)
5555
adrsp = fe_type.addrspace if fe_type.addrspace is not None else SPIR_GENERIC_ADDRSPACE
5656
be_type = dmm.lookup(fe_type.dtype).get_data_type().as_pointer(adrsp)
5757
super(GenericPointerModel, self).__init__(dmm, fe_type, be_type)

‎numba/targets/base.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,9 @@ def get_external_function_type(self, fndesc):
426426
return fnty
427427

428428
def declare_function(self, module, fndesc):
429-
print("base.py: declare_function", module, "\n\targs:", fndesc.args, "\n\trestype:", fndesc.restype, "\n\targtypes:", fndesc.argtypes, fndesc.mangled_name, fndesc.noalias)
429+
#print("base.py: declare_function", module, "\n\targs:", fndesc.args, "\n\trestype:", fndesc.restype, "\n\targtypes:", fndesc.argtypes, fndesc.mangled_name, fndesc.noalias)
430430
fnty = self.call_conv.get_function_type(fndesc.restype, fndesc.argtypes)
431-
print("fnty:", fnty)
431+
#print("fnty:", fnty)
432432
fn = module.get_or_insert_function(fnty, name=fndesc.mangled_name)
433433
self.call_conv.decorate_function(fn, fndesc.args, fndesc.argtypes, noalias=fndesc.noalias)
434434
if fndesc.inline:

‎setup.py‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ def run(self):
3939
cmdclass = versioneer.get_cmdclass()
4040
cmdclass['build_doc'] = build_doc
4141

42-
4342
GCCFLAGS = ["-std=c89", "-Wdeclaration-after-statement", "-Werror"]
4443

4544
if os.environ.get("NUMBA_GCC_FLAGS"):
@@ -152,6 +151,7 @@ def get_ext_modules():
152151
**np_compile_args)
153152

154153
ext_npyufunc_workqueue_impls = []
154+
ext_dppy_impls = []
155155

156156
def check_file_at_path(path2file):
157157
"""
@@ -188,8 +188,8 @@ def check_file_at_path(path2file):
188188
tbb_root = check_file_at_path(['include', 'tbb', 'tbb.h'])
189189

190190
# Set various flags for use in TBB and openmp. On OSX, also find OpenMP!
191-
have_openmp = False
192-
tbb_root = None
191+
have_openmp = True
192+
opeclliteflags = list()
193193
if sys.platform.startswith('win'):
194194
cpp11flags = []
195195
ompcompileflags = ['-openmp']
@@ -209,6 +209,7 @@ def check_file_at_path(path2file):
209209
else:
210210
cpp11flags = ['-std=c++11']
211211
ompcompileflags = ['-fopenmp']
212+
openclliteflags = ['-Wall', '-Wextra', '-Winit-self', '-Wuninitialized', '-Wmissing-declarations', '-std=c99', '-fdiagnostics-color=auto', '-shared', '-fPIC']
212213
if platform.machine() == 'ppc64le':
213214
omplinkflags = ['-fopenmp']
214215
else:
@@ -239,6 +240,25 @@ def check_file_at_path(path2file):
239240
else:
240241
print("TBB not found")
241242

243+
# Search for OpenCL, first check env var OPENCLROOT then conda locations
244+
opencl_root = os.getenv('OPENCLROOT')
245+
if not opencl_root:
246+
#opencl_root = check_file_at_path(['include', 'opencl', 'cl.h', "CL.h"])
247+
opencl_root = "/usr"
248+
249+
print("Building opencllite")
250+
ext_dppy = Extension(
251+
name='numba.dppy.dppy_driver.libdpglue',
252+
sources=[
253+
'numba/dppy/dppy_driver/opencllite.c'
254+
],
255+
depends=['numba/dppy/dppy_driver/dp_glue.h'],
256+
include_dirs=[os.path.join(opencl_root, 'include')],
257+
extra_compile_args=openclliteflags,
258+
)
259+
ext_dppy_impls.append(ext_dppy)
260+
261+
242262
# Disable OpenMP if we are building a wheel or
243263
# forced by user with NUMBA_NO_OPENMP=1
244264
if is_building_wheel() or os.getenv('NUMBA_NO_OPENMP'):
@@ -297,6 +317,7 @@ def check_file_at_path(path2file):
297317
ext_jitclass_box, ext_cuda_extras]
298318

299319
ext_modules += ext_npyufunc_workqueue_impls
320+
ext_modules += ext_dppy_impls
300321

301322
return ext_modules
302323

0 commit comments

Comments
 (0)