Skip to content

Commit 6d2aaaf

Browse files
authored
Move search for compiler and omp from setup.py (#146)
* Move search for compiler and omp from setup.py
1 parent c89d58f commit 6d2aaaf

File tree

2 files changed

+106
-9
lines changed

2 files changed

+106
-9
lines changed

setup.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
from utils.command_style import source_style
5050
from utils.command_clean import source_clean
5151
from utils.command_build_clib import custom_build_clib
52-
from utils.dpnp_build_utils import find_mathlib
52+
from utils.dpnp_build_utils import find_cmplr, find_mathlib, find_omp
5353

5454

5555
"""
@@ -218,18 +218,12 @@
218218
"""
219219
Get the compiler environemnt
220220
"""
221-
_cmplr_root = os.environ.get('DPCPPROOT', None)
222-
if _cmplr_root is None:
223-
raise EnvironmentError("Please install Intel OneAPI environment. DPCPPROOT is empty")
221+
_, _cmplr_libpath = find_cmplr(verbose=True)
222+
_, _omp_libpath = find_omp(verbose=True)
224223

225224
if IS_LIN:
226-
_cmplr_libpath = [os.path.join(_cmplr_root, 'linux', 'lib')]
227-
_omp_libpath = [os.path.join(_cmplr_root, 'linux', 'compiler', 'lib', 'intel64')]
228225
_cmplr_rpath = _cmplr_libpath
229226
_omp_rpath = _omp_libpath
230-
elif IS_WIN:
231-
_cmplr_libpath = [os.path.join(_cmplr_root, 'windows', 'lib')]
232-
_omp_libpath = [os.path.join(_cmplr_root, 'windows', 'compiler', 'lib', 'intel64_win')]
233227

234228

235229
"""

utils/dpnp_build_utils.py

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
# *****************************************************************************
2727

2828
import os
29+
import sys
2930

3031

3132
IS_CONDA_BUILD = os.environ.get("CONDA_BUILD") == "1"
@@ -76,6 +77,57 @@ def find_library(var_name, rel_header_paths, rel_lib_paths,
7677
return [include_find], [libpath_find]
7778

7879

80+
def _find_cmplr_in_dpcpp_root(verbose=False):
81+
"""
82+
Find compiler in dpcpp root using $DPCPPROOT.
83+
84+
Parameters
85+
----------
86+
verbose : bool
87+
to print paths to include and library directories
88+
89+
Returns
90+
-------
91+
tuple(list(str), list(str))
92+
path to include directory, path to library directory
93+
"""
94+
rel_header_paths = rel_lib_paths = []
95+
96+
if 'linux' in sys.platform:
97+
rel_include_path = os.path.join('linux', 'include')
98+
rel_libdir_path = os.path.join('linux', 'lib')
99+
elif sys.platform in ['win32', 'cygwin']:
100+
rel_include_path = os.path.join('windows', 'include')
101+
rel_libdir_path = os.path.join('windows', 'lib')
102+
else:
103+
rel_include_path, rel_libdir_path = 'include', 'lib'
104+
105+
return find_library("DPCPPROOT", rel_header_paths, rel_lib_paths,
106+
rel_include_path=rel_include_path, rel_libdir_path=rel_libdir_path, verbose=verbose)
107+
108+
109+
def find_cmplr(verbose=False):
110+
"""
111+
Find compiler in environment.
112+
113+
Parameters
114+
----------
115+
verbose : bool
116+
to print paths to include and library directories
117+
118+
Returns
119+
-------
120+
tuple(list(str), list(str))
121+
path to include directory, path to library directory
122+
"""
123+
cmplr_include, cmplr_libpath = _find_cmplr_in_dpcpp_root(verbose=verbose)
124+
125+
if not cmplr_include or not cmplr_libpath:
126+
raise EnvironmentError(f"Intel DPNP: Unable to find compiler. Please install Intel OneAPI environment")
127+
128+
return cmplr_include, cmplr_libpath
129+
130+
79131
def _find_mathlib_in_conda_root(verbose=False):
80132
"""
81133
Find mathlib in conda root using $CONDA_PREFIX or $PREFIX.
@@ -142,3 +194,54 @@ def find_mathlib(verbose=False):
142194
raise EnvironmentError("Intel DPNP: Unable to find math library")
143195

144196
return mathlib_include, mathlib_path
197+
198+
199+
def _find_omp_in_dpcpp_root(verbose=False):
200+
"""
201+
Find omp in dpcpp root using $DPCPPROOT.
202+
203+
Parameters
204+
----------
205+
verbose : bool
206+
to print paths to include and library directories
207+
208+
Returns
209+
-------
210+
tuple(list(str), list(str))
211+
path to include directory, path to library directory
212+
"""
213+
rel_header_paths = rel_lib_paths = []
214+
215+
if 'linux' in sys.platform:
216+
rel_include_path = os.path.join('linux', 'compiler', 'include')
217+
rel_libdir_path = os.path.join('linux', 'compiler', 'lib', 'intel64')
218+
elif sys.platform in ['win32', 'cygwin']:
219+
rel_include_path = os.path.join('windows', 'compiler', 'include')
220+
rel_libdir_path = os.path.join('windows', 'compiler', 'lib', 'intel64_win')
221+
else:
222+
rel_include_path, rel_libdir_path = 'include', 'lib'
223+
224+
return find_library("DPCPPROOT", rel_header_paths, rel_lib_paths,
225+
rel_include_path=rel_include_path, rel_libdir_path=rel_libdir_path, verbose=verbose)
226+
227+
228+
def find_omp(verbose=False):
229+
"""
230+
Find omp in environment.
231+
232+
Parameters
233+
----------
234+
verbose : bool
235+
to print paths to include and library directories
236+
237+
Returns
238+
-------
239+
tuple(list(str), list(str))
240+
path to include directory, path to library directory
241+
"""
242+
omp_include, omp_libpath = _find_omp_in_dpcpp_root(verbose=verbose)
243+
244+
if not omp_include or not omp_libpath:
245+
raise EnvironmentError(f"Intel DPNP: Unable to find omp. Please install Intel OneAPI environment")
246+
247+
return omp_include, omp_libpath

0 commit comments

Comments
 (0)