Skip to content

Add optional add_sycl_to_target to cmake #2

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
20 changes: 19 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ endif()
option(ENABLE_CUBLAS_BACKEND "" OFF)
option(ENABLE_CURAND_BACKEND "" OFF)
option(ENABLE_NETLIB_BACKEND "" OFF)
option(DISABLE_HALF_RUTINES "" OFF)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah here it is... an alternative naming could be ENABLE_HALF_DATA_TYPE or similar (inspired by SYCL-BLAS..)

set(ONEMKL_SYCL_IMPLEMENTATION "dpc++" CACHE STRING "Name of the SYCL compiler")



## Domains
set(DOMAINS_LIST "")
Expand Down Expand Up @@ -124,7 +128,21 @@ list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
if(WIN32)
add_library(ONEMKL::SYCL::SYCL INTERFACE IMPORTED)
else()
find_package(Compiler REQUIRED)
# Find necessary packages
string( TOLOWER "${ONEMKL_SYCL_IMPLEMENTATION}" ONEMKL_SYCL_IMPLEMENTATION)
if (ONEMKL_SYCL_IMPLEMENTATION STREQUAL "hipsycl")
message(STATUS "Looking for hipSYCL")
find_package(hipSYCL CONFIG REQUIRED)
set(USE_ADD_SYCL_TO_TARGET_INTEGRATION true)
add_library(ONEMKL::SYCL::SYCL INTERFACE IMPORTED)
elseif(ONEMKL_SYCL_IMPLEMENTATION STREQUAL "dpc++")
message(STATUS "Looking for dpc++")
set(USE_ADD_SYCL_TO_TARGET_INTEGRATION false)
set(ENABLE_HALF_ROUTINES ON)
find_package(Compiler REQUIRED)
else()
message(FATAL_ERROR "SYCL implementation ${ONEMKL_SYCL_IMPLEMENTATION} is not known")
endif()
endif()

# Add source directory and output to bin/
Expand Down
4 changes: 2 additions & 2 deletions cmake/FindCompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ if(is_dpcpp)
if(UNIX)
set(UNIX_INTERFACE_COMPILE_OPTIONS -fsycl)
set(UNIX_INTERFACE_LINK_OPTIONS -fsycl)
if(ENABLE_CURAND_BACKEND)
if(ENABLE_CURAND_BACKEND OR ENABLE_CUBLAS_BACKEND)
list(APPEND UNIX_INTERFACE_COMPILE_OPTIONS
-fsycl-targets=nvptx64-nvidia-cuda-sycldevice -fsycl-unnamed-lambda)
list(APPEND UNIX_INTERFACE_LINK_OPTIONS
-fsycl-targets=nvptx64-nvidia-cuda-sycldevice)
endif()
if(ENABLE_CURAND_BACKEND)
if(ENABLE_CURAND_BACKEND OR ENABLE_CUBLAS_BACKEND)
set_target_properties(ONEMKL::SYCL::SYCL PROPERTIES
INTERFACE_COMPILE_OPTIONS "${UNIX_INTERFACE_COMPILE_OPTIONS}"
INTERFACE_LINK_OPTIONS "${UNIX_INTERFACE_LINK_OPTIONS}"
Expand Down
8 changes: 6 additions & 2 deletions src/blas/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ target_include_directories(onemkl_blas
${CMAKE_BINARY_DIR}/bin
$<TARGET_FILE_DIR:onemkl>
)

target_compile_options(onemkl_blas PRIVATE ${ONEMKL_BUILD_COPT})

set_target_properties(onemkl_blas PROPERTIES
POSITION_INDEPENDENT_CODE ON
)
target_link_libraries(onemkl_blas PUBLIC ONEMKL::SYCL::SYCL)
if (USE_ADD_SYCL_TO_TARGET_INTEGRATION)
add_sycl_to_target(TARGET onemkl_blas SOURCES blas_loader.cpp)
else()
target_link_libraries(onemkl_blas PUBLIC ONEMKL::SYCL::SYCL)
endif()

endif()

23 changes: 12 additions & 11 deletions src/blas/backends/cublas/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@
set(LIB_NAME onemkl_blas_cublas)
set(LIB_OBJ ${LIB_NAME}_obj)
find_package(cuBLAS REQUIRED)

set(SOURCES cublas_level1.cpp
cublas_level2.cpp
cublas_level3.cpp
cublas_batch.cpp
cublas_extensions.cpp
cublas_scope_handle.cpp
$<$<BOOL:${BUILD_SHARED_LIBS}>: mkl_blas_cublas_wrappers.cpp>)
add_library(${LIB_NAME})
add_library(${LIB_OBJ} OBJECT
cublas_level1.cpp
cublas_level2.cpp
cublas_level3.cpp
cublas_batch.cpp
cublas_extensions.cpp
cublas_scope_handle.cpp
$<$<BOOL:${BUILD_SHARED_LIBS}>: mkl_blas_cublas_wrappers.cpp>
)
add_library(${LIB_OBJ} OBJECT ${SOURCES})

target_include_directories(${LIB_OBJ}
PRIVATE ${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/src
Expand All @@ -42,7 +41,9 @@ set_target_properties(${LIB_OBJ} PROPERTIES
POSITION_INDEPENDENT_CODE ON)

target_link_libraries(${LIB_NAME} PUBLIC ${LIB_OBJ})

if (USE_ADD_SYCL_TO_TARGET_INTEGRATION)
add_sycl_to_target(TARGET ${LIB_OBJ} SOURCES ${SOURCES})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we even have to specify the SOURCES here..? (not sure about the semantics with or without :D)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hipSYCL doesn't need it, but it's the correct interface for portability, as e.g. ComputeCpp needs it AFAIK.

endif()
# Add major version to the library
set_target_properties(${LIB_NAME} PROPERTIES
SOVERSION ${PROJECT_VERSION_MAJOR}
Expand Down
13 changes: 7 additions & 6 deletions src/blas/backends/mklcpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ set(LIB_NAME onemkl_blas_mklcpu)
set(LIB_OBJ ${LIB_NAME}_obj)

find_package(MKL REQUIRED)

add_library(${LIB_NAME})
add_library(${LIB_OBJ} OBJECT
fp16.hpp mklcpu_common.hpp
set(SOURCES fp16.hpp mklcpu_common.hpp
mklcpu_level1.cpp mklcpu_level2.cpp mklcpu_level3.cpp mklcpu_batch.cpp mklcpu_extensions.cpp
$<$<BOOL:${BUILD_SHARED_LIBS}>: mklcpu_wrappers.cpp>
)
$<$<BOOL:${BUILD_SHARED_LIBS}>: mklcpu_wrappers.cpp>)
add_library(${LIB_NAME})
add_library(${LIB_OBJ} OBJECT ${SOURCES})
if (USE_ADD_SYCL_TO_TARGET_INTEGRATION)
add_sycl_to_target(TARGET ${LIB_OBJ} SOURCES ${SOURCES})
endif()

target_include_directories(${LIB_OBJ}
PRIVATE ${PROJECT_SOURCE_DIR}/include
Expand Down
7 changes: 6 additions & 1 deletion src/rng/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,10 @@ target_compile_options(onemkl_rng PRIVATE ${ONEMKL_BUILD_COPT})
set_target_properties(onemkl_rng PROPERTIES
POSITION_INDEPENDENT_CODE ON
)
target_link_libraries(onemkl_rng PUBLIC ONEMKL::SYCL::SYCL)
if (USE_ADD_SYCL_TO_TARGET_INTEGRATION)
add_sycl_to_target(TARGET onemkl_rng SOURCES rng_loader.cpp)
else()
target_link_libraries(onemkl_rng PUBLIC ONEMKL::SYCL::SYCL)
endif()

endif()
13 changes: 8 additions & 5 deletions src/rng/backends/curand/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,14 @@ set(LIB_NAME onemkl_rng_curand)
set(LIB_OBJ ${LIB_NAME}_obj)
find_package(cuRAND REQUIRED)

add_library(${LIB_NAME})
add_library(${LIB_OBJ} OBJECT
philox4x32x10.cpp
set(SOURCES philox4x32x10.cpp
mrg32k3a.cpp
$<$<BOOL:${BUILD_SHARED_LIBS}>: mkl_rng_curand_wrappers.cpp>
$<$<BOOL:${BUILD_SHARED_LIBS}>: mkl_rng_curand_wrappers.cpp>)
)

add_library(${LIB_NAME})
add_library(${LIB_OBJ} OBJECT ${SOURCES})

target_include_directories(${LIB_OBJ}
PRIVATE ${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/src
Expand All @@ -81,7 +82,9 @@ set_target_properties(${LIB_OBJ} PROPERTIES
)

target_link_libraries(${LIB_NAME} PUBLIC ${LIB_OBJ})

if (USE_ADD_SYCL_TO_TARGET_INTEGRATION)
add_sycl_to_target(TARGET ${LIB_OBJ} SOURCES ${SOURCES})
endif()
# Add major version to the library
set_target_properties(${LIB_NAME} PROPERTIES
SOVERSION ${PROJECT_VERSION_MAJOR}
Expand Down
12 changes: 8 additions & 4 deletions src/rng/backends/mklcpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ set(LIB_OBJ ${LIB_NAME}_obj)

find_package(MKL REQUIRED)

add_library(${LIB_NAME})
add_library(${LIB_OBJ} OBJECT
cpu_common.hpp
set(SOURCES cpu_common.hpp
philox4x32x10.cpp
mrg32k3a.cpp
$<$<BOOL:${BUILD_SHARED_LIBS}>: mkl_rng_cpu_wrappers.cpp>
)

add_library(${LIB_NAME})
add_library(${LIB_OBJ} OBJECT ${SOURCES})


target_include_directories(${LIB_OBJ}
PRIVATE ${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/src
Expand All @@ -38,7 +40,9 @@ target_include_directories(${LIB_OBJ}
)

target_compile_options(${LIB_OBJ} PRIVATE ${ONEMKL_BUILD_COPT} ${MKL_COPT})

if (USE_ADD_SYCL_TO_TARGET_INTEGRATION)
add_sycl_to_target(TARGET ${LIB_OBJ} SOURCES ${SOURCES})
endif()
target_link_libraries(${LIB_OBJ} PUBLIC ONEMKL::SYCL::SYCL ${MKL_LINK_C})

set_target_properties(${LIB_OBJ} PROPERTIES
Expand Down
14 changes: 12 additions & 2 deletions tests/unit_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ foreach(domain ${TARGET_DOMAINS})

add_executable(test_main_${domain}_ct main_test.cpp)
target_include_directories(test_main_${domain}_ct PUBLIC ${GTEST_INCLUDE_DIR})
target_compile_options(test_main_${domain}_ct PRIVATE -fsycl)

if (USE_ADD_SYCL_TO_TARGET_INTEGRATION)
add_sycl_to_target(TARGET test_main_${domain}_ct SOURCES main_test.cpp)
else()
target_compile_options(test_main_${domain}_ct PRIVATE -fsycl)
endif()

if(BUILD_SHARED_LIBS)
add_executable(test_main_${domain}_rt main_test.cpp)
Expand All @@ -73,6 +78,9 @@ foreach(domain ${TARGET_DOMAINS})
onemkl
${${domain}_TEST_LIST_RT}
)
if (USE_ADD_SYCL_TO_TARGET_INTEGRATION)
add_sycl_to_target(TARGET test_main_${domain}_rt SOURCES main_test.cpp)
endif()
endif()

if(ENABLE_MKLCPU_BACKEND)
Expand Down Expand Up @@ -109,7 +117,6 @@ foreach(domain ${TARGET_DOMAINS})
ONEMKL::SYCL::SYCL
${${domain}_TEST_LIST_CT}
)

string(TOUPPER ${domain} DOMAIN_PREFIX)

if(BUILD_SHARED_LIBS)
Expand All @@ -130,5 +137,8 @@ foreach(domain ${TARGET_DOMAINS})
PROPERTIES TEST_PREFIX ${DOMAIN_PREFIX}/CT/
DISCOVERY_TIMEOUT 30
)
if (USE_ADD_SYCL_TO_TARGET_INTEGRATION)
add_sycl_to_target(TARGET test_main_${domain}_rt)
endif()

endforeach()
10 changes: 10 additions & 0 deletions tests/unit_tests/blas/batch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ if(BUILD_SHARED_LIBS)
PUBLIC ${CBLAS_INCLUDE}
)
target_link_libraries(blas_batch_rt PUBLIC ONEMKL::SYCL::SYCL)
if (USE_ADD_SYCL_TO_TARGET_INTEGRATION)
add_sycl_to_target(TARGET blas_batch_rt SOURCES ${BATCH_SOURCES})
else()
target_link_libraries(blas_batch_rt PUBLIC ONEMKL::SYCL::SYCL)
endif()
endif()

add_library(blas_batch_ct OBJECT ${BATCH_SOURCES})
Expand All @@ -45,3 +50,8 @@ target_include_directories(blas_batch_ct
PUBLIC ${CBLAS_INCLUDE}
)
target_link_libraries(blas_batch_ct PUBLIC ONEMKL::SYCL::SYCL)
if (USE_ADD_SYCL_TO_TARGET_INTEGRATION)
add_sycl_to_target(TARGET blas_batch_ct SOURCES ${BATCH_SOURCES})
else()
target_link_libraries(blas_batch_ct PUBLIC ONEMKL::SYCL::SYCL)
endif()
10 changes: 10 additions & 0 deletions tests/unit_tests/blas/extensions/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ if(BUILD_SHARED_LIBS)
PUBLIC ${CBLAS_INCLUDE}
)
target_link_libraries(blas_extensions_rt PUBLIC ONEMKL::SYCL::SYCL)
if (USE_ADD_SYCL_TO_TARGET_INTEGRATION)
add_sycl_to_target(TARGET blas_extensions_rt SOURCES ${EXTENSIONS_SOURCES})
else()
target_link_libraries(blas_extensions_rt PUBLIC ONEMKL::SYCL::SYCL)
endif()
endif()

add_library(blas_extensions_ct OBJECT ${EXTENSIONS_SOURCES})
Expand All @@ -45,3 +50,8 @@ target_include_directories(blas_extensions_ct
PUBLIC ${CBLAS_INCLUDE}
)
target_link_libraries(blas_extensions_ct PUBLIC ONEMKL::SYCL::SYCL)
if (USE_ADD_SYCL_TO_TARGET_INTEGRATION)
add_sycl_to_target(TARGET blas_extensions_ct SOURCES ${EXTENSIONS_SOURCES})
else()
target_link_libraries(blas_extensions_ct PUBLIC ONEMKL::SYCL::SYCL)
endif()
13 changes: 11 additions & 2 deletions tests/unit_tests/blas/level1/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ if(BUILD_SHARED_LIBS)
PUBLIC ${CMAKE_BINARY_DIR}/bin
PUBLIC ${CBLAS_INCLUDE}
)
target_link_libraries(blas_level1_rt PUBLIC ONEMKL::SYCL::SYCL)
if (USE_ADD_SYCL_TO_TARGET_INTEGRATION)
add_sycl_to_target(TARGET blas_level1_rt SOURCES ${L1_SOURCES})
else()
target_link_libraries(blas_level1_rt PUBLIC ONEMKL::SYCL::SYCL)
endif()
endif()


add_library(blas_level1_ct OBJECT ${L1_SOURCES})
target_compile_options(blas_level1_ct PRIVATE -DNOMINMAX)
target_include_directories(blas_level1_ct
Expand All @@ -44,4 +49,8 @@ target_include_directories(blas_level1_ct
PUBLIC ${CMAKE_BINARY_DIR}/bin
PUBLIC ${CBLAS_INCLUDE}
)
target_link_libraries(blas_level1_ct PUBLIC ONEMKL::SYCL::SYCL)
if (USE_ADD_SYCL_TO_TARGET_INTEGRATION)
add_sycl_to_target(TARGET blas_level1_ct SOURCES ${L1_SOURCES})
else()
target_link_libraries(blas_level1_ct PUBLIC ONEMKL::SYCL::SYCL)
endif()
12 changes: 10 additions & 2 deletions tests/unit_tests/blas/level2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ if(BUILD_SHARED_LIBS)
PUBLIC ${CMAKE_BINARY_DIR}/bin
PUBLIC ${CBLAS_INCLUDE}
)
target_link_libraries(blas_level2_rt PUBLIC ONEMKL::SYCL::SYCL)
if (USE_ADD_SYCL_TO_TARGET_INTEGRATION)
add_sycl_to_target(TARGET blas_level2_rt SOURCES ${L2_SOURCES})
else()
target_link_libraries(blas_level2_rt PUBLIC ONEMKL::SYCL::SYCL)
endif()
endif()

add_library(blas_level2_ct OBJECT ${L2_SOURCES})
Expand All @@ -44,5 +48,9 @@ target_include_directories(blas_level2_ct
PUBLIC ${CMAKE_BINARY_DIR}/bin
PUBLIC ${CBLAS_INCLUDE}
)
target_link_libraries(blas_level2_ct PUBLIC ONEMKL::SYCL::SYCL)
if (USE_ADD_SYCL_TO_TARGET_INTEGRATION)
add_sycl_to_target(TARGET blas_level2_ct SOURCES ${L2_SOURCES})
else()
target_link_libraries(blas_level2_ct PUBLIC ONEMKL::SYCL::SYCL)
endif()

12 changes: 10 additions & 2 deletions tests/unit_tests/blas/level3/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ if(BUILD_SHARED_LIBS)
PUBLIC ${CMAKE_BINARY_DIR}/bin
PUBLIC ${CBLAS_INCLUDE}
)
target_link_libraries(blas_level3_rt PUBLIC ONEMKL::SYCL::SYCL)
if (USE_ADD_SYCL_TO_TARGET_INTEGRATION)
add_sycl_to_target(TARGET blas_level3_rt SOURCES ${L3_SOURCES})
else()
target_link_libraries(blas_level3_rt PUBLIC ONEMKL::SYCL::SYCL)
endif()
endif()

add_library(blas_level3_ct OBJECT ${L3_SOURCES})
Expand All @@ -44,6 +48,10 @@ target_include_directories(blas_level3_ct
PUBLIC ${CMAKE_BINARY_DIR}/bin
PUBLIC ${CBLAS_INCLUDE}
)
target_link_libraries(blas_level3_ct PUBLIC ONEMKL::SYCL::SYCL)
if (USE_ADD_SYCL_TO_TARGET_INTEGRATION)
add_sycl_to_target(TARGET blas_level3_ct SOURCES ${L3_SOURCES})
else()
target_link_libraries(blas_level3_ct PUBLIC ONEMKL::SYCL::SYCL)
endif()


11 changes: 10 additions & 1 deletion tests/unit_tests/rng/service/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ if(BUILD_SHARED_LIBS)
PUBLIC ${PROJECT_SOURCE_DIR}/deps/googletest/include
PUBLIC ${CMAKE_BINARY_DIR}/bin
)
target_link_libraries(rng_service_rt PUBLIC ONEMKL::SYCL::SYCL)
if (USE_ADD_SYCL_TO_TARGET_INTEGRATION)
add_sycl_to_target(TARGET rng_service_rt SOURCES ${SERVICE_TESTS_SOURCES})
else()
target_link_libraries(rng_service_rt PUBLIC ONEMKL::SYCL::SYCL)
endif()
endif()

add_library(rng_service_ct OBJECT ${SERVICE_TESTS_SOURCES})
Expand All @@ -43,3 +47,8 @@ target_include_directories(rng_service_ct
PUBLIC ${CMAKE_BINARY_DIR}/bin
)
target_link_libraries(rng_service_ct PUBLIC ONEMKL::SYCL::SYCL)
if (USE_ADD_SYCL_TO_TARGET_INTEGRATION)
add_sycl_to_target(TARGET rng_service_ct SOURCES ${SERVICE_TESTS_SOURCES})
else()
target_link_libraries(rng_service_ct PUBLIC ONEMKL::SYCL::SYCL)
endif()
Loading