From 0edebd0e2b6b70c24dbc5202d48fcb4119d552f7 Mon Sep 17 00:00:00 2001 From: mosout Date: Wed, 22 May 2024 10:44:24 +0800 Subject: [PATCH] use cpm --- CMakeLists.txt | 1 + cmake/CPM.cmake | 25 +++++++++++++++++++++++++ cmake/oneflow.cmake | 10 +++++----- cmake/third_party.cmake | 16 ++++++++-------- external/CMakeLists.txt | 9 +++++++-- external/flash_attention/CMakeLists.txt | 9 +++++++++ 6 files changed, 55 insertions(+), 15 deletions(-) create mode 100644 cmake/CPM.cmake create mode 100644 external/flash_attention/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 0fe46d0a5ef..123c7cd9157 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -116,6 +116,7 @@ list(APPEND CMAKE_MODULE_PATH ${oneflow_cmake_dir}) include(threading) include(util) +include(CPM) include(proto2cpp) if(NOT DEFINED USE_CXX11_ABI) diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake new file mode 100644 index 00000000000..deb7ab2ef23 --- /dev/null +++ b/cmake/CPM.cmake @@ -0,0 +1,25 @@ +# SPDX-License-Identifier: MIT +# +# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors + +set(CPM_DOWNLOAD_VERSION 0.39.0) +set(CPM_HASH_SUM "66639bcac9dd2907b2918de466783554c1334446b9874e90d38e3778d404c2ef") + +if(CPM_SOURCE_CACHE) + set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +elseif(DEFINED ENV{CPM_SOURCE_CACHE}) + set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +else() + set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +endif() + +# Expand relative path. This is important if the provided path contains a tilde (~) +get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE) + +set(CPM_CMAKE_URL + https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake) +use_mirror(VARIABLE CPM_CMAKE_URL URL ${CPM_CMAKE_URL}) + +file(DOWNLOAD ${CPM_CMAKE_URL} ${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM}) + +include(${CPM_DOWNLOAD_LOCATION}) diff --git a/cmake/oneflow.cmake b/cmake/oneflow.cmake index b37535367e1..4dc5809f8af 100644 --- a/cmake/oneflow.cmake +++ b/cmake/oneflow.cmake @@ -632,11 +632,11 @@ if(BUILD_CPP_API) checkdirandappendslash(DIR ${TRT_FLASH_ATTENTION_LIBRARY_DIR} OUTPUT TRT_FLASH_ATTENTION_LIBRARY_DIR_APPENDED) list(APPEND LIBONEFLOW_THIRD_PARTY_DIRS ${TRT_FLASH_ATTENTION_LIBRARY_DIR_APPENDED}) - if(CUDA_VERSION VERSION_GREATER_EQUAL "11.7") - checkdirandappendslash(DIR ${FLASH_ATTENTION_LIBRARY_DIR} OUTPUT - FLASH_ATTENTION_LIBRARY_DIR_APPENDED) - list(APPEND LIBONEFLOW_THIRD_PARTY_DIRS ${FLASH_ATTENTION_LIBRARY_DIR_APPENDED}) - endif() + # if(CUDA_VERSION VERSION_GREATER_EQUAL "11.7") + # checkdirandappendslash(DIR ${FLASH_ATTENTION_LIBRARY_DIR} OUTPUT + # FLASH_ATTENTION_LIBRARY_DIR_APPENDED) + # list(APPEND LIBONEFLOW_THIRD_PARTY_DIRS ${FLASH_ATTENTION_LIBRARY_DIR_APPENDED}) + # endif() if(WITH_CUTLASS) checkdirandappendslash(DIR ${CUTLASS_LIBRARY_DIR} OUTPUT CUTLASS_LIBRARY_DIR_APPENDED) list(APPEND LIBONEFLOW_THIRD_PARTY_DIRS ${CUTLASS_LIBRARY_DIR_APPENDED}) diff --git a/cmake/third_party.cmake b/cmake/third_party.cmake index 43d731af056..82075f5f965 100644 --- a/cmake/third_party.cmake +++ b/cmake/third_party.cmake @@ -145,9 +145,9 @@ if(BUILD_CUDA) include(nccl) include(cutlass) include(trt_flash_attention) - if(CUDA_VERSION VERSION_GREATER_EQUAL "11.7") - include(flash_attention) - endif() + # if(CUDA_VERSION VERSION_GREATER_EQUAL "11.7") + # include(flash_attention) + # endif() list(APPEND oneflow_third_party_libs ${NCCL_LIBRARIES}) list(APPEND oneflow_third_party_libs ${CUDNN_LIBRARIES}) @@ -167,11 +167,11 @@ if(BUILD_CUDA) list(APPEND oneflow_third_party_dependencies trt_flash_attention) list(APPEND oneflow_third_party_libs ${TRT_FLASH_ATTENTION_LIBRARIES}) list(APPEND ONEFLOW_THIRD_PARTY_INCLUDE_DIRS ${TRT_FLASH_ATTENTION_INCLUDE_DIR}) - if(CUDA_VERSION VERSION_GREATER_EQUAL "11.7") - list(APPEND oneflow_third_party_dependencies flash_attention) - list(APPEND oneflow_third_party_libs ${FLASH_ATTENTION_LIBRARIES}) - list(APPEND ONEFLOW_THIRD_PARTY_INCLUDE_DIRS ${FLASH_ATTENTION_INCLUDE_DIR}) - endif() + # if(CUDA_VERSION VERSION_GREATER_EQUAL "11.7") + # list(APPEND oneflow_third_party_dependencies flash_attention) + # list(APPEND oneflow_third_party_libs ${FLASH_ATTENTION_LIBRARIES}) + # list(APPEND ONEFLOW_THIRD_PARTY_INCLUDE_DIRS ${FLASH_ATTENTION_INCLUDE_DIR}) + # endif() endif() if(BUILD_RDMA) diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index 495f6754b7e..98c0654af95 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -20,8 +20,8 @@ set(KINETO_MD5 f9b550591b3899fb267270c19484933f) set(EXTERNAL_TARGETS) if(WITH_TBB) # set(WITH_${threading_runtime_item} ON) in threading.cmake - add_subdirectory(onetbb) - list(APPEND EXTERNAL_TARGETS tbb) + add_subdirectory(onetbb) + list(APPEND EXTERNAL_TARGETS tbb) endif() add_subdirectory(robin-hood-hashing) @@ -33,6 +33,11 @@ list(APPEND EXTERNAL_TARGETS fmt) add_subdirectory(kineto) list(APPEND EXTERNAL_TARGETS kineto) +if(CUDA_VERSION VERSION_GREATER_EQUAL "11.7") + add_subdirectory(flash_attention) + list(APPEND EXTERNAL_TARGETS flash_attention) +endif() + mark_targets_as_system(${EXTERNAL_TARGETS}) set_property(GLOBAL PROPERTY EXTERNAL_TARGETS ${EXTERNAL_TARGETS}) diff --git a/external/flash_attention/CMakeLists.txt b/external/flash_attention/CMakeLists.txt new file mode 100644 index 00000000000..3c51bc93405 --- /dev/null +++ b/external/flash_attention/CMakeLists.txt @@ -0,0 +1,9 @@ +set(FLASH_ATTENTION_URL https://github.com/Oneflow-Inc/flash-attention-v2/archive/eed2e82b880e06237af3e50ceac4cf6728b15645.zip) +use_mirror(VARIABLE FLASH_ATTENTION_URL URL ${FLASH_ATTENTION_URL}) +set(FLASH_ATTENTION_MD5 cff17aa2a95ad754c9889bb3a03d5c51) + +CPMAddPackage( + NAME flash_attention + URL ${FLASH_ATTENTION_URL} + URL_HASH MD5=${FLASH_ATTENTION_MD5} +) \ No newline at end of file