-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
organized everything into a Test class so that I can add more tests
- Loading branch information
1 parent
2f2f388
commit 56b92ab
Showing
10 changed files
with
179 additions
and
185 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
A_rows = 2 | ||
A_cols = 4 | ||
B_cols = 3 | ||
|
||
print_input=1 | ||
print_output=1 | ||
amrex.the_arena_is_managed=0 |
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 |
---|---|---|
@@ -1,9 +1,14 @@ | ||
CEXE_sources += main.cpp | ||
CEXE_sources += MathLib.cpp | ||
CEXE_sources += Test.cpp | ||
|
||
CEXE_headers += Test.H | ||
CEXE_headers += MathLib.H | ||
CEXE_headers += MatrixDef.H | ||
CEXE_headers += GlobalFuncs.H | ||
CEXE_headers += cudaErrorCheck.H | ||
|
||
VPATH_LOCATIONS += $(CODE_HOME)/Source | ||
INCLUDE_LOCATIONS += $(CODE_HOME)/Source | ||
|
||
include $(CODE_HOME)/Source/Tests/Make.package |
114 changes: 0 additions & 114 deletions
114
scripts/negf_cpp/math_libraries/Source/Matrix_NotUsed.H
This file was deleted.
Oops, something went wrong.
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,31 @@ | ||
#ifndef TEST_MATH_LIBRARY_H_ | ||
#define TEST_MATH_LIBRARY_H_ | ||
|
||
#include "Tests/All_Tests.H" | ||
|
||
template <typename Test=Test_MM_Mul> | ||
class Test_MathLibrary | ||
{ | ||
private: | ||
Test m_test; | ||
|
||
public: | ||
Test_MathLibrary(Test&& test_instance) : m_test(std::move(test_instance)) | ||
{ | ||
m_test.Define(); | ||
m_test.Initialize(); | ||
m_test.Print_Input(); | ||
} | ||
|
||
void Perform_Test() | ||
{ | ||
m_test.Perform_Test(); | ||
} | ||
|
||
void Print_Output() { | ||
m_test.Print_Output(); | ||
} | ||
|
||
}; | ||
|
||
#endif |
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,4 @@ | ||
#include "Test.H" | ||
|
||
//Explicit instantiation of the template | ||
template class Test_MathLibrary<Test_MM_Mul>; |
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,7 @@ | ||
#ifndef ALL_TESTS_H_ | ||
#define ALL_TESTS_H_ | ||
|
||
#include "Test_MM_Mul.H" | ||
|
||
#endif | ||
|
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,7 @@ | ||
CEXE_sources += Test_MM_Mul.cpp | ||
|
||
CEXE_headers += Test_MM_Mul.H | ||
CEXE_headers += All_Tests.H | ||
|
||
VPATH_LOCATIONS += $(CODE_HOME)/Source/Tests | ||
INCLUDE_LOCATIONS += $(CODE_HOME)/Source/Tests |
25 changes: 25 additions & 0 deletions
25
scripts/negf_cpp/math_libraries/Source/Tests/Test_MM_Mul.H
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,25 @@ | ||
#include "MatrixDef.H" | ||
|
||
class Test_MM_Mul | ||
{ | ||
private: | ||
int A_rows, A_cols, B_cols; | ||
std::vector<int> print_flags; | ||
|
||
Matrix2D h_A_data, h_B_data, h_C_data; | ||
Matrix2D d_A_data, d_B_data, d_C_data; | ||
|
||
ComplexType A_init_val= ComplexType(1., 2.); | ||
ComplexType B_init_val= ComplexType(-5., 3.); | ||
|
||
public: | ||
Test_MM_Mul(int a_rows, int a_cols, int b_cols, | ||
const std::vector<int>& flags); | ||
|
||
void Define(); | ||
void Initialize(); | ||
void Perform_Test(); | ||
void Print_Input(); | ||
void Print_Output(); | ||
|
||
}; |
83 changes: 83 additions & 0 deletions
83
scripts/negf_cpp/math_libraries/Source/Tests/Test_MM_Mul.cpp
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,83 @@ | ||
#include "Test_MM_Mul.H" | ||
#include "GlobalFuncs.H" | ||
#include "MathLib.H" | ||
#include <AMReX_Gpu.H> | ||
|
||
using namespace amrex; | ||
|
||
Test_MM_Mul::Test_MM_Mul(int a_rows, int a_cols, int b_cols, const std::vector<int>& flags): | ||
A_rows(a_rows), A_cols(a_cols), B_cols(b_cols), print_flags(flags) {} | ||
|
||
|
||
void | ||
Test_MM_Mul:: Define() | ||
{ | ||
h_A_data.resize({0,0},{A_rows, A_cols},The_Pinned_Arena()); | ||
d_A_data.resize({0,0},{A_rows, A_cols},The_Arena()); | ||
h_B_data.resize({0,0},{A_cols, B_cols},The_Pinned_Arena()); | ||
d_B_data.resize({0,0},{A_cols, B_cols},The_Arena()); | ||
h_C_data.resize({0,0},{A_rows, B_cols},The_Pinned_Arena()); | ||
d_C_data.resize({0,0},{A_rows, B_cols},The_Arena()); | ||
} | ||
|
||
|
||
void | ||
Test_MM_Mul:: Initialize() | ||
{ | ||
ComplexType zero(0., 0.); | ||
|
||
Define_Table2D(h_A_data, A_init_val); | ||
Define_Table2D(h_B_data, B_init_val); | ||
SetVal_Table2D(h_C_data, zero); | ||
|
||
d_A_data.copy(h_A_data); | ||
d_B_data.copy(h_B_data); | ||
d_C_data.copy(h_C_data); | ||
} | ||
|
||
|
||
void | ||
Test_MM_Mul:: Print_Input() | ||
{ | ||
if(print_flags[0]) { | ||
Print_Table2D(h_A_data, "A"); | ||
const auto& h_A = h_A_data.const_table(); | ||
const auto& h_B = h_B_data.const_table(); | ||
|
||
amrex::Print() << "\nPrinting h_A using h_A.p\n"; | ||
|
||
//Usage Error: In the forloop we should be using (i < dim_A[0]*dim_A[1]) | ||
//But currently we need to add a buffer of 1 unit size to print properly! | ||
for(int i=0; i<(A_rows+1)*A_cols; ++i) | ||
{ | ||
amrex::Print() << i << " "<< *(h_A.p+i) << "\n"; | ||
} | ||
|
||
Print_Table2D(h_B_data, "B"); | ||
} | ||
} | ||
|
||
|
||
void | ||
Test_MM_Mul:: Perform_Test() | ||
{ | ||
const auto& d_A = d_A_data.const_table(); | ||
const auto& d_B = d_B_data.const_table(); | ||
const auto& d_C = d_C_data.table(); | ||
|
||
MathLib::MatrixMatrixMultiply(d_C.p, d_A.p, d_B.p, A_rows, A_cols, B_cols); | ||
} | ||
|
||
|
||
void | ||
Test_MM_Mul:: Print_Output() | ||
{ | ||
if(print_flags[1]) | ||
{ | ||
//copy C from device to host and print | ||
h_C_data.copy(d_C_data); | ||
Gpu::streamSynchronize(); | ||
|
||
Print_Table2D(h_C_data, "C"); | ||
} | ||
} |
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