Repository navigation
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
174 lines (147 loc) · 5.57 KB
/
Copy pathCMakeLists.txt
File metadata and controls
174 lines (147 loc) · 5.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
cmake_minimum_required(VERSION 3.21...3.27 FATAL_ERROR)
project(dpctl
VERSION 0.23
LANGUAGES CXX
DESCRIPTION "Python interface for XPU programming"
)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
# set_property(GLOBAL PROPERTY GLOBAL_DEPENDS_DEBUG_MODE 1)
if (UNIX)
add_link_options("-fuse-ld=lld")
endif()
# Option to generate code coverage report using llvm-cov and lcov.
option(DPCTL_GENERATE_COVERAGE
"Build dpctl with coverage instrumentation"
OFF
)
option(DPCTL_GENERATE_COVERAGE_FOR_PYBIND11_EXTENSIONS
"Build dpctl pybind11 offloading extensions with coverage instrumentation"
OFF
)
# SYCL provider selection
set(DPCTL_SYCL_PROVIDER "Intel" CACHE STRING "SYCL compiler provider (Intel or AdaptiveCpp)")
set_property(CACHE DPCTL_SYCL_PROVIDER PROPERTY STRINGS Intel AdaptiveCpp)
set(DPCTL_TARGET_CUDA
""
CACHE STRING
"Build DPCTL to target CUDA device. \
Set to a truthy value (e.g., ON, TRUE) to use default architecture (sm_50), \
or to a specific architecture like sm_80."
)
set(DPCTL_TARGET_HIP
""
CACHE STRING
"Build DPCTL to target a HIP device architecture"
)
# architecture mapping
set(_dpctl_sycl_targets)
set(_dpctl_cuda_arch)
set(_acpp_targets_list) # Used strictly for AdaptiveCpp
if ("x${DPCTL_SYCL_TARGETS}" STREQUAL "x")
if (DPCTL_TARGET_CUDA)
if(DPCTL_TARGET_CUDA MATCHES "^sm_")
set(_dpctl_cuda_arch ${DPCTL_TARGET_CUDA})
elseif(DPCTL_TARGET_CUDA MATCHES "^(ON|TRUE|YES|Y|1)$")
set(_dpctl_cuda_arch "sm_50")
else()
message(FATAL_ERROR
"Invalid value for DPCTL_TARGET_CUDA: \"${DPCTL_TARGET_CUDA}\". "
"Expected 'ON', 'TRUE', 'YES', 'Y', '1', or a CUDA architecture like 'sm_80'."
)
endif()
# Map to Provider Formats
if(DPCTL_SYCL_PROVIDER STREQUAL "Intel")
set(_dpctl_sycl_targets "nvidia_gpu_${_dpctl_cuda_arch},spir64-unknown-unknown")
elseif(DPCTL_SYCL_PROVIDER STREQUAL "AdaptiveCpp")
list(APPEND _acpp_targets_list "cuda:${_dpctl_cuda_arch}")
endif()
endif()
if (DPCTL_TARGET_HIP)
if(DPCTL_TARGET_HIP MATCHES "^gfx")
if(DPCTL_SYCL_PROVIDER STREQUAL "Intel")
if(_dpctl_sycl_targets)
set(_dpctl_sycl_targets "amd_gpu_${DPCTL_TARGET_HIP},${_dpctl_sycl_targets}")
else()
set(_dpctl_sycl_targets "amd_gpu_${DPCTL_TARGET_HIP},spir64-unknown-unknown")
endif()
elseif(DPCTL_SYCL_PROVIDER STREQUAL "AdaptiveCpp")
list(APPEND _acpp_targets_list "hip:${DPCTL_TARGET_HIP}")
endif()
else()
message(FATAL_ERROR
"Invalid value for DPCTL_TARGET_HIP: \"${DPCTL_TARGET_HIP}\". "
"Expected something starting with 'gfx', e.g. 'gfx1030'."
)
endif()
endif()
else()
if ("${DPCTL_SYCL_TARGETS}" MATCHES "amdgcn-amd-amdhsa")
message(FATAL_ERROR
"Legacy target 'amdgcn-amd-amdhsa' is not supported. "
"Use alias form 'amd_gpu_<arch>' instead."
)
endif()
set(_dpctl_sycl_targets ${DPCTL_SYCL_TARGETS})
if(DPCTL_SYCL_PROVIDER STREQUAL "AdaptiveCpp")
set(_acpp_targets_list ${DPCTL_SYCL_TARGETS})
endif()
endif()
# Load the SYCL env
set(_dpctl_sycl_target_compile_options)
set(_dpctl_sycl_target_link_options)
if(DPCTL_SYCL_PROVIDER STREQUAL "Intel")
message(STATUS "Using Intel DPC++ SYCL Provider")
find_package(IntelSYCL REQUIRED PATHS ${CMAKE_SOURCE_DIR}/cmake NO_DEFAULT_PATH)
if (_dpctl_sycl_targets)
message(STATUS "Compiling for -fsycl-targets=${_dpctl_sycl_targets}")
list(APPEND _dpctl_sycl_target_compile_options -fsycl-targets=${_dpctl_sycl_targets})
list(APPEND _dpctl_sycl_target_link_options -fsycl-targets=${_dpctl_sycl_targets})
endif()
elseif(DPCTL_SYCL_PROVIDER STREQUAL "AdaptiveCpp")
message(STATUS "Using AdaptiveCpp SYCL Provider")
# AdaptiveCpp reads the ACPP_TARGETS variable directly during find_package
if(_acpp_targets_list)
string(REPLACE ";" ";" ACPP_TARGETS "${_acpp_targets_list}")
set(ACPP_TARGETS "${ACPP_TARGETS}" CACHE STRING "AdaptiveCpp Targets" FORCE)
message(STATUS "Compiling for ACPP_TARGETS=${ACPP_TARGETS}")
endif()
# This automatically provides the add_sycl_to_target macro
find_package(AdaptiveCpp CONFIG REQUIRED)
endif()
add_subdirectory(libsyclinterface)
add_library(DpctlCAPI INTERFACE)
target_include_directories(DpctlCAPI INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/dpctl/apis/include)
target_link_libraries(DpctlCAPI INTERFACE DPCTLSyclInterfaceHeaders)
install(DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}/dpctl/apis/include/
DESTINATION ${CMAKE_INSTALL_PREFIX}/dpctl/include
FILES_MATCHING REGEX "\\.h(pp)?$"
)
# find Python before enabling pybind11
find_package(Python REQUIRED COMPONENTS Interpreter Development.Module)
# Define CMAKE_INSTALL_xxx: LIBDIR, INCLUDEDIR
include(GNUInstallDirs)
# Fetch pybind11
include(FetchContent)
FetchContent_Declare(
pybind11
URL https://github.com/pybind/pybind11/archive/refs/tags/v3.1.0.tar.gz
URL_HASH SHA256=ef712655692a2e9bf7bb7874c022564a45f91d847ddee987e720cd9e28849665
FIND_PACKAGE_ARGS NAMES pybind11
)
FetchContent_MakeAvailable(pybind11)
add_subdirectory(dpctl)
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)
endif()