Skip to content

Commit 0d41070

Browse files
Lit tests for cuda_add_cufft_to_target and find_package CMake macros
1 parent b6849e5 commit 0d41070

8 files changed

Lines changed: 210 additions & 3 deletions

File tree

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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
find_package(IntelSYCL)
9+
find_package(IntelSYCL REQUIRED)
10+
find_package(IntelSYCL REQUIRED)
11+
#find_package(MPI REQUIRED)
12+
#find_package(OpenMP REQUIRED)
13+
dpct_find_package(cublas cufft nvToolsExt)
14+
find_package(DNNL REQUIRED dnnl)
15+
find_package(oneDPL REQUIRED)
16+
#find_package(NVJPEG 9.0 REQUIRED)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
project(foo-bar LANGUAGES CXX CUDA)
2+
3+
find_package(CUDA)
4+
find_package(CUDA REQUIRED)
5+
find_package(CUDA ${REQUIRED_CUDA_VERSION} REQUIRED)
6+
find_package(MPI REQUIRED)
7+
FIND_PACKAGE(OpenMP REQUIRED)
8+
find_package(CUDAToolkit REQUIRED cublas cufft nvToolsExt)
9+
find_package(CUDNN REQUIRED cudnn)
10+
find_package(CUB REQUIRED)
11+
find_package(NVJPEG 9.0 REQUIRED)
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: 100 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,102 @@
2727
MatchMode: Full
2828
RuleId: "remove_cuda"
2929

30-
- Rule: rule_find_package
30+
- Rule: rule_cuda_no_args_find_package
3131
Kind: CMakeRule
3232
Priority: Fallback
33-
CmakeSyntax: find_package
34-
In: find_package(${arg0} REQUIRED)
33+
CmakeSyntax: cuda_no_args_find_package
34+
MatchMode: Partial
35+
In: find_package(CUDA)
36+
Out: find_package(IntelSYCL)
37+
38+
- Rule: rule_cuda_find_package
39+
Kind: CMakeRule
40+
Priority: Fallback
41+
CmakeSyntax: cuda_find_package
42+
MatchMode: Partial
43+
In: find_package(CUDA ${args})
3544
Out: find_package(IntelSYCL REQUIRED)
3645

46+
# Current YAML rules comments this line
47+
# due to lack of equivalent MPI config file in oneAPI
48+
- Rule: rule_MPI_find_package
49+
Kind: CMakeRule
50+
Priority: Fallback
51+
CmakeSyntax: MPI_find_package
52+
MatchMode: Partial
53+
In: find_package(MPI ${args})
54+
Out: "#find_package(MPI ${args})"
55+
56+
# Current YAML rules comments this line
57+
# due to lack of equivalent OMP config file in oneAPI
58+
- Rule: rule_OMP_find_package
59+
Kind: CMakeRule
60+
Priority: Fallback
61+
CmakeSyntax: OMP_find_package
62+
MatchMode: Partial
63+
In: find_package(OpenMP ${args})
64+
Out: "#find_package(OpenMP ${args})"
65+
66+
- Rule: rule_CUDNN_find_package
67+
Kind: CMakeRule
68+
Priority: Fallback
69+
CmakeSyntax: CUDNN_find_package
70+
MatchMode: Partial
71+
In: find_package(${value})
72+
Out: find_package(${value})
73+
Subrules:
74+
value:
75+
In: CUDNN
76+
Out: DNNL
77+
MatchMode: Full
78+
RuleId: "find pkg CUDNN"
79+
80+
- Rule: rule_cudnn_val_find_package
81+
Kind: CMakeRule
82+
Priority: Fallback
83+
CmakeSyntax: cudnn_val_find_package
84+
MatchMode: Partial
85+
In: find_package(${value})
86+
Out: find_package(${value})
87+
Subrules:
88+
value:
89+
In: cudnn
90+
Out: dnnl
91+
MatchMode: Full
92+
RuleId: "find pkg cudnn val"
93+
94+
- Rule: rule_CUB_find_package
95+
Kind: CMakeRule
96+
Priority: Fallback
97+
CmakeSyntax: CUB_find_package
98+
MatchMode: Partial
99+
In: find_package(${value})
100+
Out: find_package(${value})
101+
Subrules:
102+
value:
103+
In: CUB
104+
Out: oneDPL
105+
MatchMode: Full
106+
RuleId: "find pkg CUB"
107+
108+
# Current YAML rules comments this line
109+
# due to lack of equivalent NVJPEG config file in oneAPI
110+
- Rule: rule_NVJPEG_find_package
111+
Kind: CMakeRule
112+
Priority: Fallback
113+
CmakeSyntax: NVJPEG_find_package
114+
MatchMode: Partial
115+
In: find_package(NVJPEG ${args})
116+
Out: "#find_package(NVJPEG ${args})"
117+
118+
- Rule: rule_CUDAToolkit_find_package
119+
Kind: CMakeRule
120+
Priority: Fallback
121+
CmakeSyntax: CUDAToolkit_find_package
122+
MatchMode: Partial
123+
In: find_package(CUDAToolkit REQUIRED ${args})
124+
Out: dpct_find_package(${args})
125+
37126
- Rule: rule_set
38127
Kind: CMakeRule
39128
Priority: Fallback
@@ -138,3 +227,11 @@
138227
In: ${arg}.cu
139228
Out: ${arg}.dp.cpp
140229

230+
- Rule: rule_cuda_add_cufft_to_target
231+
Kind: CMakeRule
232+
Priority: Fallback
233+
CmakeSyntax: cuda_add_cufft_to_target
234+
MatchMode: Partial
235+
In: cuda_add_cufft_to_target(${value})
236+
Out: dpct_add_mkl_to_target(${value})
237+

clang/tools/dpct/cmake/dpct.cmake

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,35 @@ 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()
88+
89+
# Find oneAPI lib packages
90+
macro(DPCT_FIND_PACKAGE package)
91+
DPCT_GET_SOURCES(_components ${ARGN})
92+
93+
foreach(package_name _components)
94+
if(package_name STREQUAL "cublas" OR
95+
package_name STREQUAL "curand" OR
96+
package_name STREQUAL "sparse" OR
97+
package_name STREQUAL "solver" OR
98+
package_name STREQUAL "cufft")
99+
find_package(MKL REQUIRED)
100+
elseif(package_name STREQUAL "cublas_static" OR
101+
package_name STREQUAL "curand_static" OR
102+
package_name STREQUAL "sparse_static" OR
103+
package_name STREQUAL "solver_static" OR
104+
package_name STREQUAL "cufft_static")
105+
find_package(MKL REQUIRED)
106+
endif()
107+
endforeach()
108+
endmacro()

0 commit comments

Comments
 (0)