Skip to content

Commit cad6886

Browse files
dpctl/__main__.py no longer triggers loading of libsycl library for queries
`python -m dpctl --includes` will no longer load SYCL runtime libraries. Module file acquired three more options --include-dir --tensor-include-dir --library-dir This would output absolute path to directory of include headers, tensor include hedaers, and directory containing DPCTLSyclInterface library. `FindDpctl.cmake` has been renamed to `dpctl-config.cmake`. This allows downstream objects to hint CMake to finding Dpctl package by using standard mechanism: `-DDpctl_ROOT=$(python -m dpctl --cmakedir)`
1 parent 8f82fe1 commit cad6886

File tree

3 files changed

+97
-14
lines changed

3 files changed

+97
-14
lines changed

cmake/FindDpctl.cmake renamed to cmake/dpctl-config.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ if(NOT Dpctl_FOUND)
2222

2323
if(Python_EXECUTABLE)
2424
execute_process(COMMAND "${Python_EXECUTABLE}"
25-
-c "import dpctl; print(dpctl.get_include())"
25+
-m dpctl --include-dir
2626
OUTPUT_VARIABLE _dpctl_include_dir
2727
OUTPUT_STRIP_TRAILING_WHITESPACE
2828
ERROR_QUIET

dpctl/__main__.py

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,42 +15,57 @@
1515
# limitations under the License.
1616

1717
import argparse
18+
import importlib
1819
import os
1920
import os.path
2021
import platform
2122
import sys
2223
import warnings
2324

24-
import dpctl
25-
2625

2726
def _dpctl_dir() -> str:
28-
abs_path = os.path.abspath(dpctl.__file__)
29-
dpctl_dir = os.path.dirname(abs_path)
30-
return dpctl_dir
27+
dpctl_dir = importlib.util.find_spec("dpctl").submodule_search_locations[0]
28+
abs_dpctl_dir = os.path.abspath(dpctl_dir)
29+
return abs_dpctl_dir
3130

3231

33-
def print_includes() -> None:
32+
def get_include_dir() -> str:
3433
"Prints include flags for dpctl and SyclInterface library"
35-
print("-I " + dpctl.get_include())
34+
return os.path.join(_dpctl_dir(), "include")
3635

3736

38-
def print_tensor_includes() -> None:
37+
def print_include_flags() -> None:
3938
"Prints include flags for dpctl and SyclInterface library"
39+
print("-I " + get_include_dir())
40+
41+
42+
def get_tensor_include_dir() -> str:
4043
dpctl_dir = _dpctl_dir()
4144
libtensor_dir = os.path.join(dpctl_dir, "tensor", "libtensor", "include")
45+
return libtensor_dir
46+
47+
48+
def print_tensor_include_flags() -> None:
49+
"Prints include flags for dpctl and SyclInterface library"
50+
libtensor_dir = get_tensor_include_dir()
4251
print("-I " + libtensor_dir)
4352

4453

4554
def print_cmake_dir() -> None:
4655
"Prints directory with FindDpctl.cmake"
4756
dpctl_dir = _dpctl_dir()
48-
print(os.path.join(dpctl_dir, "resources", "cmake"))
57+
cmake_dir = os.path.join(dpctl_dir, "resources", "cmake")
58+
print(cmake_dir)
59+
60+
61+
def get_library_dir() -> str:
62+
dpctl_dir = _dpctl_dir()
63+
return dpctl_dir
4964

5065

5166
def print_library() -> None:
5267
"Prints linker flags for SyclInterface library"
53-
dpctl_dir = _dpctl_dir()
68+
dpctl_dir = get_library_dir()
5469
plt = platform.platform()
5570
ld_flags = "-L " + dpctl_dir
5671
if plt != "Windows":
@@ -73,6 +88,8 @@ def _warn_if_any_set(args, li) -> None:
7388

7489

7590
def print_lsplatform(verbosity: int) -> None:
91+
import dpctl
92+
7693
dpctl.lsplatform(verbosity=verbosity)
7794

7895

@@ -84,11 +101,21 @@ def main() -> None:
84101
action="store_true",
85102
help="Include flags for dpctl headers.",
86103
)
104+
parser.add_argument(
105+
"--include-dir",
106+
action="store_true",
107+
help="Path to dpctl include directory.",
108+
)
87109
parser.add_argument(
88110
"--tensor-includes",
89111
action="store_true",
90112
help="Include flags for dpctl libtensor headers.",
91113
)
114+
parser.add_argument(
115+
"--tensor-include-dir",
116+
action="store_true",
117+
help="Path to dpctl libtensor include directory.",
118+
)
92119
parser.add_argument(
93120
"--cmakedir",
94121
action="store_true",
@@ -99,6 +126,11 @@ def main() -> None:
99126
action="store_true",
100127
help="Linker flags for SyclInterface library.",
101128
)
129+
parser.add_argument(
130+
"--library-dir",
131+
action="store_true",
132+
help="Path to directory containing DPCTLSyclInterface library",
133+
)
102134
parser.add_argument(
103135
"-f",
104136
"--full-list",
@@ -139,13 +171,19 @@ def main() -> None:
139171
print_lsplatform(0)
140172
return
141173
if args.includes:
142-
print_includes()
174+
print_include_flags()
175+
if args.include_dir:
176+
print(get_include_dir())
143177
if args.tensor_includes:
144-
print_tensor_includes()
178+
print_tensor_include_flags()
179+
if args.tensor_include_dir:
180+
print(get_tensor_include_dir())
145181
if args.cmakedir:
146182
print_cmake_dir()
147183
if args.library:
148184
print_library()
185+
if args.library_dir:
186+
print(get_library_dir())
149187

150188

151189
if __name__ == "__main__":

dpctl/tests/test_service.py

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,30 @@ def test_syclinterface():
173173
raise RuntimeError("Unsupported system")
174174

175175

176+
def test_main_include_dir():
177+
res = subprocess.run(
178+
[sys.executable, "-m", "dpctl", "--include-dir"], capture_output=True
179+
)
180+
assert res.returncode == 0
181+
assert res.stdout
182+
dir_path = res.stdout.decode("utf-8").strip()
183+
assert os.path.exists(dir_path)
184+
185+
176186
def test_main_includes():
177187
res = subprocess.run(
178188
[sys.executable, "-m", "dpctl", "--includes"], capture_output=True
179189
)
180190
assert res.returncode == 0
181191
assert res.stdout
182-
assert res.stdout.decode("utf-8").startswith("-I")
192+
flags = res.stdout.decode("utf-8")
193+
res = subprocess.run(
194+
[sys.executable, "-m", "dpctl", "--include-dir"], capture_output=True
195+
)
196+
assert res.returncode == 0
197+
assert res.stdout
198+
dir = res.stdout.decode("utf-8")
199+
assert flags == "-I " + dir
183200

184201

185202
def test_main_library():
@@ -191,6 +208,34 @@ def test_main_library():
191208
assert res.stdout.decode("utf-8").startswith("-L")
192209

193210

211+
def test_tensor_includes():
212+
res = subprocess.run(
213+
[sys.executable, "-m", "dpctl", "--tensor-includes"],
214+
capture_output=True,
215+
)
216+
assert res.returncode == 0
217+
assert res.stdout
218+
flags = res.stdout.decode("utf-8")
219+
res = subprocess.run(
220+
[sys.executable, "-m", "dpctl", "--tensor-include-dir"],
221+
capture_output=True,
222+
)
223+
assert res.returncode == 0
224+
assert res.stdout
225+
dir = res.stdout.decode("utf-8")
226+
assert flags == "-I " + dir
227+
228+
229+
def test_main_library_dir():
230+
res = subprocess.run(
231+
[sys.executable, "-m", "dpctl", "--library-dir"], capture_output=True
232+
)
233+
assert res.returncode == 0
234+
assert res.stdout
235+
dir_path = res.stdout.decode("utf-8").strip()
236+
assert os.path.exists(dir_path)
237+
238+
194239
def test_cmakedir():
195240
res = subprocess.run(
196241
[sys.executable, "-m", "dpctl", "--cmakedir"], capture_output=True

0 commit comments

Comments
 (0)