Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/enable_sigma.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set(ENABLE_SIGMA ON)
10 changes: 10 additions & 0 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,13 @@ jobs:
compilers: '["gcc-11", "clang-14"]'
doc_target: 'tensorwrapper_cxx_api'
secrets: inherit
Test-Enable-Sigma:
uses: NWChemEx/.github/.github/workflows/common_pull_request.yaml@master
with:
config_file: ''
source_dir: ''
format_python: false
compilers: '["gcc-11", "clang-14"]'
repo_toolchain: ".github/enable_sigma.cmake"
doc_target: ''
secrets: inherit
46 changes: 19 additions & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,57 +36,49 @@ nwx_cxx_api_docs("${project_inc_dir}" "${project_src_dir}")
cmaize_option_list(
BUILD_TESTING OFF "Should we build the tests?"
BUILD_PYBIND11_PYBINDINGS OFF "Should we build Python3 bindings?"
ENABLE_EIGEN_SUPPORT ON "Should we enable Eigen support?"
ENABLE_SIGMA OFF "Should we enable Sigma for uncertainty tracking?"
)

configure_file(cmake/config.hpp.in config.hpp @ONLY)
### Dependendencies ###
include(get_utilities)

cmaize_find_or_build_dependency(
utilities
URL github.com/NWChemEx/utilities
BUILD_TARGET utilities
FIND_TARGET nwx::utilities
CMAKE_ARGS BUILD_TESTING=OFF
)

cmaize_find_or_build_dependency(
parallelzone
URL github.com/NWChemEx/ParallelZone
BUILD_TARGET parallelzone
FIND_TARGET nwx::parallelzone
CMAKE_ARGS BUILD_TESTING=OFF
)
include(get_parallelzone)

find_package(Boost REQUIRED)

cmaize_find_or_build_optional_dependency(
cmaize_find_or_build_dependency(
eigen
ENABLE_EIGEN_SUPPORT
URL https://www.gitlab.com/libeigen/eigen
VERSION 2e76277bd049f7bec36b0f908c69734a42c5234f
BUILD_TARGET eigen
FIND_TARGET Eigen3::Eigen
)

cmaize_find_or_build_optional_dependency(
sigma
ENABLE_SIGMA
URL github.com/QCUncertainty/sigma
VERSION ad74a8305c615a825919b3ad067fdcdf4e578ed0
BUILD_TARGET sigma
FIND_TARGET sigma::sigma
CMAKE_ARGS BUILD_TESTING=OFF
ENABLE_EIGEN_SUPPORT=ON
)

cmaize_add_library(
${PROJECT_NAME}
SOURCE_DIR "${project_src_dir}"
INCLUDE_DIRS "${project_inc_dir}"
DEPENDS utilities parallelzone Boost::boost eigen
DEPENDS utilities parallelzone Boost::boost eigen sigma
)
target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_BINARY_DIR}")

if("${BUILD_TESTING}")
set(cxx_test_dir "${CMAKE_CURRENT_LIST_DIR}/tests/cxx")
set(cxx_unit_test_dir "${cxx_test_dir}/unit_tests/${PROJECT_NAME}")

cmaize_find_or_build_dependency(
Catch2
URL github.com/catchorg/Catch2
BUILD_TARGET Catch2
FIND_TARGET Catch2::Catch2
VERSION v3.6.0
)
include(get_catch2)

cmaize_add_tests(
test_unit_${PROJECT_NAME}
SOURCE_DIR "${cxx_unit_test_dir}"
Expand Down
13 changes: 0 additions & 13 deletions cmake/config.hpp.in

This file was deleted.

39 changes: 24 additions & 15 deletions include/tensorwrapper/allocator/eigen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
#include <tensorwrapper/allocator/replicated.hpp>
#include <tensorwrapper/buffer/buffer_fwd.hpp>

#ifdef ENABLE_SIGMA
#include <sigma/sigma.hpp>
#endif

namespace tensorwrapper::allocator {

/** @brief Used to allocate buffers which rely on Eigen tensors.
Expand Down Expand Up @@ -264,21 +268,26 @@ class Eigen : public Replicated {
// -- Explicit class template declarations
// -----------------------------------------------------------------------------

#define DECLARE_EIGEN_ALLOCATOR(RANK) \
extern template class Eigen<float, RANK>; \
extern template class Eigen<double, RANK>

DECLARE_EIGEN_ALLOCATOR(0);
DECLARE_EIGEN_ALLOCATOR(1);
DECLARE_EIGEN_ALLOCATOR(2);
DECLARE_EIGEN_ALLOCATOR(3);
DECLARE_EIGEN_ALLOCATOR(4);
DECLARE_EIGEN_ALLOCATOR(5);
DECLARE_EIGEN_ALLOCATOR(6);
DECLARE_EIGEN_ALLOCATOR(7);
DECLARE_EIGEN_ALLOCATOR(8);
DECLARE_EIGEN_ALLOCATOR(9);
DECLARE_EIGEN_ALLOCATOR(10);
#define DECLARE_EIGEN_ALLOCATOR(TYPE) \
extern template class Eigen<TYPE, 0>; \
extern template class Eigen<TYPE, 1>; \
extern template class Eigen<TYPE, 2>; \
extern template class Eigen<TYPE, 3>; \
extern template class Eigen<TYPE, 4>; \
extern template class Eigen<TYPE, 5>; \
extern template class Eigen<TYPE, 6>; \
extern template class Eigen<TYPE, 7>; \
extern template class Eigen<TYPE, 8>; \
extern template class Eigen<TYPE, 9>; \
extern template class Eigen<TYPE, 10>

DECLARE_EIGEN_ALLOCATOR(float);
DECLARE_EIGEN_ALLOCATOR(double);

#ifdef ENABLE_SIGMA
DECLARE_EIGEN_ALLOCATOR(sigma::UFloat);
DECLARE_EIGEN_ALLOCATOR(sigma::UDouble);
#endif

#undef DECLARE_EIGEN_ALLOCATOR

Expand Down
12 changes: 0 additions & 12 deletions include/tensorwrapper/backends/eigen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,11 @@
*/

#pragma once
#include "config.hpp"
#ifdef TENSORWRAPPER_HAS_EIGEN
#include <unsupported/Eigen/CXX11/Tensor>
#endif

namespace tensorwrapper::eigen {

#ifdef TENSORWRAPPER_HAS_EIGEN

template<typename FloatType, unsigned short Rank>
using data_type = Eigen::Tensor<FloatType, int(Rank), Eigen::RowMajor>;

#else

template<typename, unsigned short>
using data_type = std::nullptr_t;

#endif

} // namespace tensorwrapper::eigen
45 changes: 29 additions & 16 deletions include/tensorwrapper/buffer/eigen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
#include <tensorwrapper/backends/eigen.hpp>
#include <tensorwrapper/buffer/replicated.hpp>

#ifdef ENABLE_SIGMA
#include <sigma/sigma.hpp>
#endif

namespace tensorwrapper::buffer {

/** @brief A buffer which wraps an Eigen tensor.
Expand Down Expand Up @@ -144,6 +148,10 @@ class Eigen : public Replicated {
* Two Eigen objects are value equal if they both have the same layout and
* they both have the same values.
*
* @note For tensors where the @p FloatType is an uncertain floating point
* number, the tensors are required to have the same sources of
* uncertainty.
*
* @param[in] rhs The object to compare against.
*
* @return True if *this is value equal to @p rhs and false otherwise.
Expand All @@ -153,7 +161,7 @@ class Eigen : public Replicated {
bool operator==(const Eigen& rhs) const noexcept {
if(my_base_type::operator!=(rhs)) return false;
eigen::data_type<FloatType, 0> r = (m_tensor_ - rhs.m_tensor_).sum();
return r() == 0.0;
return r() == FloatType(0.0);
}

/** @brief Is *this different from @p rhs?
Expand Down Expand Up @@ -217,21 +225,26 @@ class Eigen : public Replicated {
data_type m_tensor_;
};

#define DECLARE_EIGEN_BUFFER(RANK) \
extern template class Eigen<float, RANK>; \
extern template class Eigen<double, RANK>

DECLARE_EIGEN_BUFFER(0);
DECLARE_EIGEN_BUFFER(1);
DECLARE_EIGEN_BUFFER(2);
DECLARE_EIGEN_BUFFER(3);
DECLARE_EIGEN_BUFFER(4);
DECLARE_EIGEN_BUFFER(5);
DECLARE_EIGEN_BUFFER(6);
DECLARE_EIGEN_BUFFER(7);
DECLARE_EIGEN_BUFFER(8);
DECLARE_EIGEN_BUFFER(9);
DECLARE_EIGEN_BUFFER(10);
#define DECLARE_EIGEN_BUFFER(TYPE) \
extern template class Eigen<TYPE, 0>; \
extern template class Eigen<TYPE, 1>; \
extern template class Eigen<TYPE, 2>; \
extern template class Eigen<TYPE, 3>; \
extern template class Eigen<TYPE, 4>; \
extern template class Eigen<TYPE, 5>; \
extern template class Eigen<TYPE, 6>; \
extern template class Eigen<TYPE, 7>; \
extern template class Eigen<TYPE, 8>; \
extern template class Eigen<TYPE, 9>; \
extern template class Eigen<TYPE, 10>

DECLARE_EIGEN_BUFFER(float);
DECLARE_EIGEN_BUFFER(double);

#ifdef ENABLE_SIGMA
DECLARE_EIGEN_BUFFER(sigma::UFloat);
DECLARE_EIGEN_BUFFER(sigma::UDouble);
#endif

#undef DECLARE_EIGEN_BUFFER

Expand Down
35 changes: 20 additions & 15 deletions src/tensorwrapper/allocator/eigen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,26 @@ typename EIGEN::buffer_base_pointer EIGEN::allocate_(layout_pointer playout) {

// -- Explicit class template instantiation

#define DEFINE_EIGEN_ALLOCATOR(RANK) \
template class Eigen<float, RANK>; \
template class Eigen<double, RANK>

DEFINE_EIGEN_ALLOCATOR(0);
DEFINE_EIGEN_ALLOCATOR(1);
DEFINE_EIGEN_ALLOCATOR(2);
DEFINE_EIGEN_ALLOCATOR(3);
DEFINE_EIGEN_ALLOCATOR(4);
DEFINE_EIGEN_ALLOCATOR(5);
DEFINE_EIGEN_ALLOCATOR(6);
DEFINE_EIGEN_ALLOCATOR(7);
DEFINE_EIGEN_ALLOCATOR(8);
DEFINE_EIGEN_ALLOCATOR(9);
DEFINE_EIGEN_ALLOCATOR(10);
#define DEFINE_EIGEN_ALLOCATOR(TYPE) \
template class Eigen<TYPE, 0>; \
template class Eigen<TYPE, 1>; \
template class Eigen<TYPE, 2>; \
template class Eigen<TYPE, 3>; \
template class Eigen<TYPE, 4>; \
template class Eigen<TYPE, 5>; \
template class Eigen<TYPE, 6>; \
template class Eigen<TYPE, 7>; \
template class Eigen<TYPE, 8>; \
template class Eigen<TYPE, 9>; \
template class Eigen<TYPE, 10>

DEFINE_EIGEN_ALLOCATOR(float);
DEFINE_EIGEN_ALLOCATOR(double);

#ifdef ENABLE_SIGMA
DEFINE_EIGEN_ALLOCATOR(sigma::UFloat);
DEFINE_EIGEN_ALLOCATOR(sigma::UDouble);
#endif

#undef DEFINE_EIGEN_ALLOCATOR

Expand Down
35 changes: 20 additions & 15 deletions src/tensorwrapper/buffer/eigen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,21 +234,26 @@ TPARAMS typename EIGEN::dsl_reference EIGEN::contraction_(
#undef EIGEN
#undef TPARAMS

#define DEFINE_EIGEN_BUFFER(RANK) \
template class Eigen<float, RANK>; \
template class Eigen<double, RANK>

DEFINE_EIGEN_BUFFER(0);
DEFINE_EIGEN_BUFFER(1);
DEFINE_EIGEN_BUFFER(2);
DEFINE_EIGEN_BUFFER(3);
DEFINE_EIGEN_BUFFER(4);
DEFINE_EIGEN_BUFFER(5);
DEFINE_EIGEN_BUFFER(6);
DEFINE_EIGEN_BUFFER(7);
DEFINE_EIGEN_BUFFER(8);
DEFINE_EIGEN_BUFFER(9);
DEFINE_EIGEN_BUFFER(10);
#define DEFINE_EIGEN_BUFFER(TYPE) \
template class Eigen<TYPE, 0>; \
template class Eigen<TYPE, 1>; \
template class Eigen<TYPE, 2>; \
template class Eigen<TYPE, 3>; \
template class Eigen<TYPE, 4>; \
template class Eigen<TYPE, 5>; \
template class Eigen<TYPE, 6>; \
template class Eigen<TYPE, 7>; \
template class Eigen<TYPE, 8>; \
template class Eigen<TYPE, 9>; \
template class Eigen<TYPE, 10>

DEFINE_EIGEN_BUFFER(float);
DEFINE_EIGEN_BUFFER(double);

#ifdef ENABLE_SIGMA
DEFINE_EIGEN_BUFFER(sigma::UFloat);
DEFINE_EIGEN_BUFFER(sigma::UDouble);
#endif

#undef DEFINE_EIGEN_BUFFER

Expand Down
8 changes: 7 additions & 1 deletion tests/cxx/unit_tests/tensorwrapper/allocator/eigen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@

using namespace tensorwrapper;

TEMPLATE_TEST_CASE("EigenAllocator", "", float, double) {
#ifdef ENABLE_SIGMA
using types2test = std::tuple<float, double, sigma::UFloat, sigma::UDouble>;
#else
using types2test = std::tuple<float, double>;
#endif

TEMPLATE_LIST_TEST_CASE("EigenAllocator", "", types2test) {
using scalar_alloc_type = allocator::Eigen<TestType, 0>;
using vector_alloc_type = allocator::Eigen<TestType, 1>;
using matrix_alloc_type = allocator::Eigen<TestType, 2>;
Expand Down
Loading