Skip to content
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

Compare TUV-X Tridiagonal Solver Code with LAPACKE's implementation #97

Merged
merged 58 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
0700222
added BLAS library specification in build script
May 22, 2024
6fee119
merged local branch with main
Jun 4, 2024
0db8fa3
Merge branch 'main' of github.com:NCAR/tuv-x
Jun 12, 2024
42d8147
lapacke added in cmake
Jun 13, 2024
c2d6472
added google benchmark
Jun 17, 2024
c74f3f2
run each tridiagonal solver test multiple times and take average of t…
Jun 18, 2024
bdcb3a0
modified plots generated in numerical_analysis
Jun 18, 2024
b1b5ff4
include the correct LAPACK package based on the compiler used
Jun 26, 2024
dee5d7b
Apply suggestions from code review
AdityaDendukuri Jun 26, 2024
830184d
seperated tests and benchmark (used google benchmark)
Jun 26, 2024
5e63955
benchmarking code changes
Jun 28, 2024
3cbb75a
only use diagonally dominant matrices for unit test
Jun 28, 2024
2077a2d
Merge branch 'main' into lapacke_debug
sjsprecious Jun 28, 2024
3acc6e4
update docker files to use lapacke for tridiagonal tests
sjsprecious Jun 28, 2024
e035ad9
Update ubuntu.yml with lapacke
sjsprecious Jun 28, 2024
cc3403b
maybe this will work?
sjsprecious Jun 28, 2024
6433ed0
revert changes to ubuntu.yml
sjsprecious Jun 28, 2024
004a55d
Update Dockerfile for CI test
sjsprecious Jun 29, 2024
7e7f02b
add missing new line
sjsprecious Jun 29, 2024
ec88760
allowing benchmark folder to be copied by dockerg
K20shores Jul 1, 2024
63f1e8c
Update cmake/test_util.cmake
AdityaDendukuri Jul 1, 2024
7c7c4ed
adding lapacke to ubuntu workflow
K20shores Jul 1, 2024
21b65ca
Merge branch 'lapacke_debug' of https://github.com/NCAR/tuv-x into la…
K20shores Jul 1, 2024
feb883f
spelling
K20shores Jul 1, 2024
ab61424
serial build
K20shores Jul 1, 2024
6fc7973
undoing cmake formatting changes
K20shores Jul 1, 2024
783b494
using find lapacke from other open source libraries
K20shores Jul 1, 2024
4dc105f
correcting working directory
K20shores Jul 1, 2024
6621164
adding benchmark cmake variable
K20shores Jul 1, 2024
26fd879
dash
K20shores Jul 1, 2024
874e970
fixing path
K20shores Jul 1, 2024
4994013
removing language thing
K20shores Jul 1, 2024
0e909a0
ignore gtest when running clang tidy
K20shores Jul 1, 2024
9239c15
unit tests operate on one size (1000); formatting changes; use same r…
Jul 2, 2024
a6299bc
re-adding benchmark variable
K20shores Jul 3, 2024
510c956
fixed bug in test_error_function unit test; updated documentation
Jul 3, 2024
9820583
Merge branch 'lapacke_debug' of github.com:NCAR/tuv-x into lapacke_debug
Jul 3, 2024
9f54f5a
uncommented findLAPACKE
Jul 3, 2024
9f983b3
added some more documentation
Jul 3, 2024
c22d41d
fixed a bug that caused the memcheck to fail
Jul 3, 2024
eda38a6
Apply suggestions from code review
AdityaDendukuri Jul 3, 2024
d3b66f7
switched to std::abs instead of ::abs
Jul 3, 2024
9f256bd
Merge branch 'lapacke_debug' of github.com:NCAR/tuv-x into lapacke_debug
Jul 3, 2024
bb1c227
reverted formatting changes in cmake file
Jul 3, 2024
05e2827
re-added lapacke dependency in test_util
Jul 3, 2024
04a9b0f
linked LAPACKE libraries to unit tests
Jul 3, 2024
20e73de
removed typedefs in test_error_function.cpp
Jul 3, 2024
34b529b
updated code documentation
AdityaDendukuri Jul 5, 2024
88fa5a6
documentaion changes
AdityaDendukuri Jul 5, 2024
302fc37
documentation changes
AdityaDendukuri Jul 5, 2024
73ac682
documentation changes
Jul 8, 2024
1d165a8
switched back to version 0.9.0
Jul 8, 2024
23b358e
Documentation Changes
Jul 8, 2024
a572368
Update src/CMakeLists.txt
AdityaDendukuri Jul 9, 2024
38e9903
Update src/CMakeLists.txt
AdityaDendukuri Jul 9, 2024
b6a10f8
rolled back format changes
Jul 9, 2024
766ecf8
Merge branch 'lapacke_debug' of github.com:NCAR/tuv-x into lapacke_debug
Jul 9, 2024
98d29f6
Update src/CMakeLists.txt
AdityaDendukuri Jul 10, 2024
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
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
!packaging/
!test/
!tool/
!CMakeLists.txt
!CMakeLists.txt
!benchmark
9 changes: 7 additions & 2 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
name: Docker

on: [push, pull_request]
on:
push:
branches:
- main
pull_request:
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
cancel-in-progress: true

jobs:
docker-build-and-test:
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
name: Build and Test - ${{ matrix.dockerfile }}
runs-on: ubuntu-latest
continue-on-error: true
strategy:
fail-fast: false
matrix:
Expand Down
15 changes: 10 additions & 5 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
name: Ubuntu

on: [ push, pull_request ]
on:
push:
branches:
- main
pull_request:
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
Expand All @@ -9,7 +14,7 @@ concurrency:
jobs:
gcc:
runs-on: ubuntu-24.04
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
continue-on-error: true
strategy:
matrix:
gcc_version: [12, 13, 14]
Expand All @@ -24,13 +29,13 @@ jobs:
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y libnetcdf-dev netcdf-bin libnetcdff-dev liblapack-dev
sudo apt-get install -y libnetcdf-dev netcdf-bin libnetcdff-dev liblapack-dev liblapacke-dev
sudo apt-get install -y python3-numpy python3-scipy
- name: Run Cmake
run: cmake -S . -B build
- name: Build
run: cmake --build build --parallel
run: cmake --build build
Comment on lines -32 to +37
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may have missed this part of the conversation so my apologies in advanced but is --parallel not possible to use with lapacke

- name: Run tests
run: |
cd build
ctest --rerun-failed --output-on-failure . --verbose
ctest --rerun-failed --output-on-failure . --verbose
13 changes: 12 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ include(CMakeDependentOption)
option(TUVX_ENABLE_MPI "Enable MPI parallel support" OFF)
cmake_dependent_option(TUVX_ENABLE_OPENMP "Enable OpenMP support" OFF "TUVX_ENABLE_MPI" OFF)
option(TUVX_ENABLE_TESTS "Build tests" ON)
option(TUVX_ENABLE_BENCHMARK "Build benchmark examples" OFF)
option(TUVX_ENABLE_COVERAGE "Enable code coverage output" OFF)
option(TUVX_ENABLE_MEMCHECK "Enable memory checking in tests" OFF)
option(TUVX_ENABLE_NC_CONFIG "Use nc-config to determine NetCDF libraries" OFF)
Expand Down Expand Up @@ -105,6 +106,9 @@ endif()
target_link_libraries(tuv-x
PUBLIC
musica::tuvx
yaml-cpp::yaml-cpp
${BLAS_LIBRARIES}
${LAPACK_LIBRARIES}
)

target_include_directories(tuv-x
Expand Down Expand Up @@ -151,4 +155,11 @@ if(PROJECT_IS_TOP_LEVEL)
add_subdirectory(packaging)
endif()

################################################################################
################################################################################
# benchmarking

if(TUVX_ENABLE_BENCHMARK)
add_subdirectory(benchmark)
endif()

################################################################################
12 changes: 12 additions & 0 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
add_executable(benchmark_tridiagonal_solver benchmark_tridiagonal_solver.cpp)
target_include_directories(
benchmark_tridiagonal_solver PUBLIC ${OpenBLAS_INCLUDE_DIRS}
${LAPACK_INCLUDE_DIRS})

target_link_libraries(benchmark_tridiagonal_solver
PUBLIC
LAPACK::LAPACK
${LAPACKE_LIBRARIES}
benchmark::benchmark
musica::tuvx
)
126 changes: 126 additions & 0 deletions benchmark/benchmark_tridiagonal_solver.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@

#include <tuvx/linear_algebra/linear_algebra.hpp>

#include <benchmark/benchmark.h>

#include <random>
#include <vector>

#ifdef TUVX_COMPILE_WITH_INTEL
#include <mkl_lapacke.h>
#elif TUVX_COMPILE_WITH_GCC
#include <lapacke.h>
#endif

const std::size_t SYSTEM_SIZE = 1e6;

const bool MAKE_DIAGONALLY_DOMINANT = true;

const unsigned RANDOM_NUMBER_SEED = 1;

/// @brief This function benchmarks the lapacke tridiagonal matrix solver for single precision
/// @param state Benchmarking argument
static void BM_LAPACKE_SINGLE_PRECISISON(benchmark::State& state)
{
std::vector<float> x(SYSTEM_SIZE);
std::vector<float> b(SYSTEM_SIZE);
tuvx::TridiagonalMatrix<float> A(SYSTEM_SIZE);
std::mt19937 random_device(RANDOM_NUMBER_SEED);
for (auto _ : state)
{
state.PauseTiming();
tuvx::FillRandom<float>(A, RANDOM_NUMBER_SEED, MAKE_DIAGONALLY_DOMINANT);
tuvx::FillRandom<float>(x, RANDOM_NUMBER_SEED);
b = tuvx::Dot<float>(A, x);
state.ResumeTiming();

LAPACKE_sgtsv(
LAPACK_ROW_MAJOR,
SYSTEM_SIZE,
1,
A.lower_diagonal_.data(),
A.main_diagonal_.data(),
A.upper_diagonal_.data(),
b.data(),
1);
}
}

/// @brief This function benchmarks the lapacke tridiagonal matrix solver for double precision
/// @param state Benchmarking argument
static void BM_LAPACKE_DOUBLE_PRECISISON(benchmark::State& state)
{
std::vector<double> x(SYSTEM_SIZE);
std::vector<double> b(SYSTEM_SIZE);
tuvx::TridiagonalMatrix<double> A(SYSTEM_SIZE);

std::mt19937 random_device(RANDOM_NUMBER_SEED);
// Perform setup here
for (auto _ : state)
{
state.PauseTiming();
tuvx::FillRandom<double>(A, RANDOM_NUMBER_SEED, MAKE_DIAGONALLY_DOMINANT);
tuvx::FillRandom<double>(x, RANDOM_NUMBER_SEED);
b = tuvx::Dot<double>(A, x);
state.ResumeTiming();

LAPACKE_dgtsv(
LAPACK_ROW_MAJOR,
SYSTEM_SIZE,
1,
A.lower_diagonal_.data(),
A.main_diagonal_.data(),
A.upper_diagonal_.data(),
b.data(),
1);
}
}

/// @brief This function benchmarks the tuvx tridiagonal matrix solver for single precision
/// @param state Benchmarking argument
static void BM_TUVX_DOUBLE_PRECISISON(benchmark::State& state)
{
std::vector<double> x(SYSTEM_SIZE);
std::vector<double> b(SYSTEM_SIZE);
tuvx::TridiagonalMatrix<double> A(SYSTEM_SIZE);
std::vector<double> x_approx(SYSTEM_SIZE);

for (auto _ : state)
{
state.PauseTiming();
tuvx::FillRandom<double>(A, RANDOM_NUMBER_SEED, MAKE_DIAGONALLY_DOMINANT);
tuvx::FillRandom<double>(x, RANDOM_NUMBER_SEED);
state.ResumeTiming();
tuvx::Solve<double>(A, b);
}
}

/// @brief This function benchmarks the tuvx tridiagonal matrix solver for double precision
/// @param state Benchmarking argument
static void BM_TUVX_SINGLE_PRECISISON(benchmark::State& state)
{
std::vector<float> x(SYSTEM_SIZE);
std::vector<float> b(SYSTEM_SIZE);
tuvx::TridiagonalMatrix<float> A(SYSTEM_SIZE);
std::vector<float> x_approx(SYSTEM_SIZE);

// Perform setup here
for (auto _ : state)
{
state.PauseTiming();
tuvx::FillRandom<float>(A, RANDOM_NUMBER_SEED, MAKE_DIAGONALLY_DOMINANT);
tuvx::FillRandom<float>(x, RANDOM_NUMBER_SEED);
b = tuvx::Dot<float>(A, x);
state.ResumeTiming();
tuvx::Solve<float>(A, b);
}
}

/// @brief Register the functions defined above as a benchmark
BENCHMARK(BM_LAPACKE_DOUBLE_PRECISISON);
BENCHMARK(BM_LAPACKE_SINGLE_PRECISISON);
BENCHMARK(BM_TUVX_DOUBLE_PRECISISON);
BENCHMARK(BM_TUVX_SINGLE_PRECISISON);

/// @brief Run all benchmarks
BENCHMARK_MAIN();
Loading
Loading