-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compare TUV-X Tridiagonal Solver Code with LAPACKE's implementation (#97
) * added BLAS library specification in build script * lapacke added in cmake * added google benchmark * run each tridiagonal solver test multiple times and take average of the metrics being recorded * modified plots generated in numerical_analysis * include the correct LAPACK package based on the compiler used * Apply suggestions from code review formatting changes Co-authored-by: Kyle Shores <[email protected]> * seperated tests and benchmark (used google benchmark) * benchmarking code changes * only use diagonally dominant matrices for unit test * update docker files to use lapacke for tridiagonal tests * Update ubuntu.yml with lapacke * maybe this will work? * revert changes to ubuntu.yml * Update Dockerfile for CI test * add missing new line * allowing benchmark folder to be copied by dockerg * Update cmake/test_util.cmake minor formatting change Co-authored-by: Kyle Shores <[email protected]> * adding lapacke to ubuntu workflow * spelling * serial build * undoing cmake formatting changes * using find lapacke from other open source libraries * correcting working directory * adding benchmark cmake variable * dash * fixing path * removing language thing * ignore gtest when running clang tidy * unit tests operate on one size (1000); formatting changes; use same random values to compare lapacke and tuvx * re-adding benchmark variable * fixed bug in test_error_function unit test; updated documentation * uncommented findLAPACKE * added some more documentation * fixed a bug that caused the memcheck to fail * Apply suggestions from code review CMAKE file formatting changes Co-authored-by: mwaxmonsky <[email protected]> * switched to std::abs instead of ::abs * reverted formatting changes in cmake file * re-added lapacke dependency in test_util * linked LAPACKE libraries to unit tests * removed typedefs in test_error_function.cpp * updated code documentation * documentaion changes * documentation changes * documentation changes * switched back to version 0.9.0 * Documentation Changes * Update src/CMakeLists.txt Co-authored-by: Kyle Shores <[email protected]> * Update src/CMakeLists.txt Co-authored-by: Kyle Shores <[email protected]> * rolled back format changes * Update src/CMakeLists.txt Co-authored-by: mwaxmonsky <[email protected]> --------- Co-authored-by: Aditya Dendukuri <[email protected]> Co-authored-by: Aditya Dendukuri <[email protected]> Co-authored-by: Aditya Dendukuri <[email protected]> Co-authored-by: Aditya Dendukuri <[email protected]> Co-authored-by: Aditya Dendukuri <[email protected]> Co-authored-by: Aditya Dendukuri <[email protected]> Co-authored-by: Kyle Shores <[email protected]> Co-authored-by: Aditya Dendukuri <[email protected]> Co-authored-by: Jian Sun <[email protected]> Co-authored-by: Jian Sun <[email protected]> Co-authored-by: Aditya Dendukuri <[email protected]> Co-authored-by: mwaxmonsky <[email protected]>
- Loading branch information
1 parent
80f896a
commit 9b48b5d
Showing
22 changed files
with
986 additions
and
311 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,5 @@ | |
!packaging/ | ||
!test/ | ||
!tool/ | ||
!CMakeLists.txt | ||
!CMakeLists.txt | ||
!benchmark |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
Oops, something went wrong.