diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index e732ed5d..58452528 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -58,7 +58,7 @@ jobs: if: ${{ matrix.os == 'ubuntu-20.04' }} run: | sudo apt-get update - sudo apt-get install ninja-build g++-9 liblapack-dev libboost-dev libboost-serialization-dev libeigen3-dev openmpi-bin libopenmpi-dev libtbb-dev ccache + sudo apt-get install ninja-build g++-9 liblapack-dev libboost-dev libboost-serialization-dev libboost-random-dev libeigen3-dev openmpi-bin libopenmpi-dev libtbb-dev ccache if [ "${{matrix.build_type}}" = "Release" ]; then sudo apt-get install libclang1-9 libclang-cpp9 graphviz fonts-liberation cd ${{github.workspace}}/build @@ -80,6 +80,7 @@ jobs: sudo apt-get install intel-oneapi-mkl-devel echo "BLAS_PREFERENCE_LIST=IntelMKL" >> $GITHUB_ENV echo "MKLROOT=/opt/intel/oneapi/mkl/latest" >> $GITHUB_ENV + echo "MKL_NUM_THREADS=1" >> $GITHUB_ENV else echo "BLAS_PREFERENCE_LIST=ReferenceBLAS" >> $GITHUB_ENV fi diff --git a/CMakeLists.txt b/CMakeLists.txt index a367abb9..fb714ec9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -225,8 +225,11 @@ add_custom_target_subproject(btas install-config COMMAND ${CMAKE_COMMAND} -DCOMPONENT=btas-config -P ${PROJECT_BINARY_DIR}/cmake_install.cmake COMMENT "Installing BTAS config components") -feature_summary(WHAT ALL - DESCRIPTION "=== BTAS Package/Feature Info ===") +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) + feature_summary(WHAT ALL + DESCRIPTION "=== BTAS Package/Feature Info ===") + feature_summary(FILENAME ${CMAKE_CURRENT_BINARY_DIR}/features.log WHAT ALL) +endif() ############################################################################### # appendix: misc details diff --git a/btas/generic/cp_als.h b/btas/generic/cp_als.h index b10fd6af..592af8ba 100644 --- a/btas/generic/cp_als.h +++ b/btas/generic/cp_als.h @@ -659,7 +659,6 @@ namespace btas { double lambda = 0) { Tensor temp(A[n].extent(0), rank); Tensor an(A[n].range()); - // Testing the code to see if pivoted QR can help if (false) { // First create a Pivot matrix from the flattened tensor_ref @@ -795,10 +794,6 @@ namespace btas { } KRP_dims.push_back(ndim); contract(this->one, tensor_ref, tref_indices, KhatriRao, KRP_dims, this->zero, temp, An_indices); - - // without MKL program cannot perform the swapping algorithm, must compute - // flattened intermediate -// gemm(blas::Op::NoTrans, blas::Op::NoTrans, this->one, new_flatten(tensor_ref, n), this->generate_KRP(n, rank, true), this->zero, temp); #endif if(lambda != 0){ diff --git a/cmake/btas-config.cmake.in b/cmake/btas-config.cmake.in index 2259b169..26a4db67 100644 --- a/cmake/btas-config.cmake.in +++ b/cmake/btas-config.cmake.in @@ -16,44 +16,7 @@ set(BTAS_EXT_VERSION "@BTAS_EXT_VERSION@") @PACKAGE_INIT@ -# import boost components, if any missing -set(Boost_BTAS_DEPS_LIBRARIES @Boost_BTAS_DEPS_LIBRARIES@) -foreach(_deplib ${Boost_BTAS_DEPS_LIBRARIES}) - if (DEFINED Boost_BTAS_DEPS_LIBRARIES_NOT_FOUND_CHECK) - list(APPEND Boost_BTAS_DEPS_LIBRARIES_NOT_FOUND_CHECK OR) - endif() - list(APPEND Boost_BTAS_DEPS_LIBRARIES_NOT_FOUND_CHECK "NOT;TARGET;Boost::${_deplib}") -endforeach(_deplib) -if (NOT DEFINED Boost_BTAS_DEPS_LIBRARIES_NOT_FOUND_CHECK) - list(APPEND Boost_BTAS_DEPS_LIBRARIES_NOT_FOUND_CHECK "NOT;TARGET;Boost::boost") -endif (NOT DEFINED Boost_BTAS_DEPS_LIBRARIES_NOT_FOUND_CHECK) - -if(${Boost_BTAS_DEPS_LIBRARIES_NOT_FOUND_CHECK}) - set(Boost_USE_CONFIG @Boost_USE_CONFIG@) - # OPTIONAL_COMPONENTS in FindBoost available since 3.11 - cmake_minimum_required(VERSION 3.11.0) - if (Boost_USE_CONFIG) - set(Boost_CONFIG @Boost_CONFIG@) - if (NOT Boost_CONFIG OR NOT EXISTS ${Boost_CONFIG}) - message(FATAL_ERROR "Expected Boost config file at ${Boost_CONFIG}; directory moved since BTAS configuration?") - endif() - get_filename_component(Boost_DIR ${Boost_CONFIG} DIRECTORY) - find_package(Boost CONFIG QUIET REQUIRED OPTIONAL_COMPONENTS ${Boost_BTAS_DEPS_LIBRARIES} PATHS ${Boost_DIR} NO_DEFAULT_PATH) - else (Boost_USE_CONFIG) - set(BOOST_INCLUDEDIR @Boost_INCLUDE_DIR@) - set(BOOST_LIBRARYDIR @Boost_LIBRARY_DIR_RELEASE@) - if (NOT BOOST_LIBRARYDIR OR NOT EXISTS ${BOOST_LIBRARYDIR}) - set(BOOST_LIBRARYDIR @Boost_LIBRARY_DIR_DEBUG@) - endif() - set(Boost_NO_SYSTEM_PATHS OFF) - if (BOOST_LIBRARYDIR AND BOOST_INCLUDEDIR) - if (EXISTS ${BOOST_LIBRARYDIR} AND EXISTS ${BOOST_INCLUDEDIR}) - set(Boost_NO_SYSTEM_PATHS ON) - endif() - endif() - find_package(Boost QUIET REQUIRED OPTIONAL_COMPONENTS ${Boost_BTAS_DEPS_LIBRARIES}) - endif (Boost_USE_CONFIG) -endif(${Boost_BTAS_DEPS_LIBRARIES_NOT_FOUND_CHECK}) +@Boost_CONFIG_FILE_CONTENTS@ # find linalgpp dependencies if(NOT TARGET blaspp) diff --git a/cmake/modules/FindOrFetchBoost.cmake b/cmake/modules/FindOrFetchBoost.cmake deleted file mode 100644 index c0b24b5f..00000000 --- a/cmake/modules/FindOrFetchBoost.cmake +++ /dev/null @@ -1,25 +0,0 @@ -if (NOT TARGET Boost::boost) - include (FetchContent) - cmake_minimum_required (VERSION 3.14.0) # for FetchContent_MakeAvailable - - FetchContent_Declare( - CMAKEBOOST - GIT_REPOSITORY https://github.com/Orphis/boost-cmake - ) - FetchContent_MakeAvailable(CMAKEBOOST) - FetchContent_GetProperties(CMAKEBOOST - SOURCE_DIR CMAKEBOOST_SOURCE_DIR - BINARY_DIR CMAKEBOOST_BINARY_DIR - ) - - # current boost-cmake/master does not install boost correctly, so warn that installed BTAS will not be usable - # boost-cmake/install_rules https://github.com/Orphis/boost-cmake/pull/45 is supposed to fix it but is inactive - message(WARNING "Building Boost from source makes BTAS unusable from the install location! Install Boost using package manager or manually and reconfigure/reinstall BTAS to fix this") - install(TARGETS Boost_serialization EXPORT btas COMPONENT boost-libs) - -endif(NOT TARGET Boost::boost) - -# postcond check -if (NOT TARGET Boost::boost) - message(FATAL_ERROR "FindOrFetchBoost could not make Boost::boost target available") -endif(NOT TARGET Boost::boost) diff --git a/external/boost.cmake b/external/boost.cmake index 9570bb53..1611011c 100644 --- a/external/boost.cmake +++ b/external/boost.cmake @@ -1,63 +1,39 @@ # -*- mode: cmake -*- -# Limit scope of the search if BOOST_ROOT or BOOST_INCLUDEDIR is provided. -if (BOOST_ROOT OR BOOST_INCLUDEDIR) - set(Boost_NO_SYSTEM_PATHS TRUE) +# Boost can be discovered by every (sub)package but only the top package can *build* it ... +# in either case must declare the components used by BTAS +set(required_components + headers # BTAS + container # BTAS + iterator # BTAS + random # BTAS +) +if (DEFINED Boost_REQUIRED_COMPONENTS) + list(APPEND Boost_REQUIRED_COMPONENTS ${required_components}) + list(REMOVE_DUPLICATES Boost_REQUIRED_COMPONENTS) +else() + set(Boost_REQUIRED_COMPONENTS "${required_components}" CACHE STRING "Required components of Boost to discovered or built") +endif() +set(optional_components + serialization # BTAS +) +if (DEFINED Boost_OPTIONAL_COMPONENTS) + list(APPEND Boost_OPTIONAL_COMPONENTS ${optional_components}) + list(REMOVE_DUPLICATES Boost_OPTIONAL_COMPONENTS) +else() + set(Boost_OPTIONAL_COMPONENTS "${optional_components}" CACHE STRING "Optional components of Boost to discovered or built") endif() -# make sure Boost::boost is available, and look for optional serialization component -if (NOT TARGET Boost::boost OR NOT TARGET Boost::serialization) - list(APPEND Boost_BTAS_DEPS_LIBRARIES serialization) - - # detect which Boost targets I already have - foreach(tgt boost;headers;${Boost_BTAS_DEPS_LIBRARIES}) - if (TARGET Boost::${tgt}) - set(btas_imported_boost_${tgt} 0) - else() - set(btas_imported_boost_${tgt} 1) - endif() - endforeach() - - # try config first - # OPTIONAL_COMPONENTS in FindBoost available since 3.11 - cmake_minimum_required(VERSION 3.11.0) - find_package(Boost ${BTAS_TRACKED_BOOST_VERSION} CONFIG OPTIONAL_COMPONENTS ${Boost_BTAS_DEPS_LIBRARIES}) - if (NOT TARGET Boost::boost) - find_package(Boost ${BTAS_TRACKED_BOOST_VERSION} OPTIONAL_COMPONENTS ${Boost_BTAS_DEPS_LIBRARIES}) - if (TARGET Boost::boost) - set(Boost_USE_CONFIG FALSE) - endif(TARGET Boost::boost) - else() - set(Boost_USE_CONFIG TRUE) - endif() - - # Boost::* targets by default are not GLOBAL, so to allow users of LINALG_LIBRARIES to safely use them we need to make them global - # more discussion here: https://gitlab.kitware.com/cmake/cmake/-/issues/17256 - foreach(tgt boost;headers;${Boost_BTAS_DEPS_LIBRARIES}) - if (TARGET Boost::${tgt} AND btas_imported_boost_${tgt}) - get_target_property(_boost_tgt_${tgt}_is_imported_global Boost::${tgt} IMPORTED_GLOBAL) - if (NOT _boost_tgt_${tgt}_is_imported_global) - set_target_properties(Boost::${tgt} PROPERTIES IMPORTED_GLOBAL TRUE) - endif() - unset(_boost_tgt_${tgt}_is_imported_global) - endif() - endforeach() - -endif (NOT TARGET Boost::boost OR NOT TARGET Boost::serialization) - -# if Boost not found, and BTAS_BUILD_DEPS_FROM_SOURCE=ON, use FetchContent to build it -set(BTAS_BUILT_BOOST_FROM_SOURCE 0) -if (NOT TARGET Boost::boost) - if (BTAS_BUILD_DEPS_FROM_SOURCE) - include(${PROJECT_SOURCE_DIR}/cmake/modules/FindOrFetchBoost.cmake) - set(BTAS_BUILT_BOOST_FROM_SOURCE 1) - else(BTAS_BUILD_DEPS_FROM_SOURCE) - message(FATAL_ERROR "Boost is a required prerequisite of BTAS, but not found; install Boost or set BTAS_BUILD_DEPS_FROM_SOURCE=ON to obtain from source") - endif(BTAS_BUILD_DEPS_FROM_SOURCE) -endif (NOT TARGET Boost::boost) +if (BTAS_BUILD_DEPS_FROM_SOURCE AND NOT DEFINED Boost_FETCH_IF_MISSING) + set(Boost_FETCH_IF_MISSING 1) +endif() +include(${vg_cmake_kit_SOURCE_DIR}/modules/FindOrFetchBoost.cmake) +if (DEFINED Boost_SOURCE_DIR) + set(BTAS_BUILT_BOOST_FROM_SOURCE 1) +endif() # make BTAS depend on Boost -set(Boost_LIBRARIES Boost::boost) +set(Boost_LIBRARIES Boost::headers;Boost::random) if (TARGET Boost::serialization) list(APPEND Boost_LIBRARIES Boost::serialization) target_compile_definitions(BTAS INTERFACE -DBTAS_HAS_BOOST_SERIALIZATION=1) diff --git a/external/versions.cmake b/external/versions.cmake index 2c955352..cf7f8470 100644 --- a/external/versions.cmake +++ b/external/versions.cmake @@ -1,4 +1,4 @@ -set(BTAS_TRACKED_VGCMAKEKIT_TAG d6746098e63deab4032309c4455bb084a17ff51a) +set(BTAS_TRACKED_VGCMAKEKIT_TAG 45e7d0d8d7f994a88c5af5fc082332db7bd0d6b3) # likely can use earlier, but # - as of oct 2023 tested with 1.71 and up only diff --git a/unittest/ztensor_cp_test.cc b/unittest/ztensor_cp_test.cc index f7c26732..d523b0f9 100644 --- a/unittest/ztensor_cp_test.cc +++ b/unittest/ztensor_cp_test.cc @@ -146,13 +146,13 @@ TEST_CASE("ZCP") { SECTION("RALS MODE = 4, Finite rank") { CP_RALS A1(Z4); conv.set_norm(norm4.real()); - double diff = A1.compute_rank(65, conv, 1, true, 65); + double diff = A1.compute_rank(67, conv, 1, true, 65); CHECK(std::abs(diff) <= epsilon); } SECTION("RALS MODE = 4, Finite error"){ CP_RALS A1(Z4); conv.set_norm(norm4.real()); - double diff = A1.compute_error(conv, 1e-2, 1, 67, true, 65); + double diff = A1.compute_error(conv, 1e-5, 1, 67, true, 65); CHECK(std::abs(diff) <= epsilon); } #if BTAS_ENABLE_TUCKER_CP_UT