Skip to content

Commit 8cb6182

Browse files
Lit tests for target_compile_features and cuda_add_cufft_to_target CMake
macros
1 parent b6849e5 commit 8cb6182

File tree

8 files changed

+150
-0
lines changed

8 files changed

+150
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: rm -rf %T && mkdir -p %T
2+
// RUN: cd %T
3+
// RUN: cp %S/input.cmake ./input.cmake
4+
// RUN: dpct -in-root ./ -out-root out ./input.cmake --rule-file=%S/../../../../tools/dpct/DpctOptRules/cmake_script_migration_rule.yaml --migrate-cmake-script-only --cuda-include-path="%cuda-path/include"
5+
// RUN: echo "begin" > %T/diff.txt
6+
// RUN: diff --strip-trailing-cr %S/expected.txt %T/out/input.cmake >> %T/diff.txt
7+
// RUN: echo "end" >> %T/diff.txt
8+
9+
// CHECK: begin
10+
// CHECK-NEXT: end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
add_library(culib)
2+
add_executable(cuexe)
3+
target_compile_features(culib PUBLIC c_std_11)
4+
target_compile_features(culib PRIVATE cxx_std_17)
5+
target_compile_features(culib
6+
PUBLIC
7+
cxx_std_17)
8+
9+
target_compile_features(culib PUBLIC c_std_17)
10+
target_compile_features(culib PRIVATE cxx_std_17)
11+
target_compile_features(culib
12+
PUBLIC
13+
cxx_std_17)
14+
15+
target_compile_features(cuexe PUBLIC c_std_20)
16+
target_compile_features(cuexe PRIVATE cxx_std_17)
17+
target_compile_features(cuexe
18+
PUBLIC
19+
cxx_std_17)
20+
21+
target_compile_features(cuexe PUBLIC c_std_23)
22+
target_compile_features(cuexe PRIVATE cxx_std_17)
23+
target_compile_features(cuexe
24+
PUBLIC
25+
cxx_std_17)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
add_library(culib)
2+
add_executable(cuexe)
3+
TARGET_COMPILE_FEATURES(culib PUBLIC c_std_11)
4+
target_compile_features(culib PRIVATE cxx_std_11)
5+
target_compile_features(culib
6+
PUBLIC
7+
cuda_std_11)
8+
9+
TARGET_COMPILE_FEATURES(culib PUBLIC c_std_17)
10+
target_compile_features(culib PRIVATE cxx_std_17)
11+
target_compile_features(culib
12+
PUBLIC
13+
cuda_std_17)
14+
15+
TARGET_COMPILE_FEATURES(cuexe PUBLIC c_std_20)
16+
target_compile_features(cuexe PRIVATE cxx_std_20)
17+
target_compile_features(cuexe
18+
PUBLIC
19+
cuda_std_20)
20+
21+
TARGET_COMPILE_FEATURES(cuexe PUBLIC c_std_23)
22+
target_compile_features(cuexe PRIVATE cxx_std_23)
23+
target_compile_features(cuexe
24+
PUBLIC
25+
cuda_std_23)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: rm -rf %T && mkdir -p %T
2+
// RUN: cd %T
3+
// RUN: cp %S/input.cmake ./input.cmake
4+
// RUN: dpct -in-root ./ -out-root out ./input.cmake --rule-file=%S/../../../../tools/dpct/DpctOptRules/cmake_script_migration_rule.yaml --migrate-cmake-script-only --cuda-include-path="%cuda-path/include"
5+
// RUN: echo "begin" > %T/diff.txt
6+
// RUN: diff --strip-trailing-cr %S/expected.txt %T/out/input.cmake >> %T/diff.txt
7+
// RUN: echo "end" >> %T/diff.txt
8+
9+
// CHECK: begin
10+
// CHECK-NEXT: end
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
project(foo-bar LANGUAGES CXX )
2+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsycl")
3+
find_program(dpct_bin_path NAMES dpct PATHS)
4+
get_filename_component(bin_path_of_dpct ${dpct_bin_path} DIRECTORY)
5+
set(dpct_cmake_file_path "${bin_path_of_dpct}/../cmake/dpct.cmake")
6+
include(${dpct_cmake_file_path})
7+
8+
add_library(culib)
9+
add_executable(cuexe)
10+
dpct_add_mkl_to_target(culib)
11+
dpct_add_mkl_to_target(
12+
culib
13+
)
14+
15+
dpct_add_mkl_to_target(cuexe)
16+
dpct_add_mkl_to_target(
17+
cuexe
18+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
project(foo-bar LANGUAGES CXX CUDA)
2+
3+
add_library(culib)
4+
add_executable(cuexe)
5+
CUDA_ADD_CUFFT_TO_TARGET(culib)
6+
cuda_add_cufft_to_target(
7+
culib
8+
)
9+
10+
CUDA_ADD_CUFFT_TO_TARGET(cuexe)
11+
cuda_add_cufft_to_target(
12+
cuexe
13+
)

clang/tools/dpct/DpctOptRules/cmake_script_migration_rule.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,41 @@
138138
In: ${arg}.cu
139139
Out: ${arg}.dp.cpp
140140

141+
- Rule: rule_cuda_add_cufft_to_target
142+
Kind: CMakeRule
143+
Priority: Fallback
144+
CmakeSyntax: cuda_add_cufft_to_target
145+
MatchMode: Partial
146+
In: cuda_add_cufft_to_target(${value})
147+
Out: dpct_add_mkl_to_target(${value})
148+
149+
# Current Yaml based rule hard-code to map "cxx_std_xx" to "cxx_std_17"
150+
# A more flexible mapping logic should be implemented in implicit rules
151+
- Rule: rule_cxx_target_compile_features
152+
Kind: CMakeRule
153+
Priority: Fallback
154+
CmakeSyntax: cxx_target_compile_features
155+
MatchMode: Partial
156+
In: target_compile_features(${value})
157+
Out: target_compile_features(${value})
158+
Subrules:
159+
value:
160+
In: cxx_std_${ver}
161+
Out: cxx_std_17
162+
RuleId: "adjust cxx_ver"
163+
164+
# Current Yaml based rule hard-code to map "cuda_std_xx" to "cxx_std_17"
165+
# A more flexible mapping logic should be implemented in implicit rules
166+
- Rule: rule_cuda_target_compile_features
167+
Kind: CMakeRule
168+
Priority: Fallback
169+
CmakeSyntax: cuda_target_compile_features
170+
MatchMode: Partial
171+
In: target_compile_features(${value})
172+
Out: target_compile_features(${value})
173+
Subrules:
174+
value:
175+
In: cuda_std_${ver}
176+
Out: cxx_std_17
177+
RuleId: "adjust cuda_ver"
178+

clang/tools/dpct/cmake/dpct.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,14 @@ endmacro()
7474
macro(DPCT_COMPILE_SYCL_CODE generated_files)
7575
DPCT_COMPILE_SYCL_CODE_IMP(sycl_device ${generated_files} ${ARGN})
7676
endmacro()
77+
78+
# Link MKL library to target
79+
macro(DPCT_ADD_MKL_TO_TARGET target)
80+
if(WIN32)
81+
target_link_libraries(${target} mkl_sycl_dll.lib mkl_intel_ilp64_dll.lib mkl_tbb_thread_dll.lib mkl_core_dll.lib OpenCL.lib)
82+
elseif(UNIX AND NOT APPLE)
83+
target_link_libraries(${target} -L${MKLROOT}/lib/intel64 -lmkl_intel_ilp64 -lmkl_tbb_thread -lmkl_core -lOpenCL -lmkl_sycl -lpthread -ldl)
84+
else()
85+
message(FATAL_ERROR "Unsupported platform")
86+
endif()
87+
endfunction()

0 commit comments

Comments
 (0)