diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e21a09..b6989e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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() @@ -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) @@ -97,3 +78,5 @@ endif() if(TILEDMM_WITH_EXAMPLES) add_subdirectory(examples) endif() + + diff --git a/cmake/Tiled-MMConfig.cmake.in b/cmake/Tiled-MMConfig.cmake.in index 22818cc..36b2e8e 100644 --- a/cmake/Tiled-MMConfig.cmake.in +++ b/cmake/Tiled-MMConfig.cmake.in @@ -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") diff --git a/src/Tiled-MM/CMakeLists.txt b/src/Tiled-MM/CMakeLists.txt index d59293d..7fa648b 100644 --- a/src/Tiled-MM/CMakeLists.txt +++ b/src/Tiled-MM/CMakeLists.txt @@ -6,22 +6,32 @@ add_library(Tiled-MM gpu_context.cpp tile_coord.cpp) target_link_libraries(Tiled-MM PUBLIC - $ - $ + $<$:roc::rocblas> + $<$:CUDA::cublas CUDA::cudart> ) -message("TILEDMM_EXTERNAL_LIBRARIES ${TILEDMM_EXTERNAL_LIBRARIES}") - target_include_directories(Tiled-MM PUBLIC - $ + $ + INTERFACE + $ ) target_compile_features(Tiled-MM PUBLIC cxx_std_14) -target_compile_definitions(Tiled-MM PUBLIC ${TILEDMM_DEFINITIONS}) +target_compile_definitions(Tiled-MM PUBLIC + $<$:TILED_MM_CUDA> + $<$: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() +