Skip to content

Commit

Permalink
Merge pull request #1508 from IntelPython/service-improvements
Browse files Browse the repository at this point in the history
Service improvements
  • Loading branch information
oleksandr-pavlyk authored Jan 29, 2024
2 parents 86aaede + 6e30b84 commit 16a9c81
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 19 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ file(GLOB _cmake_scripts ${CMAKE_SOURCE_DIR}/cmake/*.cmake)
install(FILES ${_cmake_scripts}
DESTINATION dpctl/resources/cmake
)
install(FILES
${CMAKE_SOURCE_DIR}/cmake/dpctl-config.cmake
DESTINATION lib/cmake/dpctl
)

if (DPCTL_GENERATE_DOCS)
add_subdirectory(docs)
Expand Down
13 changes: 8 additions & 5 deletions cmake/FindDpctl.cmake → cmake/dpctl-config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
#
# ``Dpctl_FOUND``
# True if DPCTL was found.
# ``Dpctl_INCLUDE_DIRS``
# The include directories needed to use Dpctl.
# ``Dpctl_INCLUDE_DIR``
# The include directory needed to use dpctl.
# ``Dpctl_TENSOR_INCLUDE_DIR``
# The include directory for tensor kernels implementation.
# ``Dpctl_VERSION``
# The version of DPCTL found.
# The version of dpctl found.
#
# The module will also explicitly define one cache variable:
# The module will also explicitly define two cache variables:
#
# ``Dpctl_INCLUDE_DIR``
# ``Dpctl_TENSOR_INCLUDE_DIR``
#

if(NOT Dpctl_FOUND)
Expand All @@ -22,7 +25,7 @@ if(NOT Dpctl_FOUND)

if(Python_EXECUTABLE)
execute_process(COMMAND "${Python_EXECUTABLE}"
-c "import dpctl; print(dpctl.get_include())"
-m dpctl --include-dir
OUTPUT_VARIABLE _dpctl_include_dir
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
Expand Down
62 changes: 50 additions & 12 deletions dpctl/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,57 @@
# limitations under the License.

import argparse
import importlib
import os
import os.path
import platform
import sys
import warnings

import dpctl


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


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


def print_tensor_includes() -> None:
def print_include_flags() -> None:
"Prints include flags for dpctl and SyclInterface library"
print("-I " + get_include_dir())


def get_tensor_include_dir() -> str:
dpctl_dir = _dpctl_dir()
libtensor_dir = os.path.join(dpctl_dir, "tensor", "libtensor", "include")
return libtensor_dir


def print_tensor_include_flags() -> None:
"Prints include flags for dpctl and SyclInterface library"
libtensor_dir = get_tensor_include_dir()
print("-I " + libtensor_dir)


def print_cmake_dir() -> None:
"Prints directory with FindDpctl.cmake"
dpctl_dir = _dpctl_dir()
print(os.path.join(dpctl_dir, "resources", "cmake"))
cmake_dir = os.path.join(dpctl_dir, "resources", "cmake")
print(cmake_dir)


def get_library_dir() -> str:
dpctl_dir = _dpctl_dir()
return dpctl_dir


def print_library() -> None:
"Prints linker flags for SyclInterface library"
dpctl_dir = _dpctl_dir()
dpctl_dir = get_library_dir()
plt = platform.platform()
ld_flags = "-L " + dpctl_dir
if plt != "Windows":
Expand All @@ -73,6 +88,8 @@ def _warn_if_any_set(args, li) -> None:


def print_lsplatform(verbosity: int) -> None:
import dpctl

dpctl.lsplatform(verbosity=verbosity)


Expand All @@ -84,11 +101,21 @@ def main() -> None:
action="store_true",
help="Include flags for dpctl headers.",
)
parser.add_argument(
"--include-dir",
action="store_true",
help="Path to dpctl include directory.",
)
parser.add_argument(
"--tensor-includes",
action="store_true",
help="Include flags for dpctl libtensor headers.",
)
parser.add_argument(
"--tensor-include-dir",
action="store_true",
help="Path to dpctl libtensor include directory.",
)
parser.add_argument(
"--cmakedir",
action="store_true",
Expand All @@ -99,6 +126,11 @@ def main() -> None:
action="store_true",
help="Linker flags for SyclInterface library.",
)
parser.add_argument(
"--library-dir",
action="store_true",
help="Path to directory containing DPCTLSyclInterface library",
)
parser.add_argument(
"-f",
"--full-list",
Expand Down Expand Up @@ -139,13 +171,19 @@ def main() -> None:
print_lsplatform(0)
return
if args.includes:
print_includes()
print_include_flags()
if args.include_dir:
print(get_include_dir())
if args.tensor_includes:
print_tensor_includes()
print_tensor_include_flags()
if args.tensor_include_dir:
print(get_tensor_include_dir())
if args.cmakedir:
print_cmake_dir()
if args.library:
print_library()
if args.library_dir:
print(get_library_dir())


if __name__ == "__main__":
Expand Down
49 changes: 47 additions & 2 deletions dpctl/tests/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,30 @@ def test_syclinterface():
raise RuntimeError("Unsupported system")


def test_main_include_dir():
res = subprocess.run(
[sys.executable, "-m", "dpctl", "--include-dir"], capture_output=True
)
assert res.returncode == 0
assert res.stdout
dir_path = res.stdout.decode("utf-8").strip()
assert os.path.exists(dir_path)


def test_main_includes():
res = subprocess.run(
[sys.executable, "-m", "dpctl", "--includes"], capture_output=True
)
assert res.returncode == 0
assert res.stdout
assert res.stdout.decode("utf-8").startswith("-I")
flags = res.stdout.decode("utf-8")
res = subprocess.run(
[sys.executable, "-m", "dpctl", "--include-dir"], capture_output=True
)
assert res.returncode == 0
assert res.stdout
dir = res.stdout.decode("utf-8")
assert flags == "-I " + dir


def test_main_library():
Expand All @@ -191,14 +208,42 @@ def test_main_library():
assert res.stdout.decode("utf-8").startswith("-L")


def test_tensor_includes():
res = subprocess.run(
[sys.executable, "-m", "dpctl", "--tensor-includes"],
capture_output=True,
)
assert res.returncode == 0
assert res.stdout
flags = res.stdout.decode("utf-8")
res = subprocess.run(
[sys.executable, "-m", "dpctl", "--tensor-include-dir"],
capture_output=True,
)
assert res.returncode == 0
assert res.stdout
dir = res.stdout.decode("utf-8")
assert flags == "-I " + dir


def test_main_library_dir():
res = subprocess.run(
[sys.executable, "-m", "dpctl", "--library-dir"], capture_output=True
)
assert res.returncode == 0
assert res.stdout
dir_path = res.stdout.decode("utf-8").strip()
assert os.path.exists(dir_path)


def test_cmakedir():
res = subprocess.run(
[sys.executable, "-m", "dpctl", "--cmakedir"], capture_output=True
)
assert res.returncode == 0
assert res.stdout
cmake_dir = res.stdout.decode("utf-8").strip()
assert os.path.exists(os.path.join(cmake_dir, "FindDpctl.cmake"))
assert os.path.exists(os.path.join(cmake_dir, "dpctl-config.cmake"))


def test_main_full_list():
Expand Down

0 comments on commit 16a9c81

Please sign in to comment.