Skip to content

Commit

Permalink
Benchmarked transpose and softmax functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandroarmas committed May 20, 2022
1 parent cca5d2e commit 84301ba
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 3 deletions.
5 changes: 2 additions & 3 deletions benchmarks/benchmark_softmax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
32 changes: 32 additions & 0 deletions benchmarks/benchmark_transpose.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <iostream>

#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;
}
2 changes: 2 additions & 0 deletions benchmarks/results.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
34 changes: 34 additions & 0 deletions unittests/test_transpose.cpp
Original file line number Diff line number Diff line change
@@ -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);
}


}

0 comments on commit 84301ba

Please sign in to comment.