Skip to content

Commit b62ef67

Browse files
committed
Move search for compiler and omp from setup.py
1 parent 07bee6d commit b62ef67

File tree

2 files changed

+119
-21
lines changed

2 files changed

+119
-21
lines changed

setup.py

Lines changed: 3 additions & 21 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, IS_LIN, IS_WIN
5353

5454

5555
"""
@@ -96,18 +96,6 @@
9696
Operating System :: MacOS
9797
"""
9898

99-
IS_WIN = False
100-
IS_MAC = False
101-
IS_LIN = False
102-
103-
if 'linux' in sys.platform:
104-
IS_LIN = True
105-
elif sys.platform == 'darwin':
106-
IS_MAC = True
107-
elif sys.platform in ['win32', 'cygwin']:
108-
IS_WIN = True
109-
else:
110-
raise EnvironmentError("Intel NumPy: " + sys.platform + " not supported")
11199

112100
"""
113101
Set compiler for the project
@@ -218,18 +206,12 @@
218206
"""
219207
Get the compiler environemnt
220208
"""
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")
209+
_, _cmplr_libpath = find_cmplr(verbose=True)
210+
_, _omp_libpath = find_omp(verbose=True)
224211

225212
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')]
228213
_cmplr_rpath = _cmplr_libpath
229214
_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')]
233215

234216

235217
"""

utils/dpnp_build_utils.py

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,24 @@
2626
# *****************************************************************************
2727

2828
import os
29+
import sys
2930

3031

3132
IS_CONDA_BUILD = os.environ.get("CONDA_BUILD") == "1"
3233

34+
IS_WIN = False
35+
IS_MAC = False
36+
IS_LIN = False
37+
38+
if 'linux' in sys.platform:
39+
IS_LIN = True
40+
elif sys.platform == 'darwin':
41+
IS_MAC = True
42+
elif sys.platform in ['win32', 'cygwin']:
43+
IS_WIN = True
44+
else:
45+
raise EnvironmentError(f"Intel NumPy: {sys.platform} not supported")
46+
3347

3448
def find_library(var_name, rel_header_paths, rel_lib_paths,
3549
rel_include_path="include", rel_libdir_path="lib", verbose=False):
@@ -76,6 +90,57 @@ def find_library(var_name, rel_header_paths, rel_lib_paths,
7690
return [include_find], [libpath_find]
7791

7892

93+
def _find_cmplr_in_dpcpp_root(verbose=False):
94+
"""
95+
Find compiler in dpcpp root using $DPCPPROOT.
96+
97+
Parameters
98+
----------
99+
verbose : bool
100+
to print paths to include and library directories
101+
102+
Returns
103+
-------
104+
tuple(list(str), list(str))
105+
path to include directory, path to library directory
106+
"""
107+
rel_header_paths = rel_lib_paths = []
108+
109+
if IS_LIN:
110+
rel_include_path = os.path.join('linux', 'include')
111+
rel_libdir_path = os.path.join('linux', 'lib')
112+
elif IS_WIN:
113+
rel_include_path = os.path.join('windows', 'include')
114+
rel_libdir_path = os.path.join('windows', 'lib')
115+
else:
116+
rel_include_path, rel_libdir_path = 'include', 'lib'
117+
118+
return find_library("DPCPPROOT", rel_header_paths, rel_lib_paths,
119+
rel_include_path=rel_include_path, rel_libdir_path=rel_libdir_path, verbose=verbose)
120+
121+
122+
def find_cmplr(verbose=False):
123+
"""
124+
Find compiler in environment.
125+
126+
Parameters
127+
----------
128+
verbose : bool
129+
to print paths to include and library directories
130+
131+
Returns
132+
-------
133+
tuple(list(str), list(str))
134+
path to include directory, path to library directory
135+
"""
136+
cmplr_include, cmplr_libpath = _find_cmplr_in_dpcpp_root(verbose=verbose)
137+
138+
if not cmplr_include or not cmplr_libpath:
139+
raise EnvironmentError(f"Intel DPNP: Unable to find compiler. Please install Intel OneAPI environment")
140+
141+
return cmplr_include, cmplr_libpath
142+
143+
79144
def _find_mathlib_in_conda_root(verbose=False):
80145
"""
81146
Find mathlib in conda root using $CONDA_PREFIX or $PREFIX.
@@ -142,3 +207,54 @@ def find_mathlib(verbose=False):
142207
raise EnvironmentError("Intel DPNP: Unable to find math library")
143208

144209
return mathlib_include, mathlib_path
210+
211+
212+
def _find_omp_in_dpcpp_root(verbose=False):
213+
"""
214+
Find omp in dpcpp root using $DPCPPROOT.
215+
216+
Parameters
217+
----------
218+
verbose : bool
219+
to print paths to include and library directories
220+
221+
Returns
222+
-------
223+
tuple(list(str), list(str))
224+
path to include directory, path to library directory
225+
"""
226+
rel_header_paths = rel_lib_paths = []
227+
228+
if IS_LIN:
229+
rel_include_path = os.path.join('linux', 'compiler', 'include')
230+
rel_libdir_path = os.path.join('linux', 'compiler', 'lib', 'intel64')
231+
elif IS_WIN:
232+
rel_include_path = os.path.join('windows', 'compiler', 'include')
233+
rel_libdir_path = os.path.join('windows', 'compiler', 'lib', 'intel64_win')
234+
else:
235+
rel_include_path, rel_libdir_path = 'include', 'lib'
236+
237+
return find_library("DPCPPROOT", rel_header_paths, rel_lib_paths,
238+
rel_include_path=rel_include_path, rel_libdir_path=rel_libdir_path, verbose=verbose)
239+
240+
241+
def find_omp(verbose=False):
242+
"""
243+
Find omp in environment.
244+
245+
Parameters
246+
----------
247+
verbose : bool
248+
to print paths to include and library directories
249+
250+
Returns
251+
-------
252+
tuple(list(str), list(str))
253+
path to include directory, path to library directory
254+
"""
255+
omp_include, omp_libpath = _find_omp_in_dpcpp_root(verbose=verbose)
256+
257+
if not omp_include or not omp_libpath:
258+
raise EnvironmentError(f"Intel DPNP: Unable to find omp. Please install Intel OneAPI environment")
259+
260+
return omp_include, omp_libpath

0 commit comments

Comments
 (0)