From a4f0f035b4573faac86abe0780f467eab288b774 Mon Sep 17 00:00:00 2001 From: emdant <30555419+emdant@users.noreply.github.com> Date: Fri, 26 May 2023 22:09:39 +0200 Subject: [PATCH] Better cmake integration with Level Zero --- CMakeLists.txt | 5 +++++ cmake/FindLevelZero.cmake | 38 ++++++++++++++++++++++++++++++++++++++ samples/CMakeLists.txt | 6 +++--- 3 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 cmake/FindLevelZero.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index d37d38c..97d0fa6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,8 @@ cmake_minimum_required(VERSION 3.17) project(SYnergy VERSION 0.1.1 LANGUAGES CXX) +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") + set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -53,7 +55,10 @@ if(SYNERGY_ROCM_SUPPORT) endif() if(SYNERGY_LZ_SUPPORT) + find_package(LevelZero REQUIRED) + target_compile_definitions(synergy INTERFACE SYNERGY_LZ_SUPPORT) + target_link_libraries(synergy INTERFACE LevelZero::LevelZero) target_sources(synergy INTERFACE include/vendors/lz_wrapper.hpp) endif() diff --git a/cmake/FindLevelZero.cmake b/cmake/FindLevelZero.cmake new file mode 100644 index 0000000..307ab53 --- /dev/null +++ b/cmake/FindLevelZero.cmake @@ -0,0 +1,38 @@ +include(FindPackageHandleStandardArgs) + +find_path(LevelZero_INCLUDE_DIR + NAMES level_zero/ze_api.h +) + +find_library(LevelZero_LIBRARY + NAMES ze_loader ze_loader32 ze_loader64 +) + +find_package_handle_standard_args(LevelZero + REQUIRED_VARS + LevelZero_INCLUDE_DIR + LevelZero_LIBRARY + HANDLE_COMPONENTS +) +mark_as_advanced(LevelZero_LIBRARY LevelZero_INCLUDE_DIR) + +if(LevelZero_FOUND) + list(APPEND LevelZero_LIBRARIES ${LevelZero_LIBRARY} ${CMAKE_DL_LIBS}) + list(APPEND LevelZero_INCLUDE_DIRS ${LevelZero_INCLUDE_DIR}) + if(OpenCL_FOUND) + list(APPEND LevelZero_INCLUDE_DIRS ${OpenCL_INCLUDE_DIRS}) + endif() +endif() + +if(LevelZero_FOUND AND NOT TARGET LevelZero::LevelZero) + add_library(LevelZero::LevelZero INTERFACE IMPORTED) + set_target_properties(LevelZero::LevelZero + PROPERTIES INTERFACE_LINK_LIBRARIES "${LevelZero_LIBRARIES}" + ) + set_target_properties(LevelZero::LevelZero + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${LevelZero_INCLUDE_DIRS}" + ) +endif() + +MESSAGE(STATUS "LevelZero_LIBRARIES: " ${LevelZero_LIBRARIES}) +MESSAGE(STATUS "LevelZero_INCLUDE_DIRS: " ${LevelZero_INCLUDE_DIRS}) diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index adc8698..e1097c3 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -29,7 +29,7 @@ foreach(target IN LISTS all_targets) if(SYNERGY_CUDA_SUPPORT) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsycl-targets=nvptx64-nvidia-cuda") - set(SYNERGY_SAMPLES_CUDA_ARCH "" CACHE STRING "CUDA architecture in format \"sm_**\" e.g. sm_70") + set(SYNERGY_SAMPLES_CUDA_ARCH "" CACHE STRING "CUDA device architecture e.g. sm_70") if(NOT SYNERGY_SAMPLES_CUDA_ARCH STREQUAL "") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Xsycl-target-backend --cuda-gpu-arch=${SYNERGY_SAMPLES_CUDA_ARCH}") @@ -37,7 +37,7 @@ foreach(target IN LISTS all_targets) endif() if(SYNERGY_ROCM_SUPPORT) - set(SYNERGY_SAMPLES_ROCM_ARCH "" CACHE STRING "ROCm architecture in format \"gfx***\" e.g. gfx908") + set(SYNERGY_SAMPLES_ROCM_ARCH "" CACHE STRING "ROCm device architecture e.g. gfx908") if(NOT SYNERGY_SAMPLES_ROCM_ARCH STREQUAL "") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsycl-targets=amd_gpu_${SYNERGY_SAMPLES_ROCM_ARCH}") @@ -47,7 +47,7 @@ foreach(target IN LISTS all_targets) if(SYNERGY_LZ_SUPPORT) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsycl-targets=spir64_gen") - set(SYNERGY_SAMPLES_LZ_ARCH "" CACHE STRING "LevelZero device architecture e.g. acm-g10") + set(SYNERGY_SAMPLES_LZ_ARCH "" CACHE STRING "Level Zero device architecture e.g. acm-g10") if(NOT SYNERGY_SAMPLES_ROCM_ARCH STREQUAL "") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Xsycl-target-backend \"-device ${SYNERGY_SAMPLES_LZ_ARCH}\"") endif()