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 10 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
283 changes: 149 additions & 134 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,137 +34,152 @@ jobs:
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4

- uses: actions/cache/restore@v4
with:
path: ${{ env.CCACHE_DIR }}
key: ccache-${{ matrix.os }}-${{ matrix.cc }}-${{ github.run_id }}
restore-keys:
ccache-${{ matrix.os }}-${{ matrix.cc }}-

- name: Install ubuntu dependencies
if: ${{ contains(matrix.os, 'ubuntu') }}
run: >
sudo apt-get update &&
sudo apt-get install lsb-release wget software-properties-common &&
sudo apt-get install
ccache
clang
g++
gfortran
hdf5-tools
libblas-dev
libclang-dev
libc++-dev
libc++abi-dev
libomp-dev
libfftw3-dev
libgfortran5
libgmp-dev
libhdf5-dev
liblapack-dev
libopenmpi-dev
openmpi-bin
openmpi-common
openmpi-doc
python3-clang
python3-dev
python3-mako
python3-mpi4py
python3-numpy
python3-pip
python3-scipy
python3-sphinx
python3-nbsphinx

- name: Set up virtualenv
run: |
mkdir $HOME/.venv
python3 -m venv --system-site-packages $HOME/.venv/my_python
source $HOME/.venv/my_python/bin/activate
echo "VIRTUAL_ENV=$VIRTUAL_ENV" >> $GITHUB_ENV
echo "PATH=$PATH" >> $GITHUB_ENV

- name: Install homebrew dependencies
if: ${{ contains(matrix.os, 'macos') }}
run: |
brew update
brew install ccache gcc llvm hdf5 open-mpi openblas doxygen
pip install mako numpy scipy mpi4py
pip install -r requirements.txt
echo "PATH=$(brew --prefix llvm)/bin:$(brew --prefix gcc)/bin:$PATH" >> $GITHUB_ENV
echo "PYTHONPATH=$(brew --prefix llvm)/lib/python3.13/site-packages" >> $GITHUB_ENV

- name: Add clang CXXFLAGS
if: ${{ contains(matrix.cxx, 'clang') }}
run: |
echo "CXXFLAGS=-stdlib=libc++" >> $GITHUB_ENV

- name: Add clang LDFLAGS for macos to link against brew's libc++
if: ${{ contains(matrix.os, 'macos') && contains(matrix.cxx, 'clang') }}
run: |
echo 'LDFLAGS="-L$(brew --prefix llvm)/lib/c++ -L$(brew --prefix llvm)/lib -lunwind"' >> $GITHUB_ENV

- name: Set up test coverage
if: matrix.cov == 'ON'
run: |
pip install gcovr
echo "CXXFLAGS=--coverage" >> $GITHUB_ENV

- name: Prepare source files for doxygen
if: matrix.doc == 'ON'
working-directory: ./c++/nda
run: |
sed -e '/#include .*impl.*.hpp/{r _impl_basic_array_view_common.hpp' -e 'd' -e '}' basic_array.hpp > tmp_basic_array.hpp
sed -e '/#include .*impl.*.hpp/{r _impl_basic_array_view_common.hpp' -e 'd' -e '}' basic_array_view.hpp > tmp_basic_array_view.hpp
mv tmp_basic_array.hpp basic_array.hpp
mv tmp_basic_array_view.hpp basic_array_view.hpp

- name: Build nda
env:
CC: ${{ matrix.cc }}
CXX: ${{ matrix.cxx }}
run: |
mkdir build && cd build && cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/install -DPythonSupport=ON -DBuild_Documentation=${{ matrix.doc }} -DCMAKE_BUILD_TYPE=${{ matrix.cov == 'ON' && 'Debug' || 'Release' }}
make -j2 || make -j1 VERBOSE=1

- name: Test nda
env:
OPENBLAS_NUM_THREADS: "1"
run: |
cd build
ctest -j2 --output-on-failure

- name: Generate test coverage HTML output
if: matrix.cov == 'ON'
run: |
cd build
mkdir coverage
gcovr --gcov-executable "gcov" --root ../c++ --html-details -o coverage/coverage.html .

- name: ccache statistics
if: always()
run: ccache -sv

- uses: actions/cache/save@v4
if: always()
with:
path: ${{ env.CCACHE_DIR }}
key: ccache-${{ matrix.os }}-${{ matrix.cc }}-${{ github.run_id }}

- name: Deploy documentation
if: matrix.doc == 'ON' && github.ref == 'refs/heads/unstable'
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: build/doc/html
branch: github.io
target-folder: docs/unstable

- name: Deploy test coverage
if: matrix.cov == 'ON' && github.ref == 'refs/heads/unstable'
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: build/coverage
branch: github.io
target-folder: docs/coverage
- uses: actions/checkout@v4

- uses: actions/cache/restore@v4
with:
path: ${{ env.CCACHE_DIR }}
key: ccache-${{ matrix.os }}-${{ matrix.cc }}-${{ github.run_id }}
restore-keys:
ccache-${{ matrix.os }}-${{ matrix.cc }}-

- name: Install ubuntu dependencies
if: ${{ contains(matrix.os, 'ubuntu') }}
run: >
sudo apt-get update &&
sudo apt-get install lsb-release wget software-properties-common &&
sudo apt-get install
ccache
clang
g++
gfortran
hdf5-tools
libblas-dev
libclang-dev
libc++-dev
libc++abi-dev
libomp-dev
libfftw3-dev
libgfortran5
libgmp-dev
libhdf5-dev
liblapack-dev
libopenmpi-dev
openmpi-bin
openmpi-common
openmpi-doc
python3-clang
python3-dev
python3-mako
python3-mpi4py
python3-numpy
python3-pip
python3-scipy
python3-sphinx
python3-nbsphinx

- name: Set up virtualenv
run: |
mkdir $HOME/.venv
python3 -m venv --system-site-packages $HOME/.venv/my_python
source $HOME/.venv/my_python/bin/activate
echo "VIRTUAL_ENV=$VIRTUAL_ENV" >> $GITHUB_ENV
echo "PATH=$PATH" >> $GITHUB_ENV

- name: Install homebrew dependencies
if: ${{ contains(matrix.os, 'macos') }}
run: |
brew update
brew install ccache gcc llvm hdf5 open-mpi openblas doxygen
pip install mako numpy scipy mpi4py
pip install -r requirements.txt
echo "PATH=$(brew --prefix llvm)/bin:$(brew --prefix gcc)/bin:$PATH" >> $GITHUB_ENV
echo "PYTHONPATH=$(brew --prefix llvm)/lib/python3.13/site-packages" >> $GITHUB_ENV

- name: Add clang CXXFLAGS
if: ${{ contains(matrix.cxx, 'clang') }}
run: |
echo "CXXFLAGS=-stdlib=libc++" >> $GITHUB_ENV

- name: Add clang LDFLAGS for macos to link against brew's libc++
if: ${{ contains(matrix.os, 'macos') && contains(matrix.cxx, 'clang') }}
run: |
echo 'LDFLAGS="-L$(brew --prefix llvm)/lib/c++ -L$(brew --prefix llvm)/lib -lunwind"' >> $GITHUB_ENV

- name: Set up test coverage
if: matrix.cov == 'ON'
run: |
pip install gcovr
echo "CXXFLAGS=--coverage" >> $GITHUB_ENV

- name: Prepare source files for doxygen
if: matrix.doc == 'ON'
working-directory: ./c++/nda
run: |
sed -e '/#include .*impl.*.hpp/{r _impl_basic_array_view_common.hpp' -e 'd' -e '}' basic_array.hpp > tmp_basic_array.hpp
sed -e '/#include .*impl.*.hpp/{r _impl_basic_array_view_common.hpp' -e 'd' -e '}' basic_array_view.hpp > tmp_basic_array_view.hpp
mv tmp_basic_array.hpp basic_array.hpp
mv tmp_basic_array_view.hpp basic_array_view.hpp

- name: Test flag combinations
env:
CC: ${{ matrix.cc }}
CXX: ${{ matrix.cxx }}
OPENBLAS_NUM_THREADS: "1"
run: |
set -e
for hdf5 in ON OFF; do
for openmp in ON OFF; do
for mpi in ON OFF; do
echo "::group::[Config] HDF5=$hdf5 OMP=$openmp MPI=$mpi"
rm -rf build && mkdir build && cd build

cmake .. \
-DCMAKE_INSTALL_PREFIX=$HOME/install \
-DPythonSupport=ON \
-DBuild_Documentation=${DOC:-OFF} \
-DCMAKE_BUILD_TYPE=$( [ "${COV:-OFF}" == "ON" ] && echo "Debug" || echo "Release" ) \
-DHDF5Support=$hdf5 \
-DOpenMPSupport=$openmp \
-DMPISupport=$mpi

make -j2 || make -j1 VERBOSE=1
ctest -j2 --output-on-failure
cd ..
echo "::endgroup::"
done
done
done

- name: Generate test coverage HTML output
if: matrix.cov == 'ON'
run: |
cd build
mkdir coverage
gcovr --gcov-executable "gcov" --root ../c++ --html-details -o coverage/coverage.html .

- name: ccache statistics
if: always()
run: ccache -sv

- uses: actions/cache/save@v4
if: always()
with:
path: ${{ env.CCACHE_DIR }}
key: ccache-${{ matrix.os }}-${{ matrix.cc }}-${{ github.run_id }}

- name: Deploy documentation
if: matrix.doc == 'ON' && github.ref == 'refs/heads/unstable'
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: build/doc/html
branch: github.io
target-folder: docs/unstable

- name: Deploy test coverage
if: matrix.cov == 'ON' && github.ref == 'refs/heads/unstable'
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: build/coverage
branch: github.io
target-folder: docs/coverage
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
Loading
Loading