Skip to content

Commit

Permalink
Merge pull request #443 from ValeevGroup/evaleev/feature/modularized-…
Browse files Browse the repository at this point in the history
…boost

modularized boost
  • Loading branch information
evaleev authored Jan 19, 2024
2 parents dee87e8 + 98c6c3b commit c0a88b9
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 142 deletions.
5 changes: 2 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,9 @@ if (ENABLE_WFN91_LINALG_DISCOVERY_KIT)
include(FetchWfn91LinAlgModules)
include(FindLinalg)
endif(ENABLE_WFN91_LINALG_DISCOVERY_KIT)
# BTAS does a better job of building and checking Boost since it uses Boost::serialization
# it also memorized the location of its config for use from install tree
# Boost is to be discovered by the top cmake project, and every (sub)project needs to make sure it has all of its targets
include(external/boost.cmake)
include(${PROJECT_SOURCE_DIR}/cmake/modules/FindOrFetchBTAS.cmake)
include(${PROJECT_SOURCE_DIR}/cmake/modules/FindOrFetchBoost.cmake)
if(ENABLE_SCALAPACK)
include(external/scalapackpp.cmake)
endif()
Expand Down
4 changes: 2 additions & 2 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ Both methods are supported. However, for most users we _strongly_ recommend to b
- Boost.Container: header-only
- Boost.Test: header-only or (optionally) as a compiled library, *only used for unit testing*
- Boost.Range: header-only, *only used for unit testing*
- [BTAS](http://github.com/ValeevGroup/BTAS), tag bf0c376d5cdd6f668174b2a4c67b19634d1c0da7 . If usable BTAS installation is not found, TiledArray will download and compile
- [BTAS](http://github.com/ValeevGroup/BTAS), tag 85eea7796651de1bcb4781b0081a352b32bf91d5 . If usable BTAS installation is not found, TiledArray will download and compile
BTAS from source. *This is the recommended way to compile BTAS for all users*.
- [MADNESS](https://github.com/m-a-d-n-e-s-s/madness), tag b1f1c39c497b86ab3ef4e560a686de63eb555cc4 .
- [MADNESS](https://github.com/m-a-d-n-e-s-s/madness), tag 39de6cb4d262b3df1f67b3c04a37a935564ca657 .
Only the MADworld runtime and BLAS/LAPACK C API component of MADNESS is used by TiledArray.
If usable MADNESS installation is not found, TiledArray will download and compile
MADNESS from source. *This is the recommended way to compile MADNESS for all users*.
Expand Down
21 changes: 1 addition & 20 deletions bin/admin/dependency-versions-update-hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,7 @@ def replace_dep_id(topsrc, file_ext, dep_name, old_id, new_id, search_prefix = '
tokens = line.split()
if len(tokens) < 3:
continue
if tokens[1].find('TRACKED_BOOST') != -1:
if tokens[1].find('PREVIOUS') != -1:
boost_old_version = tokens[2]
else:
boost_new_version = tokens[2]
elif tokens[1].find('INSTALL_BOOST') != -1:
if tokens[1].find('VERSION') != -1:
if tokens[1].find('PREVIOUS') != -1:
boost_old_install_version = tokens[2]
else:
boost_new_install_version = tokens[2]
else: # URL_HASH
if tokens[1].find('PREVIOUS') != -1:
boost_old_install_url_hash = tokens[2]
else:
boost_new_install_url_hash = tokens[2]
elif tokens[1].find('TRACKED_EIGEN') != -1:
if tokens[1].find('TRACKED_EIGEN') != -1:
if tokens[1].find('PREVIOUS') != -1:
eigen_old_version = tokens[2]
else:
Expand Down Expand Up @@ -134,9 +118,6 @@ def replace_dep_id(topsrc, file_ext, dep_name, old_id, new_id, search_prefix = '

any_files_changed = False

# Boost version in INSTALL.md
any_files_changed |= replace_dep_id(topsrc, 'md', 'Boost', boost_old_version, boost_new_version, 'boost.org/), version ', ' or higher')

# Eigen version in INSTALL.md
any_files_changed |= replace_dep_id(topsrc, 'md', 'Eigen', eigen_old_version, eigen_new_version, 'eigen.tuxfamily.org), version ', ' or higher')
# Eigen install version in eigen.cmake
Expand Down
79 changes: 0 additions & 79 deletions cmake/modules/FindOrFetchBoost.cmake

This file was deleted.

10 changes: 8 additions & 2 deletions cmake/tiledarray-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ set(TILEDARRAY_EXT_VERSION "@TILEDARRAY_EXT_VERSION@")

@PACKAGE_INIT@

include(CMakeFindDependencyMacro)

# Include library IMPORT targets

@Boost_CONFIG_FILE_CONTENTS@

if (NOT TARGET BTAS::BTAS)
get_filename_component(BTAS_DIR "@BTAS_CONFIG@" DIRECTORY)
find_package(BTAS 1.0.0 QUIET CONFIG REQUIRED HINTS "${BTAS_DIR}")
find_dependency(BTAS 1.0.0 QUIET CONFIG REQUIRED HINTS "${BTAS_DIR}")
endif()

if(NOT TARGET MADworld)
# if madness installed separately, use the madness install discovered when configuring TA
set(MADNESS_CONFIG_DIR "@MADNESS_CONFIG_DIR@")
Expand All @@ -38,7 +44,7 @@ set(TILEDARRAY_HAS_CUDA "@CUDA_FOUND@")
if(TILEDARRAY_HAS_CUDA)
cmake_minimum_required(VERSION 3.17)
if (NOT TARGET CUDA::cublas)
find_package(CUDAToolkit REQUIRED COMPONENTS cublas nvToolsExt)
find_dependency(CUDAToolkit REQUIRED COMPONENTS cublas nvToolsExt)
endif(NOT TARGET CUDA::cublas)
set(CMAKE_CUDA_HOST_COMPILER "@CMAKE_CUDA_HOST_COMPILER@")
# workaround from https://gitlab.kitware.com/cmake/cmake/issues/18614#note_485631
Expand Down
36 changes: 36 additions & 0 deletions external/boost.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Boost can be discovered by every (sub)package but only the top package can build it ...
# if we are the top package need to include the list of Boost components to be built
if("${CMAKE_PROJECT_NAME}" STREQUAL "${PROJECT_NAME}")
set(required_components
headers # TA, BTAS
algorithm # TA
container # TA, BTAS
iterator # TA, BTAS
random # TA, BTAS
tuple # TA
)
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 "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()
endif()

if (NOT DEFINED Boost_FETCH_IF_MISSING)
set(Boost_FETCH_IF_MISSING 1)
endif()

include(${vg_cmake_kit_SOURCE_DIR}/modules/FindOrFetchBoost.cmake)
18 changes: 5 additions & 13 deletions external/versions.cmake
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
# for each dependency track both current and previous id (the variable for the latter must contain PREVIOUS)
# to be able to auto-update them

set(TA_TRACKED_VGCMAKEKIT_TAG d6746098e63deab4032309c4455bb084a17ff51a)

# Boost explicitly downgraded to 1.59 from 1.68
set(TA_TRACKED_BOOST_VERSION 1.59)
set(TA_TRACKED_BOOST_PREVIOUS_VERSION 1.68)
set(TA_INSTALL_BOOST_VERSION 1.70.0)
set(TA_INSTALL_BOOST_PREVIOUS_VERSION 1.70.0)
set(TA_INSTALL_BOOST_URL_HASH 882b48708d211a5f48e60b0124cf5863c1534cd544ecd0664bb534a4b5d506e9)
set(TA_INSTALL_BOOST_PREVIOUS_URL_HASH 882b48708d211a5f48e60b0124cf5863c1534cd544ecd0664bb534a4b5d506e9)
set(TA_TRACKED_VGCMAKEKIT_TAG 8713beb71ff6b7d4b1c758e9e1c7d814bd97b0af)

# N.B. may need to update INSTALL.md manually with the CUDA-specific version
set(TA_TRACKED_EIGEN_VERSION 3.3.5)
Expand All @@ -19,13 +11,13 @@ set(TA_INSTALL_EIGEN_PREVIOUS_VERSION 3.3.7)
set(TA_INSTALL_EIGEN_URL_HASH SHA256=b4c198460eba6f28d34894e3a5710998818515104d6e74e5cc331ce31e46e626)
set(TA_INSTALL_EIGEN_PREVIOUS_URL_HASH MD5=b9e98a200d2455f06db9c661c5610496)

set(TA_TRACKED_MADNESS_TAG b1f1c39c497b86ab3ef4e560a686de63eb555cc4)
set(TA_TRACKED_MADNESS_PREVIOUS_TAG cf3c98053453329f35b775c8b9f561301f6a997e)
set(TA_TRACKED_MADNESS_TAG 39de6cb4d262b3df1f67b3c04a37a935564ca657)
set(TA_TRACKED_MADNESS_PREVIOUS_TAG 51c2728d664c096d0ea39d3b9cbf2895d8d99439)
set(TA_TRACKED_MADNESS_VERSION 0.10.1)
set(TA_TRACKED_MADNESS_PREVIOUS_VERSION 0.10.1)

set(TA_TRACKED_BTAS_TAG bf0c376d5cdd6f668174b2a4c67b19634d1c0da7)
set(TA_TRACKED_BTAS_PREVIOUS_TAG 3c91f086090390930bba62c6512c4e74a5520e76)
set(TA_TRACKED_BTAS_TAG 85eea7796651de1bcb4781b0081a352b32bf91d5)
set(TA_TRACKED_BTAS_PREVIOUS_TAG bf0c376d5cdd6f668174b2a4c67b19634d1c0da7)

set(TA_TRACKED_LIBRETT_TAG 6eed30d4dd2a5aa58840fe895dcffd80be7fbece)
set(TA_TRACKED_LIBRETT_PREVIOUS_TAG 354e0ccee54aeb2f191c3ce2c617ebf437e49d83)
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ add_library(tiledarray ${TILEDARRAY_SOURCE_FILES} ${TILEDARRAY_HEADER_FILES})

target_link_libraries(${targetname} PUBLIC ${TILEDARRAY_PRIVATE_LINK_LIBRARIES})
target_link_libraries(${targetname} PUBLIC MADworld)
target_link_libraries(${targetname} PUBLIC Boost::boost)
target_link_libraries(${targetname} PUBLIC Boost::headers)

# build all external deps before building tiledarray
add_dependencies(${targetname} External-tiledarray)
Expand Down
16 changes: 14 additions & 2 deletions src/TiledArray/tiled_range.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,18 @@ class TiledRange {
return result;
}

/// Convert an element index to a tile index

/// \tparam Integer An integral type
/// \param index The element index to convert
/// \return The tile index that corresponds to the given element index
template <typename Integer,
typename = std::enable_if_t<std::is_integral_v<Integer>>>
typename range_type::index element_to_tile(
const std::initializer_list<Integer>& index) const {
return this->element_to_tile<std::initializer_list<Integer>>(index);
}

/// The rank accessor

/// \return the rank (=number of dimensions) of this object
Expand Down Expand Up @@ -316,14 +328,14 @@ class TiledRange {
typename std::enable_if<madness::is_input_archive_v<
std::decay_t<Archive>>>::type* = nullptr>
void serialize(Archive& ar) {
ar& range_& elements_range_& ranges_;
ar & range_ & elements_range_ & ranges_;
}

template <typename Archive,
typename std::enable_if<madness::is_output_archive_v<
std::decay_t<Archive>>>::type* = nullptr>
void serialize(Archive& ar) const {
ar& range_& elements_range_& ranges_;
ar & range_ & elements_range_ & ranges_;
}

private:
Expand Down
34 changes: 22 additions & 12 deletions src/TiledArray/tiled_range1.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
#include <TiledArray/type_traits.h>
#include <TiledArray/utility.h>
#include <madness/world/archive.h>

#include <cassert>
#include <initializer_list>
#include <memory>
#include <mutex>
#include <vector>

Expand Down Expand Up @@ -56,8 +58,7 @@ class TiledRange1 {
/// assert(tr.elements_range() == (TiledRange1::range_type{0,0}));
/// assert(tr.begin() == tr.end());
/// \endcode
TiledRange1()
: range_(0, 0), elements_range_(0, 0), tiles_ranges_(), elem2tile_() {}
TiledRange1() : range_(0, 0), elements_range_(0, 0) {}

/// Constructs a range with the tile boundaries ("hashmarks") provided by
/// the range [ \p first , \p last ).
Expand All @@ -66,8 +67,7 @@ class TiledRange1 {
template <typename RandIter,
typename std::enable_if<
detail::is_random_iterator<RandIter>::value>::type* = nullptr>
explicit TiledRange1(RandIter first, RandIter last)
: range_(), elements_range_(), tiles_ranges_(), elem2tile_() {
explicit TiledRange1(RandIter first, RandIter last) {
init_tiles_(first, last, 0);
}

Expand Down Expand Up @@ -227,7 +227,7 @@ class TiledRange1 {
/// across ALL TiledRange1 instances.
const index1_type& element_to_tile(const index1_type& i) const {
TA_ASSERT(includes(elements_range_, i));
if (elem2tile_.empty()) {
if (!elem2tile_) {
init_elem2tile_();
}
return elem2tile_[i - elements_range_.first];
Expand Down Expand Up @@ -290,14 +290,14 @@ class TiledRange1 {
typename std::enable_if<madness::is_input_archive_v<
std::decay_t<Archive>>>::type* = nullptr>
void serialize(Archive& ar) {
ar& range_& elements_range_& tiles_ranges_& elem2tile_;
ar & range_ & elements_range_ & tiles_ranges_;
}

template <typename Archive,
typename std::enable_if<madness::is_output_archive_v<
std::decay_t<Archive>>>::type* = nullptr>
void serialize(Archive& ar) const {
ar& range_& elements_range_& tiles_ranges_& elem2tile_;
ar & range_ & elements_range_ & tiles_ranges_;
}

private:
Expand Down Expand Up @@ -345,19 +345,29 @@ class TiledRange1 {
void init_elem2tile_() const {
using TiledArray::extent;
// check for 0 size range.
if (extent(elements_range_) == 0) return;
const auto n = extent(elements_range_);
if (n == 0) return;

static std::mutex mtx;
{
std::lock_guard<std::mutex> lock(mtx);
if (elem2tile_.empty()) {
if (!elem2tile_) {
// initialize elem2tile map
elem2tile_.resize(extent(elements_range_));
auto e2t =
// #if __cplusplus >= 202002L ... still broken in Xcode 14
// std::make_shared<index1_type[]>(n);
// #else
std::shared_ptr<index1_type[]>(
new index1_type[n], [](index1_type* ptr) { delete[] ptr; });
// #endif
const auto end = extent(range_);
for (index1_type t = 0; t < end; ++t)
for (index1_type e = tiles_ranges_[t].first;
e < tiles_ranges_[t].second; ++e)
elem2tile_[e - elements_range_.first] = t + range_.first;
e2t[e - elements_range_.first] = t + range_.first;
auto e2t_const = std::const_pointer_cast<const index1_type[]>(e2t);
// commit the changes
std::swap(elem2tile_, e2t_const);
}
}
}
Expand All @@ -369,7 +379,7 @@ class TiledRange1 {
range_type elements_range_; ///< the range of element indices
std::vector<range_type>
tiles_ranges_; ///< ranges of each tile (NO GAPS between tiles)
mutable std::vector<index1_type>
mutable std::shared_ptr<const index1_type[]>
elem2tile_; ///< maps element index to tile index (memoized data).

}; // class TiledRange1
Expand Down
Loading

0 comments on commit c0a88b9

Please sign in to comment.