Skip to content

Commit c918f38

Browse files
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 ```
1 parent d6f8df7 commit c918f38

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
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

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()

0 commit comments

Comments
 (0)