Skip to content

Commit

Permalink
Better cmake integration with Level Zero
Browse files Browse the repository at this point in the history
  • Loading branch information
emdant committed May 26, 2023
1 parent 9c62b75 commit a4f0f03
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -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()

Expand Down
38 changes: 38 additions & 0 deletions cmake/FindLevelZero.cmake
Original file line number Diff line number Diff line change
@@ -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})
6 changes: 3 additions & 3 deletions samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ 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}")
endif()
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}")
Expand All @@ -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()
Expand Down

0 comments on commit a4f0f03

Please sign in to comment.