Skip to content

Commit 16ed729

Browse files
Install cmake scripts (#853)
* aligned script with what's installed in oneAPI * steps to install *.cmake files in dpctl/resources/cmake * Added __main__ script, added dpctl/resources/cmake to gitignore Indended usage of the main module is ```bash python -m dpctl --includes # prints include flags for dpctl headers ``` ```bash python -m dpctl --cmakdir # prints directory to be used as DPCTL_ROOT \ # for cmake to find dpctl package ``` ```bash python -m dpctl --library # prints linker flags for linking \ # to SyclInterface library ``` * Added tests to check functionality of main script
2 parents 22eec72 + 6d62afb commit 16ed729

File tree

6 files changed

+125
-4
lines changed

6 files changed

+125
-4
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,6 @@ dpctl/_sycl_queue.h
9999
dpctl/_sycl_queue_manager.h
100100
dpctl/memory/_memory.h
101101
dpctl/tensor/_usmarray.h
102+
103+
# moved cmake scripts
104+
dpctl/resources/cmake

CMakeLists.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,19 @@ include(GNUInstallDirs)
3030
include(FetchContent)
3131

3232
FetchContent_Declare(
33-
pybind11
34-
URL https://github.com/pybind/pybind11/archive/refs/tags/v2.9.2.tar.gz
35-
URL_HASH SHA256=6bd528c4dbe2276635dc787b6b1f2e5316cf6b49ee3e150264e455a0d68d19c1
33+
pybind11
34+
URL https://github.com/pybind/pybind11/archive/refs/tags/v2.9.2.tar.gz
35+
URL_HASH SHA256=6bd528c4dbe2276635dc787b6b1f2e5316cf6b49ee3e150264e455a0d68d19c1
3636
)
3737
FetchContent_MakeAvailable(pybind11)
3838

3939
add_subdirectory(dpctl)
4040

41+
file(GLOB _cmake_scripts ${CMAKE_SOURCE_DIR}/cmake/*.cmake)
42+
install(FILES ${_cmake_scripts}
43+
DESTINATION dpctl/resources/cmake
44+
)
45+
4146
if (DPCTL_GENERATE_DOCS)
4247
add_subdirectory(docs)
4348
endif()

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
recursive-include dpctl/include *.h
22
include dpctl/include/dpctl4pybind11.hpp
33
recursive-include dpctl *.pxd
4+
recursive-include dpctl *.cmake
45
include dpctl/_sycl_context.h
56
include dpctl/_sycl_context_api.h
67
include dpctl/_sycl_device.h

cmake/IntelDPCPPConfig.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ if(WIN32)
240240
endif()
241241

242242
set(SYCL_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SYCL_FLAGS}")
243-
set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} ${SYCL_LINK_FLAGS}")
244243

245244
# And now test the assumptions.
246245

@@ -277,6 +276,7 @@ endif()
277276
set(SYCL_IMPLEMENTATION_ID "${CMAKE_CXX_COMPILER_ID}")
278277

279278
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SYCL_FLAGS}")
279+
set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} ${SYCL_LINK_FLAGS}")
280280

281281
message(STATUS "Echo from ${CMAKE_CURRENT_SOURCE_DIR}/IntelDPCPPConfig.cmake")
282282
message(STATUS "The SYCL compiler is ${SYCL_COMPILER}")

dpctl/__main__.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Data Parallel Control (dpctl)
2+
#
3+
# Copyright 2020-2021 Intel Corporation
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
import argparse
18+
import os
19+
import os.path
20+
import platform
21+
import sys
22+
23+
import dpctl
24+
25+
26+
def _dpctl_dir() -> str:
27+
abs_path = os.path.abspath(dpctl.__file__)
28+
dpctl_dir = os.path.dirname(abs_path)
29+
return dpctl_dir
30+
31+
32+
def print_includes() -> None:
33+
"Prints include flags for dpctl and SyclInterface library"
34+
print("-I " + dpctl.get_include())
35+
36+
37+
def print_cmake_dir() -> None:
38+
"Prints directory with FindDpctl.cmake"
39+
dpctl_dir = _dpctl_dir()
40+
print(os.path.join(dpctl_dir, "resources", "cmake"))
41+
42+
43+
def print_library() -> None:
44+
"Prints linker flags for SyclInterface library"
45+
dpctl_dir = _dpctl_dir()
46+
plt = platform.platform()
47+
ld_flags = "-L " + dpctl_dir
48+
if plt != "Windows":
49+
ld_flags = ld_flags + " -Wl,-rpath," + dpctl_dir
50+
print(ld_flags + " -lSyclInterface")
51+
52+
53+
def main() -> None:
54+
"""Main entry-point."""
55+
parser = argparse.ArgumentParser()
56+
parser.add_argument(
57+
"--includes",
58+
action="store_true",
59+
help="Include flags dpctl headers.",
60+
)
61+
parser.add_argument(
62+
"--cmakedir",
63+
action="store_true",
64+
help="CMake module directory, ideal for setting -DDPCTL_ROOT in CMake.",
65+
)
66+
parser.add_argument(
67+
"--library",
68+
action="store_true",
69+
help="Linker flags for SyclInterface library.",
70+
)
71+
args = parser.parse_args()
72+
if not sys.argv[1:]:
73+
parser.print_help()
74+
if args.includes:
75+
print_includes()
76+
if args.cmakedir:
77+
print_cmake_dir()
78+
if args.library:
79+
print_library()
80+
81+
82+
if __name__ == "__main__":
83+
main()

dpctl/tests/test_service.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import os
2424
import os.path
2525
import re
26+
import subprocess
2627
import sys
2728

2829
import pytest
@@ -153,3 +154,31 @@ def test_syclinterface():
153154
), "Installation does not have DPCTLSyclInterface.dll"
154155
else:
155156
raise RuntimeError("Unsupported system")
157+
158+
159+
def test_main_includes():
160+
res = subprocess.run(
161+
[sys.executable, "-m", "dpctl", "--includes"], capture_output=True
162+
)
163+
assert res.returncode == 0
164+
assert res.stdout
165+
assert res.stdout.decode("utf-8").startswith("-I")
166+
167+
168+
def test_main_library():
169+
res = subprocess.run(
170+
[sys.executable, "-m", "dpctl", "--library"], capture_output=True
171+
)
172+
assert res.returncode == 0
173+
assert res.stdout
174+
assert res.stdout.decode("utf-8").startswith("-L")
175+
176+
177+
def test_cmakedir():
178+
res = subprocess.run(
179+
[sys.executable, "-m", "dpctl", "--cmakedir"], capture_output=True
180+
)
181+
assert res.returncode == 0
182+
assert res.stdout
183+
cmake_dir = res.stdout.decode("utf-8").strip()
184+
assert os.path.exists(os.path.join(cmake_dir, "FindDpctl.cmake"))

0 commit comments

Comments
 (0)