Skip to content

Commit

Permalink
[SYCLomatic] support migration of cmake syntax: target_link_libraries (
Browse files Browse the repository at this point in the history
…#1571)

Signed-off-by: Ahmed, Daiyaan <[email protected]>
  • Loading branch information
daiyaan-ahmed6 authored Jan 5, 2024
1 parent 7dd458d commit adf9fb6
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: rm -rf %T && mkdir -p %T
// RUN: cd %T
// RUN: cp %S/input.cmake ./input.cmake
// RUN: dpct -in-root ./ -out-root out ./input.cmake --migrate-cmake-script-only
// RUN: echo "begin" > %T/diff.txt
// RUN: diff --strip-trailing-cr %S/expected.txt %T/out/input.cmake >> %T/diff.txt
// RUN: echo "end" >> %T/diff.txt

// CHECK: begin
// CHECK-NEXT: end
21 changes: 21 additions & 0 deletions clang/test/dpct/cmake_migration/case_004/expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
target_link_libraries(main PRIVATE cxxopts fmt::fmt -qmkl)

target_link_libraries(foo3 PUBLIC ${TCNN_LIBRARIES} fmt)

target_link_libraries(transformer_engine PUBLIC
-qmkl




${DNN_LIB})

target_link_libraries(${target} PRIVATE
-static-libgcc

)

target_link_libraries(${PROJECT_NAME}


)
21 changes: 21 additions & 0 deletions clang/test/dpct/cmake_migration/case_004/input.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
target_link_libraries(main PRIVATE cxxopts fmt::fmt -lcublas)

target_link_libraries(foo3 PUBLIC ${CUDA_LIBRARIES} ${TCNN_LIBRARIES} fmt)

target_link_libraries(transformer_engine PUBLIC
CUDA::cublas
CUDA::cuda_driver
CUDA::cudart
CUDA::nvrtc
CUDA::nvToolsExt
cudnn)

target_link_libraries(${target} PRIVATE
-static-libgcc
-static-libstdc++
)

target_link_libraries(${PROJECT_NAME}
libnvinfer.so
libnvonnxparser.so
)
152 changes: 152 additions & 0 deletions clang/tools/dpct/DpctOptRules/cmake_script_migration_rule.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,155 @@
In: ${arg}.cu
Out: ${arg}.dp.cpp

# CUDA_LIBRARIES is cmake cuda reverved list variable, should be removed in SYCL
- Rule: rule_target_link_libraries_CUDA_LIBRARIES
Kind: CMakeRule
Priority: Fallback
CmakeSyntax: CUDA_LIBRARIES_target_link_libraries
In: target_link_libraries(${CULibraries})
Out: target_link_libraries(${CULibraries})
Subrules:
CULibraries:
In: |
\${CUDA_LIBRARIES}
Out: ""
MatchMode: Full
RuleId: "remove_cuda_reserved_variable_CUDA_LIBRARIES"

- Rule: rule_target_link_libraries_-lcublas
Kind: CMakeRule
Priority: Fallback
CmakeSyntax: -lcublas_target_link_libraries
In: target_link_libraries(${CUDALibraries})
Out: target_link_libraries(${CUDALibraries})
Subrules:
CUDALibraries:
In: -lcublas
Out: -qmkl
MatchMode: Full
RuleId: "replace_-lcublas_with_qmkl"

- Rule: rule_target_link_libraries_CUDA_cublas
Kind: CMakeRule
Priority: Fallback
CmakeSyntax: CUDA_cublas_target_link_libraries
In: target_link_libraries(${CUDALibraries})
Out: target_link_libraries(${CUDALibraries})
Subrules:
CUDALibraries:
In: "CUDA::cublas"
Out: -qmkl
MatchMode: Full
RuleId: "replace_CUDA_cublas_with_qmkl"

# libsycl.so is linked by default as alternative to cuda_driver library, so removing here
- Rule: rule_target_link_libraries_cuda_driver
Kind: CMakeRule
Priority: Fallback
CmakeSyntax: cuda_driver_target_link_libraries
In: target_link_libraries(${CUDALibraries})
Out: target_link_libraries(${CUDALibraries})
Subrules:
CUDALibraries:
In: "CUDA::cuda_driver"
Out: ""
MatchMode: Full
RuleId: "remove_CUDA_driver"

# libsycl.so is linked by default as alternative to cuda_driver library, so removing here
- Rule: rule_target_link_libraries_cuda_rt
Kind: CMakeRule
Priority: Fallback
CmakeSyntax: cudart_target_link_libraries
In: target_link_libraries(${CUDALibraries})
Out: target_link_libraries(${CUDALibraries})
Subrules:
CUDALibraries:
In: "CUDA::cudart"
Out: ""
MatchMode: Full
RuleId: "remove_CUDA_cudart"

- Rule: rule_target_link_libraries_cudnn
Kind: CMakeRule
Priority: Fallback
CmakeSyntax: cudnn_target_link_libraries
In: target_link_libraries(${CUDALibraries})
Out: target_link_libraries(${CUDALibraries})
Subrules:
CUDALibraries:
In: "cudnn"
Out: |
\${DNN_LIB}
MatchMode: Full
RuleId: "replace_cudnn_with_libdnn"

# SYCL does not have mapping for nvrtc currently, so removing here
- Rule: rule_target_link_libraries_nvrtc
Kind: CMakeRule
Priority: Fallback
CmakeSyntax: nvrtc_target_link_libraries
In: target_link_libraries(${CUDALibraries})
Out: target_link_libraries(${CUDALibraries})
Subrules:
CUDALibraries:
In: "CUDA::nvrtc"
Out: ""
MatchMode: Full
RuleId: "remove_nvrtc"

# SYCL does not have mapping for nvToolsExt currently, so removing here
- Rule: rule_target_link_libraries_nvToolsExt
Kind: CMakeRule
Priority: Fallback
CmakeSyntax: nvToolsExt_target_link_libraries
In: target_link_libraries(${CUDALibraries})
Out: target_link_libraries(${CUDALibraries})
Subrules:
CUDALibraries:
In: "CUDA::nvToolsExt"
Out: ""
MatchMode: Full
RuleId: "remove_nvToolsExt"

# SYCL does not have mapping for libnvinfer currently, so removing here
- Rule: rule_target_link_libraries_libnvinfer
Kind: CMakeRule
Priority: Fallback
CmakeSyntax: libnvinfer_target_link_libraries
In: target_link_libraries(${CUDALibraries})
Out: target_link_libraries(${CUDALibraries})
Subrules:
CUDALibraries:
In: libnvinfer.so
Out: ""
MatchMode: Full
RuleId: "remove_libnvinfer"

# SYCL does not have mapping for libnvonnxparser currently, so removing here
- Rule: rule_target_link_libraries_libnvonnxparser
Kind: CMakeRule
Priority: Fallback
CmakeSyntax: libnvonnxparser_target_link_libraries
In: target_link_libraries(${CUDALibraries})
Out: target_link_libraries(${CUDALibraries})
Subrules:
CUDALibraries:
In: libnvonnxparser.so
Out: ""
MatchMode: Full
RuleId: "remove_libnvonnxparser"

# icpx: error: '-static-libstdc++' is not supported with '-fsycl', so removing here
- Rule: rule_target_link_libraries_libstdc++
Kind: CMakeRule
Priority: Fallback
CmakeSyntax: libstdc++_target_link_libraries
In: target_link_libraries(${StaticLibraries})
Out: target_link_libraries(${StaticLibraries})
Subrules:
StaticLibraries:
In: -static-libstdc++
Out: ""
MatchMode: Full
RuleId: "remove_-static-libstdc++"
6 changes: 6 additions & 0 deletions clang/tools/dpct/cmake/dpct.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,9 @@ macro(DPCT_HELPER_SYCL_COMPILE generated_files)

_DPCT_CREATE_BUILD_COMMAND("sycl_device" ${generated_files} ${_sources})
endmacro()

if(WIN32)
set(DNN_LIB "dnnl.lib")
else()
set(DNN_LIB "dnnl")
endif()

0 comments on commit adf9fb6

Please sign in to comment.