From 84301ba0a05a93c7e64eb1cc0f23984eeaf44338 Mon Sep 17 00:00:00 2001 From: Alejandro Armas Date: Fri, 20 May 2022 15:12:20 -0700 Subject: [PATCH] Benchmarked transpose and softmax functions. --- benchmarks/benchmark_softmax.cpp | 5 ++--- benchmarks/benchmark_transpose.cpp | 32 ++++++++++++++++++++++++++++ benchmarks/results.md | 2 ++ unittests/test_transpose.cpp | 34 ++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 benchmarks/benchmark_transpose.cpp create mode 100644 unittests/test_transpose.cpp diff --git a/benchmarks/benchmark_softmax.cpp b/benchmarks/benchmark_softmax.cpp index e034658..9462862 100644 --- a/benchmarks/benchmark_softmax.cpp +++ b/benchmarks/benchmark_softmax.cpp @@ -13,17 +13,16 @@ int main(void) { using matrix_t = Matrix::Representation; matrix_t ma = matrix_t(Matrix::Rows(5000), Matrix::Columns(1)); - matrix_t mb = matrix_t(Matrix::Rows(5000), Matrix::Columns(1)); + Matrix::Generation::Normal<0, 1> normal_distribution_init; ma = normal_distribution_init(ma); - mb = normal_distribution_init(mb); Matrix::Operations::Timer timer( Matrix::Operations::Unary::SoftMax{} ); - matrix_t mf = timer(ma, mb); + matrix_t mf = timer(ma); std::cout << std::endl << "Performed in " << timer.get_computation_duration_ms() << " ms." << std::endl; diff --git a/benchmarks/benchmark_transpose.cpp b/benchmarks/benchmark_transpose.cpp new file mode 100644 index 0000000..05fd4a0 --- /dev/null +++ b/benchmarks/benchmark_transpose.cpp @@ -0,0 +1,32 @@ +#include + +#include "../include/m_algorithms.h" +#include "../include/matrix.h" +#include "../include/generator.h" +#include "../include/matrix_benchmark.h" +#include "../include/matrix_printer.h" + +int main(void) { + + std::cout << "[10000, 9000] Matrix Transpose Benchmark:" << std::endl << std::endl ; + std::cout << "..." << std::endl; + + using matrix_t = Matrix::Representation; + + matrix_t ma = matrix_t(Matrix::Rows(10000), Matrix::Columns(9000)); + Matrix::Generation::Normal<0, 1> normal_distribution_init; + + ma = normal_distribution_init(ma); + + Matrix::Operations::Timer timer( + Matrix::Operations::Unary::Transpose{} + ); + + matrix_t mb = timer(ma); + + + std::cout << std::endl << "Performed in " << timer.get_computation_duration_ms() << " ms." << std::endl; + + + return 0; +} \ No newline at end of file diff --git a/benchmarks/results.md b/benchmarks/results.md index aaec968..243d6d0 100644 --- a/benchmarks/results.md +++ b/benchmarks/results.md @@ -11,3 +11,5 @@ [5000, 1] x [5000, 1] **Softmax** Benchmark: 5 ms [5000, 1] x [5000, 1] **Hadamard Product** Benchmark: 21 ms. + +[10000, 9000] **Matrix Transpose** Benchmark: 659166 -> 66771 ms. \ No newline at end of file diff --git a/unittests/test_transpose.cpp b/unittests/test_transpose.cpp new file mode 100644 index 0000000..05eb631 --- /dev/null +++ b/unittests/test_transpose.cpp @@ -0,0 +1,34 @@ +#include "../deps/doctest.h" + +#include "../include/matrix.h" +#include "../include/generator.h" +#include "../include/m_algorithms.h" + + +TEST_CASE("Matrix Transpose") +{ + + Matrix::Representation ma = Matrix::Representation( + Matrix::Rows(200), Matrix::Columns(1000)); + + + Matrix::Generation::Normal<0, 1> normal_distribution_init; + + ma = normal_distribution_init(ma); + + + Matrix::Operations::Unary::Transpose operation; + + Matrix::Representation mb = operation(ma); + Matrix::Representation mc = operation(mb); + + + + SUBCASE("Cache Oblivious Transpose") + { + + CHECK((Matrix::Representation{ma} == Matrix::Representation{mc}) == true); + } + + +} \ No newline at end of file