Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install cmake scripts #853

Merged
merged 4 commits into from
Jun 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 8 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion cmake/IntelDPCPPConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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}")
Expand Down
83 changes: 83 additions & 0 deletions dpctl/__main__.py
Original file line number Diff line number Diff line change
@@ -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()
29 changes: 29 additions & 0 deletions dpctl/tests/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import os
import os.path
import re
import subprocess
import sys

import pytest
Expand Down Expand Up @@ -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"))