Skip to content

Fixed cmake to make dependencies optional #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: unstable
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ endif()

# Python Support
option(PythonSupport "Build with Python support" OFF)
# H5 support
option(HDF5Support "Build with HDF5 support" OFF)
# MPI support
option(MPISupport "Build with MPI support" OFF)
# OpenMP support
option(OpenMPSupport "Build with OpenMP support" OFF)

# Documentation
option(Build_Documentation "Build documentation" OFF)
Expand Down
3 changes: 3 additions & 0 deletions benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ foreach(bench ${all_benchs})
add_executable(${bench_name} ${bench})
target_link_libraries(${bench_name} ${PROJECT_NAME}::${PROJECT_NAME}_c ${PROJECT_NAME}_warnings benchmark_main)
set_property(TARGET ${bench_name} PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${bench_dir})
if (CudaSupport)
target_compile_definitions(${bench_name} PRIVATE -DNDA_CUDA_SUPPORT)
endif()
#add_bench(NAME ${bench_name} COMMAND ${bench_name} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${bench_dir})
# Run clang-tidy if found
if(CLANG_TIDY_EXECUTABLE)
Expand Down
6 changes: 6 additions & 0 deletions benchmarks/blas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ static void DOT(benchmark::State &state) {
state.counters["bytesize"] = double(NBytes);
}
BENCHMARK_TEMPLATE(DOT, nda::vector<value_t>)->RangeMultiplier(2)->Range(Nmin, Nmax)->Unit(benchmark::kMicrosecond); // NOLINT
#ifdef NDA_CUDA_SUPPORT
BENCHMARK_TEMPLATE(DOT, nda::cuvector<value_t>)->RangeMultiplier(2)->Range(Nmin, Nmax)->Unit(benchmark::kMicrosecond); // NOLINT
#endif

template <typename Matrix>
static void GEMM(benchmark::State &state) {
Expand All @@ -36,7 +38,9 @@ static void GEMM(benchmark::State &state) {
state.counters["bytesize"] = double(NBytes);
}
BENCHMARK_TEMPLATE(GEMM, nda::matrix<value_t>)->RangeMultiplier(2)->Range(Nmin, Nmax)->Unit(benchmark::kMicrosecond); // NOLINT
#ifdef NDA_CUDA_SUPPORT
BENCHMARK_TEMPLATE(GEMM, nda::cumatrix<value_t>)->RangeMultiplier(2)->Range(Nmin, Nmax)->Unit(benchmark::kMicrosecond); // NOLINT
#endif

template <typename Vector, typename Matrix>
static void GER(benchmark::State &state) {
Expand All @@ -50,7 +54,9 @@ static void GER(benchmark::State &state) {
state.counters["bytesize"] = double(NBytes);
}
BENCHMARK_TEMPLATE(GER, nda::vector<value_t>, nda::matrix<value_t>)->RangeMultiplier(2)->Range(Nmin, Nmax)->Unit(benchmark::kMicrosecond); // NOLINT
#ifdef NDA_CUDA_SUPPORT
BENCHMARK_TEMPLATE(GER, nda::cuvector<value_t>, nda::cumatrix<value_t>)
->RangeMultiplier(2)
->Range(Nmin, Nmax)
->Unit(benchmark::kMicrosecond); // NOLINT
#endif
9 changes: 8 additions & 1 deletion benchmarks/copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ using value_t = double;
template <size_t Rank>
using array_t = nda::array<value_t, Rank>;

#ifdef NDA_CUDA_SUPPORT
template <size_t Rank>
using device_array_t = nda::cuarray<value_t, Rank>;
#endif

const long KBmin = 8;
const long KBmax = 1 << 15;
Expand All @@ -27,8 +29,9 @@ static void Copy(benchmark::State &state) {
state.counters["processed"] = double(NBytes);
}
BENCHMARK_TEMPLATE(Copy, array_t<1>)->RangeMultiplier(8)->Range(KBmin, KBmax); // NOLINT
#ifdef NDA_CUDA_SUPPORT
BENCHMARK_TEMPLATE(Copy, device_array_t<1>)->RangeMultiplier(8)->Range(KBmin, KBmax); // NOLINT

#endif
template <typename Array>
static void Copy1DStrided(benchmark::State &state) {
long NBytes = state.range(0) * 1024;
Expand All @@ -44,7 +47,9 @@ static void Copy1DStrided(benchmark::State &state) {
state.counters["step"] = double(step);
}
BENCHMARK_TEMPLATE(Copy1DStrided, array_t<1>)->RangeMultiplier(8)->Range(KBmin, KBmax); // NOLINT
#ifdef NDA_CUDA_SUPPORT
BENCHMARK_TEMPLATE(Copy1DStrided, device_array_t<1>)->RangeMultiplier(8)->Range(KBmin, KBmax); // NOLINT
#endif

template <typename DstArray, typename SrcArray>
static void CopyBlockStrided(benchmark::State &state) {
Expand All @@ -63,6 +68,8 @@ static void CopyBlockStrided(benchmark::State &state) {
state.counters["n_blocks"] = double(n_blocks);
}
BENCHMARK_TEMPLATE(CopyBlockStrided, array_t<2>, array_t<2>)->RangeMultiplier(8)->Range(KBmin, KBmax); // NOLINT
#ifdef NDA_CUDA_SUPPORT
BENCHMARK_TEMPLATE(CopyBlockStrided, device_array_t<2>, device_array_t<2>)->RangeMultiplier(8)->Range(KBmin, KBmax); // NOLINT
BENCHMARK_TEMPLATE(CopyBlockStrided, array_t<2>, device_array_t<2>)->RangeMultiplier(8)->Range(KBmin, KBmax); // NOLINT
BENCHMARK_TEMPLATE(CopyBlockStrided, device_array_t<2>, array_t<2>)->RangeMultiplier(8)->Range(KBmin, KBmax); // NOLINT
#endif
6 changes: 6 additions & 0 deletions benchmarks/gemm_batch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ static void GEMM_BATCH(benchmark::State &state) {
state.counters["bytesize"] = double(NBytes);
}
BENCHMARK_TEMPLATE(GEMM_BATCH, nda::matrix<value_t>)->RangeMultiplier(2)->Range(Nmin, Nmax)->Unit(benchmark::kMicrosecond); // NOLINT
#ifdef NDA_CUDA_SUPPORT
BENCHMARK_TEMPLATE(GEMM_BATCH, nda::cumatrix<value_t>)->RangeMultiplier(2)->Range(Nmin, Nmax)->Unit(benchmark::kMicrosecond); // NOLINT
#endif

template <typename M>
static void GEMM_VBATCH(benchmark::State &state) {
Expand All @@ -45,7 +47,9 @@ static void GEMM_VBATCH(benchmark::State &state) {
state.counters["bytesize"] = double(NBytes);
}
BENCHMARK_TEMPLATE(GEMM_VBATCH, nda::matrix<value_t>)->RangeMultiplier(2)->Range(Nmin, Nmax)->Unit(benchmark::kMicrosecond); // NOLINT
#ifdef NDA_CUDA_SUPPORT
BENCHMARK_TEMPLATE(GEMM_VBATCH, nda::cumatrix<value_t>)->RangeMultiplier(2)->Range(Nmin, Nmax)->Unit(benchmark::kMicrosecond); // NOLINT
#endif

template <typename T>
static void GEMM_BATCH_STRIDED(benchmark::State &state) {
Expand All @@ -63,4 +67,6 @@ static void GEMM_BATCH_STRIDED(benchmark::State &state) {
state.counters["bytesize"] = double(NBytes);
}
BENCHMARK_TEMPLATE(GEMM_BATCH_STRIDED, nda::array<value_t, 3>)->RangeMultiplier(2)->Range(Nmin, Nmax)->Unit(benchmark::kMicrosecond); // NOLINT
#ifdef NDA_CUDA_SUPPORT
BENCHMARK_TEMPLATE(GEMM_BATCH_STRIDED, nda::cuarray<value_t, 3>)->RangeMultiplier(2)->Range(Nmin, Nmax)->Unit(benchmark::kMicrosecond); // NOLINT
#endif
21 changes: 17 additions & 4 deletions c++/nda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,30 @@ install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DESTINATION include FILES_MATCHING
configure_file(version.hpp.in version.hpp @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/version.hpp DESTINATION include/${PROJECT_NAME})


# ========= Itertools ==========
target_link_libraries(${PROJECT_NAME}_c PUBLIC itertools::itertools_c)

# ========= Additional Depdencies ==========

# Link against HDF5 C++ Interface
target_link_libraries(${PROJECT_NAME}_c PUBLIC h5::h5_c)
if(HDF5Support)
message(STATUS "-------- HDF5 detection -------------")
target_link_libraries(${PROJECT_NAME}_c PUBLIC h5::h5_c)
endif()

# Link against MPI C++ Interface
target_link_libraries(${PROJECT_NAME}_c PUBLIC mpi::mpi_c)
if (MPISupport)
message(STATUS "-------- MPI detection -------------")
add_subdirectory(mpi)
endif()

# OpenMP
find_package(OpenMP REQUIRED COMPONENTS CXX)
target_link_libraries(${PROJECT_NAME}_c PUBLIC OpenMP::OpenMP_CXX)
if (OpenMPSupport)
message(STATUS "-------- OpenMP detection -------------")
find_package(OpenMP REQUIRED COMPONENTS CXX)
target_link_libraries(${PROJECT_NAME}_c PUBLIC OpenMP::OpenMP_CXX)
endif ()

# ========= Blas / Lapack ==========

Expand Down
12 changes: 6 additions & 6 deletions c++/nda/h5.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

#pragma once

#include "./concepts.hpp"
#include "./declarations.hpp"
#include "./exceptions.hpp"
#include "./layout/for_each.hpp"
#include "./layout/range.hpp"
#include "./traits.hpp"
#include "concepts.hpp"
#include "declarations.hpp"
#include "exceptions.hpp"
#include "layout/for_each.hpp"
#include "layout/range.hpp"
#include "traits.hpp"

#include <h5/h5.hpp>

Expand Down
10 changes: 5 additions & 5 deletions c++/nda/mpi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

#pragma once

#include "./mpi/broadcast.hpp"
#include "./mpi/gather.hpp"
#include "./mpi/reduce.hpp"
#include "./mpi/scatter.hpp"
#include "./mpi/utils.hpp"
#include "mpi/broadcast.hpp"
#include "mpi/gather.hpp"
#include "mpi/reduce.hpp"
#include "mpi/scatter.hpp"
#include "mpi/utils.hpp"
6 changes: 6 additions & 0 deletions c++/nda/mpi/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
target_link_libraries(${PROJECT_NAME}_c PUBLIC mpi::mpi_c)

target_compile_definitions(${PROJECT_NAME}_c PRIVATE
$<BUILD_INTERFACE:MPI_SUPPORT>
$<INSTALL_INTERFACE:MPI_SUPPORT>
)
26 changes: 22 additions & 4 deletions c++/nda/sym_grp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
#pragma once

#include "./nda.hpp"
#include "./mpi.hpp"
#ifdef MPI_SUPPORT
#include "mpi.hpp"
#endif

#include <itertools/itertools.hpp>
#include <itertools/omp_chunk.hpp>
#include <mpi/mpi.hpp>

#include <array>
#include <concepts>
Expand Down Expand Up @@ -182,17 +184,33 @@ namespace nda {
if (parallel) {
// reset input array to allow for mpi reduction
a() = 0.0;

#ifdef MPI_SUPPORT
#pragma omp parallel
for (auto const &sym_class : itertools::omp_chunk(mpi::chunk(sym_classes))) {
auto idx = a.indexmap().to_idx(sym_class[0].first);
auto ref_val = init_func(idx);
std::apply(a, idx) = ref_val;
for (auto const &[lin_idx, op] : sym_class) { std::apply(a, a.indexmap().to_idx(lin_idx)) = op(ref_val); }
}

// distribute data among all ranks
a = mpi::all_reduce(a);
#elifdef _OPENMP
#pragma omp parallel
for (auto const &sym_class : itertools::omp_chunk(sym_classes)) {
auto idx = a.indexmap().to_idx(sym_class[0].first);
auto ref_val = init_func(idx);
std::apply(a, idx) = ref_val;
for (auto const &[lin_idx, op] : sym_class) { std::apply(a, a.indexmap().to_idx(lin_idx)) = op(ref_val); }
}
#else
for (auto const &sym_class : sym_classes) {
auto idx = a.indexmap().to_idx(sym_class[0].first);
auto ref_val = init_func(idx);
std::apply(a, idx) = ref_val;
for (auto const &[lin_idx, op] : sym_class) { std::apply(a, a.indexmap().to_idx(lin_idx)) = op(ref_val); }
}
#endif

} else {
for (auto const &sym_class : sym_classes) {
auto idx = a.indexmap().to_idx(sym_class[0].first);
Expand Down
16 changes: 9 additions & 7 deletions deps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,21 @@ external_dependency(itertools
)

# -- h5 --
external_dependency(h5
GIT_REPO https://github.com/TRIQS/h5
VERSION 1.3
GIT_TAG unstable
)

if (HDF5Support)
external_dependency(h5
GIT_REPO https://github.com/TRIQS/h5
VERSION 1.3
GIT_TAG unstable
)
endif()
# -- MPI --
if (MPISupport)
external_dependency(mpi
GIT_REPO https://github.com/TRIQS/mpi
VERSION 1.3
GIT_TAG unstable
)

endif ()
## Pybind 11
#find_package(Python)
#add_subdirectory(pybind11)
Expand Down
24 changes: 19 additions & 5 deletions test/c++/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,37 @@
# Copy h5 files to binary dir
file(GLOB_RECURSE all_h5_ref_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.ref.h5)
foreach(file ${all_h5_ref_files})
configure_file(${file} ${file} COPYONLY)
endforeach()
if(HDF5Support)
find_package(HDF5 REQUIRED COMPONENTS C HL)
file(GLOB_RECURSE all_h5_ref_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.ref.h5)
foreach(file ${all_h5_ref_files})
configure_file(${file} ${file} COPYONLY)
endforeach()

endif()
# List of all tests
file(GLOB_RECURSE all_tests RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp)
if(NOT CudaSupport)
list(FILTER all_tests EXCLUDE REGEX "nda_cu")
endif()

if(NOT MPISupport)
list(FILTER all_tests EXCLUDE REGEX "mpi")
endif()

if(NOT HDF5Support)
list(FILTER all_tests EXCLUDE REGEX "h5")
endif()

macro(SetUpAllTestWithMacroDef extension macrodef)
foreach(test ${all_tests})
get_filename_component(test_name ${test} NAME_WE)
string(APPEND test_name "${ARGV0}")
#MESSAGE("${test_name} with option ${ARGV1}")
get_filename_component(test_dir ${test} DIRECTORY)
add_executable(${test_name} ${test})
target_link_libraries(${test_name} ${PROJECT_NAME}_c gtest_main ${PROJECT_NAME}_warnings hdf5::hdf5)
target_link_libraries(${test_name} ${PROJECT_NAME}_c gtest_main ${PROJECT_NAME}_warnings)
if (HDF5Support)
target_link_libraries(${test_name} hdf5::hdf5)
endif()
target_compile_options(${test_name} PRIVATE "${ARGV1}")
set_property(TARGET ${test_name} PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${test_dir})
add_test(NAME ${test_name} COMMAND ${test_name} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${test_dir})
Expand Down
1 change: 1 addition & 0 deletions test/c++/nda_h5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <h5/h5.hpp>
#include <hdf5_hl.h>


using namespace nda::clef::literals;
using nda::ellipsis;
using nda::range;
Expand Down
Loading