Skip to content
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

cmake cleanup to support FetchContent functionality #23

Open
wants to merge 1 commit 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
41 changes: 12 additions & 29 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
cmake_minimum_required(VERSION 3.17 FATAL_ERROR)

# generate compile_commands.json with compile commands for each target
set(CMAKE_EXPORT_COMPILE_COMMANDS "YES")

set(MASTER_PROJECT OFF)
if(NOT DEFINED PROJECT_NAME)
set(MASTER_PROJECT ON)
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
project(Tiled-MM VERSION 2.3.1 LANGUAGES CXX)
Expand All @@ -25,34 +20,16 @@ endif()

message(STATUS "Selected TILEDMM_GPU_BACKEND: ${TILEDMM_GPU_BACKEND}")

set (TILEDMM_DEFINITIONS)
set (TILEDMM_EXTERNAL_LIBRARIES)
set(TILED_MM_CUDA OFF)
set(TILED_MM_ROCM OFF)
# Dependencies
#
if(TILEDMM_GPU_BACKEND STREQUAL "CUDA")
find_package(CUDAToolkit REQUIRED)
# this seems to be a cmake bug that was fixed in 3.12.2
if(CUDA_VERSION VERSION_GREATER 9.1 AND CMAKE_VERSION VERSION_LESS 3.12.2)
list(REMOVE_ITEM CUDA_CUBLAS_LIBRARIES "CUDA_cublas_device_LIBRARY-NOTFOUND")
endif()
if (NOT TARGET tiledmm::cuda)
add_library(tiledmm::cuda INTERFACE IMPORTED)
target_link_libraries(tiledmm::cuda INTERFACE CUDA::cublas CUDA::cudart)
endif()
list(APPEND TILEDMM_DEFINITIONS TILED_MM_CUDA)

set(TILED_MM_CUDA ON)
elseif(TILEDMM_GPU_BACKEND STREQUAL "ROCM")
find_package(rocblas REQUIRED)
if (NOT TARGET tiledmm::rocm)
add_library(tiledmm::rocm INTERFACE IMPORTED)
target_link_libraries(tiledmm::rocm INTERFACE roc::rocblas)
endif()

list(APPEND TILEDMM_DEFINITIONS TILED_MM_ROCM)
# TODO: it should be possible to remove this (and adapt the cpp code
# accordingly). Recent rocblas supports all types
list(APPEND TILEDMM_DEFINITIONS TILED_MM_ROCBLAS_HAS_SGEMM
TILED_MM_ROCBLAS_HAS_DGEMM TILED_MM_ROCBLAS_HAS_ZGEMM)
set(TILED_MM_ROCM ON)
else()
message(FATAL_ERROR "TILED_MM: GPU Backend must be CUDA or ROCM!")
endif()
Expand Down Expand Up @@ -86,7 +63,11 @@ install(FILES "${Tiled-MM_BINARY_DIR}/Tiled-MMConfig.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Tiled-MM")

if(TILEDMM_WITH_TESTS OR TILEDMM_WITH_EXAMPLES)
find_package(cxxopts REQUIRED)
FetchContent_Declare(cxxopts
GIT_REPOSITORY https://github.com/jarro2783/cxxopts.git
GIT_TAG 4bf61f08697b110d9e3991864650a405b3dd515d # v3.2.1
)
FetchContent_MakeAvailable(cxxopts)
endif()

if(TILEDMM_WITH_TESTS)
Expand All @@ -97,3 +78,5 @@ endif()
if(TILEDMM_WITH_EXAMPLES)
add_subdirectory(examples)
endif()


11 changes: 1 addition & 10 deletions cmake/Tiled-MMConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,11 @@ if(NOT TARGET Tiled-MM::Tiled-MM)
set(TILEDMM_GPU_BACKEND "@TILEDMM_GPU_BACKEND@")

if(TILEDMM_GPU_BACKEND STREQUAL "CUDA")
find_dependency(CUDAToolkit)
if (NOT TARGET tiledmm::cuda)
add_library(tiledmm::cuda INTERFACE IMPORTED)
target_link_libraries(tiledmm::cuda INTERFACE CUDA::cublas CUDA::cudart)
endif()

find_dependency(CUDAToolkit REQUIRED)
endif()

if(TILEDMM_GPU_BACKEND STREQUAL "ROCM")
find_dependency(rocblas REQUIRED)
if (NOT TARGET tiledmm::rocm)
add_library(tiledmm::rocm INTERFACE IMPORTED)
target_link_libraries(tiledmm::rocm INTERFACE roc::rocblas)
endif()
endif()

include("${CMAKE_CURRENT_LIST_DIR}/Tiled-MMTargets.cmake")
Expand Down
24 changes: 17 additions & 7 deletions src/Tiled-MM/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,32 @@ add_library(Tiled-MM gpu_context.cpp
tile_coord.cpp)

target_link_libraries(Tiled-MM PUBLIC
$<TARGET_NAME_IF_EXISTS:tiledmm::rocm>
$<TARGET_NAME_IF_EXISTS:tiledmm::cuda>
$<$<BOOL:${TILED_MM_ROCM}>:roc::rocblas>
$<$<BOOL:${TILED_MM_CUDA}>:CUDA::cublas CUDA::cudart>
)

message("TILEDMM_EXTERNAL_LIBRARIES ${TILEDMM_EXTERNAL_LIBRARIES}")

target_include_directories(Tiled-MM PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>
$<BUILD_INTERFACE:${Tiled-MM_SOURCE_DIR}/src>
INTERFACE
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

target_compile_features(Tiled-MM PUBLIC cxx_std_14)

target_compile_definitions(Tiled-MM PUBLIC ${TILEDMM_DEFINITIONS})
target_compile_definitions(Tiled-MM PUBLIC
$<$<BOOL:${TILED_MM_CUDA}>:TILED_MM_CUDA>
$<$<BOOL:${TILED_MM_ROCM}>:TILED_MM_ROCM TILED_MM_ROCBLAS_HAS_SGEMM TILED_MM_ROCBLAS_HAS_DGEMM TILED_MM_ROCBLAS_HAS_ZGEMM>)


install(TARGETS Tiled-MM
EXPORT Tiled-MM_targets
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/Tiled-MM")


# FetchContent mechanism. It should really use the config.cmake stuff instead of this
if (NOT TARGET Tiled-MM::Tiled-MM AND NOT TILED_MM_MASTER_PROJECT)
add_library(Tiled-MM::Tiled-MM ALIAS Tiled-MM)
endif()