-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#EDITS: updates to linalg module and file seperation
- Loading branch information
1 parent
e3e3af5
commit eb62e0e
Showing
2 changed files
with
75 additions
and
1 deletion.
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
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,74 @@ | ||
/************************************************************************* | ||
* Testing Mtx class operations | ||
************************************************************************/ | ||
#include "../../include/linalg/mtx.hpp" | ||
#include "../../include/linalg/mtx_tmpl.hpp" | ||
#include "t_matrix.hpp" | ||
#include <chrono> | ||
#include <cmath> | ||
#include <cstdint> | ||
#include <gtest/gtest.h> | ||
#include <iostream> | ||
#include <limits.h> | ||
#include <string> | ||
#include <vector> | ||
|
||
using namespace gpmp; | ||
#define TEST_COUT std::cerr << "\033[32m[ ] [ INFO ] \033[0m" | ||
|
||
namespace { | ||
|
||
TEST(MatrixArrayTestI32, AdditionPerformanceComparisonF90) { | ||
int mtx_size = 1024; | ||
TEST_COUT << "Matrix size : " << mtx_size << std::endl; | ||
// define input matrices A and B | ||
int *A = new int[mtx_size * mtx_size]; | ||
int *B = new int[mtx_size * mtx_size]; | ||
int *expected = new int[mtx_size * mtx_size]; | ||
int *result = new int[mtx_size * mtx_size]; | ||
|
||
// initialize random number generator | ||
std::random_device rd; | ||
std::mt19937 gen(rd()); | ||
std::uniform_int_distribution<int> distribution(1, 100); | ||
|
||
// populate matrices A and B with random values | ||
for (int i = 0; i < mtx_size; ++i) { | ||
for (int j = 0; j < mtx_size; ++j) { | ||
A[i * mtx_size + j] = distribution(gen); | ||
B[i * mtx_size + j] = distribution(gen); | ||
} | ||
} | ||
|
||
gpmp::linalg::Mtx mtx; | ||
auto start_std = std::chrono::high_resolution_clock::now(); | ||
|
||
// expected result using the naive implementation | ||
mtx.std_mtx_add(A, B, expected, mtx_size, mtx_size); | ||
|
||
auto end_std = std::chrono::high_resolution_clock::now(); | ||
std::chrono::duration<double> elapsed_seconds_std = end_std - start_std; | ||
|
||
auto start_intrin = std::chrono::high_resolution_clock::now(); | ||
|
||
// result using the intrinsics implementation | ||
mtx.mtx_add_f90(A, B, result, mtx_size, mtx_size); | ||
auto end_intrin = std::chrono::high_resolution_clock::now(); | ||
std::chrono::duration<double> elapsed_seconds_intrin = | ||
end_intrin - start_intrin; | ||
|
||
TEST_COUT << "INTRINSIC Matrix Addition Time : " | ||
<< elapsed_seconds_intrin.count() << " seconds" << std::endl; | ||
TEST_COUT << "STANDARD Matrix Addition Time : " | ||
<< elapsed_seconds_std.count() << " seconds" << std::endl; | ||
|
||
// compare the results | ||
ASSERT_TRUE(mtx_verif(expected, result, mtx_size, mtx_size)); | ||
delete[] A; | ||
delete[] B; | ||
delete[] expected; | ||
delete[] result; | ||
} | ||
|
||
|
||
} |