diff --git a/.gitignore b/.gitignore index ae22979595..feb538de6b 100644 --- a/.gitignore +++ b/.gitignore @@ -99,3 +99,6 @@ dpctl/_sycl_queue.h dpctl/_sycl_queue_manager.h dpctl/memory/_memory.h dpctl/tensor/_usmarray.h + +# moved cmake scripts +dpctl/resources/cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 51959f2bc2..23ae1dd632 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,14 +30,19 @@ include(GNUInstallDirs) include(FetchContent) FetchContent_Declare( - pybind11 - URL https://github.com/pybind/pybind11/archive/refs/tags/v2.9.2.tar.gz - URL_HASH SHA256=6bd528c4dbe2276635dc787b6b1f2e5316cf6b49ee3e150264e455a0d68d19c1 + pybind11 + URL https://github.com/pybind/pybind11/archive/refs/tags/v2.9.2.tar.gz + URL_HASH SHA256=6bd528c4dbe2276635dc787b6b1f2e5316cf6b49ee3e150264e455a0d68d19c1 ) FetchContent_MakeAvailable(pybind11) add_subdirectory(dpctl) +file(GLOB _cmake_scripts ${CMAKE_SOURCE_DIR}/cmake/*.cmake) +install(FILES ${_cmake_scripts} + DESTINATION dpctl/resources/cmake +) + if (DPCTL_GENERATE_DOCS) add_subdirectory(docs) endif() diff --git a/MANIFEST.in b/MANIFEST.in index 9ace2ea6ab..7a1dcbf027 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,6 +1,7 @@ recursive-include dpctl/include *.h include dpctl/include/dpctl4pybind11.hpp recursive-include dpctl *.pxd +recursive-include dpctl *.cmake include dpctl/_sycl_context.h include dpctl/_sycl_context_api.h include dpctl/_sycl_device.h diff --git a/cmake/IntelDPCPPConfig.cmake b/cmake/IntelDPCPPConfig.cmake index cbdf9361a0..74714a4191 100644 --- a/cmake/IntelDPCPPConfig.cmake +++ b/cmake/IntelDPCPPConfig.cmake @@ -240,7 +240,6 @@ if(WIN32) endif() set(SYCL_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SYCL_FLAGS}") -set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} ${SYCL_LINK_FLAGS}") # And now test the assumptions. @@ -277,6 +276,7 @@ endif() set(SYCL_IMPLEMENTATION_ID "${CMAKE_CXX_COMPILER_ID}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SYCL_FLAGS}") +set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} ${SYCL_LINK_FLAGS}") message(STATUS "Echo from ${CMAKE_CURRENT_SOURCE_DIR}/IntelDPCPPConfig.cmake") message(STATUS "The SYCL compiler is ${SYCL_COMPILER}") diff --git a/dpctl/__main__.py b/dpctl/__main__.py new file mode 100644 index 0000000000..798ccc10c9 --- /dev/null +++ b/dpctl/__main__.py @@ -0,0 +1,83 @@ +# Data Parallel Control (dpctl) +# +# Copyright 2020-2021 Intel Corporation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import argparse +import os +import os.path +import platform +import sys + +import dpctl + + +def _dpctl_dir() -> str: + abs_path = os.path.abspath(dpctl.__file__) + dpctl_dir = os.path.dirname(abs_path) + return dpctl_dir + + +def print_includes() -> None: + "Prints include flags for dpctl and SyclInterface library" + print("-I " + dpctl.get_include()) + + +def print_cmake_dir() -> None: + "Prints directory with FindDpctl.cmake" + dpctl_dir = _dpctl_dir() + print(os.path.join(dpctl_dir, "resources", "cmake")) + + +def print_library() -> None: + "Prints linker flags for SyclInterface library" + dpctl_dir = _dpctl_dir() + plt = platform.platform() + ld_flags = "-L " + dpctl_dir + if plt != "Windows": + ld_flags = ld_flags + " -Wl,-rpath," + dpctl_dir + print(ld_flags + " -lSyclInterface") + + +def main() -> None: + """Main entry-point.""" + parser = argparse.ArgumentParser() + parser.add_argument( + "--includes", + action="store_true", + help="Include flags dpctl headers.", + ) + parser.add_argument( + "--cmakedir", + action="store_true", + help="CMake module directory, ideal for setting -DDPCTL_ROOT in CMake.", + ) + parser.add_argument( + "--library", + action="store_true", + help="Linker flags for SyclInterface library.", + ) + args = parser.parse_args() + if not sys.argv[1:]: + parser.print_help() + if args.includes: + print_includes() + if args.cmakedir: + print_cmake_dir() + if args.library: + print_library() + + +if __name__ == "__main__": + main() diff --git a/dpctl/tests/test_service.py b/dpctl/tests/test_service.py index aadf320704..351c4a2f13 100644 --- a/dpctl/tests/test_service.py +++ b/dpctl/tests/test_service.py @@ -23,6 +23,7 @@ import os import os.path import re +import subprocess import sys import pytest @@ -153,3 +154,31 @@ def test_syclinterface(): ), "Installation does not have DPCTLSyclInterface.dll" else: raise RuntimeError("Unsupported system") + + +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") + + +def test_main_library(): + res = subprocess.run( + [sys.executable, "-m", "dpctl", "--library"], capture_output=True + ) + assert res.returncode == 0 + assert res.stdout + assert res.stdout.decode("utf-8").startswith("-L") + + +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"))