From 04eb8a285d033def56fa15cc0fbd6c406dc935a2 Mon Sep 17 00:00:00 2001 From: Hui Zhang Date: Mon, 7 Mar 2022 07:01:38 +0000 Subject: [PATCH] openblas cmake --- speechx/CMakeLists.txt | 30 ++++----------- speechx/build.sh | 5 ++- speechx/cmake/external/absl.cmake | 5 +++ speechx/cmake/external/gtest.cmake | 1 + speechx/cmake/external/openblas.cmake | 53 +++++++++++++++++++++++++++ 5 files changed, 69 insertions(+), 25 deletions(-) create mode 100644 speechx/cmake/external/openblas.cmake diff --git a/speechx/CMakeLists.txt b/speechx/CMakeLists.txt index 494b08d0..34b90116 100644 --- a/speechx/CMakeLists.txt +++ b/speechx/CMakeLists.txt @@ -26,6 +26,9 @@ set(FETCHCONTENT_BASE_DIR ${fc_patch}) # compiler option set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++14 -pthread -fPIC -O0 -Wall -g") +SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} --std=c++14 -pthread -fPIC -O0 -Wall -g -ggdb") +SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} --std=c++14 -pthread -fPIC -O3 -Wall") + ############################################################################### # Option Configurations ############################################################################### @@ -134,29 +137,10 @@ set(DEPS ${DEPS} ${EXTERNAL_LIB}) #openblas -set(OpenBLAS_INSTALL_PREFIX ${fc_patch}/openblas-install) -#set(OpenBLAS_INSTALL_PREFIX ${fc_patch}/OpenBLAS) -#set(OpenBLAS_SOURCE_DIR ${fc_patch}/OpenBLAS-src) -#set(OpenBLAS_PREFIX ${fc_patch}/OpenBLAS-prefix) -#ExternalProject_Add( - #OpenBLAS - #GIT_REPOSITORY https://github.com/xianyi/OpenBLAS - #GIT_TAG 1ef97c470ccf23d06d3bb0597c52df4a2e9093b9 - #GIT_SHALLOW TRUE - #GIT_PROGRESS TRUE - #PREFIX ${OpenBLAS_PREFIX} - #SOURCE_DIR ${OpenBLAS_SOURCE_DIR} - #BUILD_IN_SOURCE TRUE - #CONFIGURE_COMMAND "" - #BUILD_COMMAND make - #INSTALL_COMMAND make PREFIX=${OpenBLAS_INSTALL_PREFIX} install - #UPDATE_DISCONNECTED TRUE -#) -link_directories(${OpenBLAS_INSTALL_PREFIX}/lib) -include_directories(${OpenBLAS_INSTALL_PREFIX}/include) - -# gfortan dir in the docker. -link_directories(/usr/local/gcc-8.2/lib64) +include(openblas) + +# openblas need, gfortan dir in the docker. +#link_directories(/usr/local/gcc-8.2/lib64) ############################################################################### # Add local library diff --git a/speechx/build.sh b/speechx/build.sh index a5c93267..15caa18a 100755 --- a/speechx/build.sh +++ b/speechx/build.sh @@ -16,11 +16,12 @@ if [ ! -d ${boost_SOURCE_DIR} ]; then wget -c https://boostorg.jfrog.io/artifact echo -e "\n" fi +rm -rf build mkdir -p build cd build -cmake .. -DBOOST_ROOT:STRING=${boost_SOURCE_DIR} --target clean +cmake .. -DBOOST_ROOT:STRING=${boost_SOURCE_DIR} -make +make -j cd - diff --git a/speechx/cmake/external/absl.cmake b/speechx/cmake/external/absl.cmake index b22e56d8..2c5e5af5 100644 --- a/speechx/cmake/external/absl.cmake +++ b/speechx/cmake/external/absl.cmake @@ -1,5 +1,10 @@ include(FetchContent) + +set(BUILD_SHARED_LIBS OFF) # up to you +set(BUILD_TESTING OFF) # to disable abseil test, or gtest will fail. +set(ABSL_ENABLE_INSTALL ON) # now you can enable install rules even in subproject... + FetchContent_Declare( absl GIT_REPOSITORY "https://github.com/abseil/abseil-cpp.git" diff --git a/speechx/cmake/external/gtest.cmake b/speechx/cmake/external/gtest.cmake index da6f7cc5..7fe397fc 100644 --- a/speechx/cmake/external/gtest.cmake +++ b/speechx/cmake/external/gtest.cmake @@ -5,4 +5,5 @@ FetchContent_Declare( URL_HASH SHA256=94c634d499558a76fa649edb13721dce6e98fb1e7018dfaeba3cd7a083945e91 ) FetchContent_MakeAvailable(gtest) + include_directories(${gtest_BINARY_DIR} ${gtest_SOURCE_DIR}/src) \ No newline at end of file diff --git a/speechx/cmake/external/openblas.cmake b/speechx/cmake/external/openblas.cmake new file mode 100644 index 00000000..141860fe --- /dev/null +++ b/speechx/cmake/external/openblas.cmake @@ -0,0 +1,53 @@ +include(FetchContent) + +# set(OpenBLAS_INSTALL_PREFIX ${fc_patch}/openblas-install) +# set(OpenBLAS_INSTALL_PREFIX ${fc_patch}/OpenBLAS) + +set(OpenBLAS_SOURCE_DIR ${fc_patch}/OpenBLAS-src) +set(OpenBLAS_PREFIX ${fc_patch}/OpenBLAS-prefix) + +# ExternalProject_Add( +# OpenBLAS +# GIT_REPOSITORY https://github.com/xianyi/OpenBLAS +# GIT_TAG 1ef97c470ccf23d06d3bb0597c52df4a2e9093b9 +# GIT_SHALLOW TRUE +# GIT_PROGRESS TRUE +# PREFIX ${OpenBLAS_PREFIX} +# SOURCE_DIR ${OpenBLAS_SOURCE_DIR} +# BUILD_IN_SOURCE TRUE +# CONFIGURE_COMMAND "" +# BUILD_COMMAND make +# INSTALL_COMMAND make PREFIX=${OpenBLAS_INSTALL_PREFIX} install +# UPDATE_DISCONNECTED TRUE +# ) + +# ###################################################################################################################### +# OPENBLAS https://github.com/lattice/quda/blob/develop/CMakeLists.txt#L575 +# ###################################################################################################################### +enable_language(Fortran) +#TODO: switch to CPM +include(GNUInstallDirs) +ExternalProject_Add( + OPENBLAS + GIT_REPOSITORY https://github.com/xianyi/OpenBLAS.git + GIT_TAG v0.3.10 + GIT_SHALLOW YES + PREFIX ${OpenBLAS_PREFIX} + SOURCE_DIR ${OpenBLAS_SOURCE_DIR} + CMAKE_ARGS -DCMAKE_INSTALL_PREFIX= + CMAKE_GENERATOR "Unix Makefiles") +# https://cmake.org/cmake/help/latest/module/ExternalProject.html?highlight=externalproject_get_property#external-project-definition +ExternalProject_Get_Property(OPENBLAS INSTALL_DIR) +set(OpenBLAS_INSTALL_PREFIX ${INSTALL_DIR}) +add_library(openblas STATIC IMPORTED) +add_dependencies(openblas OPENBLAS) +set_target_properties(openblas PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES Fortran) +# ${CMAKE_INSTALL_LIBDIR} lib +set_target_properties(openblas PROPERTIES IMPORTED_LOCATION ${OpenBLAS_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/libopenblas.a) + + +# https://cmake.org/cmake/help/latest/command/install.html?highlight=cmake_install_libdir#installing-targets +# ${CMAKE_INSTALL_LIBDIR} lib +# ${CMAKE_INSTALL_INCLUDEDIR} include +link_directories(${OpenBLAS_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}) +include_directories(${OpenBLAS_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}) \ No newline at end of file