Skip to content

Commit

Permalink
Refactored the code.
Browse files Browse the repository at this point in the history
  • Loading branch information
wermos committed Jul 31, 2022
1 parent 8d7df4a commit 125a084
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@

#include "benchmark/benchmark.h"
#include "blaze/Math.h"
#include "gemm_header.h"
#include "shared/common.hpp"
#include "random.hpp"

static void gemm_blaze(benchmark::State& state) {
blaze::StaticMatrix<double, SIZE, SIZE, blaze::rowMajor> m1, m2, res;
blaze::StaticMatrix<float, SIZE, SIZE, blaze::rowMajor> m1, m2, res;

m1 =
blaze::generate(SIZE, SIZE, [](std::size_t i, std::size_t j) { return randomDouble(-1.0, 1.0); });
blaze::generate(SIZE, SIZE, [](std::size_t i, std::size_t j) { return randomFloat(-1.0, 1.0); });
m2 =
blaze::generate(SIZE, SIZE, [](std::size_t i, std::size_t j) { return randomDouble(-1.0, 1.0); });
blaze::generate(SIZE, SIZE, [](std::size_t i, std::size_t j) { return randomFloat(-1.0, 1.0); });

for (auto _ : state) {
benchmark::DoNotOptimize(res);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

#include "benchmark/benchmark.h"
#include "fast5x5/fast5x5.hpp"
#include "gemm_header.h"
#include "shared/common.hpp"
#include "random.hpp"

static void gemm_custom(benchmark::State& state) {
alignas(32) double a[SIZE * SIZE];
alignas(32) double b[SIZE * SIZE];
alignas(32) float a[SIZE * SIZE];
alignas(32) float b[SIZE * SIZE];

for (int i = 0; i < SIZE; i++) {
for (int j = 0; j < SIZE; j++) {
Expand All @@ -17,7 +17,7 @@ static void gemm_custom(benchmark::State& state) {
}
}

using M = BaseMatrix<double, SIZE, SIZE>;
using M = BaseMatrix<float, SIZE, SIZE>;
M m1(a), m2(b), res;

for (auto _ : state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

#include "Eigen/Dense"
#include "benchmark/benchmark.h"
#include "gemm_header.h"
#include "shared/common.hpp"

static void gemm_eigen(benchmark::State& state) {
Eigen::Matrix<double, SIZE, SIZE> m1, m2, res;
Eigen::Matrix<float, SIZE, SIZE> m1, m2, res;

m1 = Eigen::Matrix<double, SIZE, SIZE>::Random();
m2 = Eigen::Matrix<double, SIZE, SIZE>::Random();
m1 = Eigen::Matrix<float, SIZE, SIZE>::Random();
m2 = Eigen::Matrix<float, SIZE, SIZE>::Random();

for (auto _ : state) {
benchmark::DoNotOptimize(res);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@

#include <iostream>

static constexpr int SIZE = 8;
constexpr int repetitions = 20;

template <typename T>
void print_matrix(T *matrix, int n, int m) {
for (int i = 0; i < n; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
#define GEMM_SIMPLE_H

#include "benchmark/benchmark.h"
#include "gemm_header.h"
#include "shared/common.hpp"

static void gemm_simple(benchmark::State& state) {
alignas(32) double a[SIZE * SIZE];
alignas(32) double b[SIZE * SIZE];
alignas(32) double c[SIZE * SIZE];
alignas(32) float a[SIZE * SIZE];
alignas(32) float b[SIZE * SIZE];
alignas(32) float c[SIZE * SIZE];

for (int i = 0; i < SIZE; i++) {
for (int j = 0; j < SIZE; j++) {
Expand All @@ -17,7 +17,7 @@ static void gemm_simple(benchmark::State& state) {

for (int i = 0; i < SIZE; i++) {
for (int j = 0; j < SIZE; j++) {
double val;
float val;
if (i == 0 && j == 1)
val = -1;
else if (i == 1 && j == 0)
Expand All @@ -35,10 +35,10 @@ static void gemm_simple(benchmark::State& state) {
for (auto _ : state) {
benchmark::DoNotOptimize(c);

gemm<double, SIZE>(a, b, c);
gemm<double, SIZE>(b, c, a);
gemm<float, SIZE>(a, b, c);
gemm<float, SIZE>(b, c, a);

// print_matrix<double>(a, SIZE, SIZE);
// print_matrix<float>(a, SIZE, SIZE);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

#include "benchmark/benchmark.h"
#include "blaze/Math.h"
#include "gemm_header.h"
#include "shared/common.hpp"
#include "random.hpp"

static void inversion_blaze(benchmark::State& state) {
blaze::StaticMatrix<double, SIZE, SIZE, blaze::rowMajor> m;
blaze::StaticMatrix<float, SIZE, SIZE, blaze::rowMajor> m;

for (int i = 0; i < SIZE; i++) {
for (int j = 0; j < SIZE - i; j++) {
Expand All @@ -16,7 +16,7 @@ static void inversion_blaze(benchmark::State& state) {
}
}

blaze::SymmetricMatrix<blaze::StaticMatrix<double, SIZE, SIZE, blaze::rowMajor>> m1(m), res;
blaze::SymmetricMatrix<blaze::StaticMatrix<float, SIZE, SIZE, blaze::rowMajor>> m1(m), res;

for (auto _ : state) {
benchmark::DoNotOptimize(res);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "benchmark/benchmark.h"
#include "fast5x5/fast5x5.hpp"
#include "gemm_header.h"
#include "shared/common.hpp"
#include "random.hpp"

static void inversion_custom(benchmark::State& state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "Eigen/Dense"
#include "benchmark/benchmark.h"
#include "gemm_header.h"
#include "shared/common.hpp"

static void inversion_eigen(benchmark::State& state) {
Eigen::Matrix<float, SIZE, SIZE> m1, res;
Expand Down

0 comments on commit 125a084

Please sign in to comment.