Skip to content

Commit 662e5e3

Browse files
committed
converted static test matrix include files to an API that uses files with the matrix data
1 parent 052f588 commit 662e5e3

File tree

8 files changed

+338
-28
lines changed

8 files changed

+338
-28
lines changed

Diff for: CMakeLists.txt

+14
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,20 @@ else(NOT CMAKE_BUILD_TYPE)
5858
endif(CMAKE_BUILD_TYPE STREQUAL "Debug")
5959
endif(NOT CMAKE_BUILD_TYPE)
6060

61+
####
62+
# Set the path to the data directory
63+
set(TEST_MATRIX_DATA_DIR "${CMAKE_SOURCE_DIR}/data/matrices")
64+
# Configure a header file that will contain the data directory path
65+
66+
configure_file(
67+
"${CMAKE_SOURCE_DIR}/config/TestMatrixDataDirConfig.hpp.in"
68+
"${CMAKE_BINARY_DIR}/generated/TestMatrixDataDirConfig.hpp"
69+
)
70+
71+
# Include the binary directory to find the generated header file
72+
include_directories("${CMAKE_BINARY_DIR}/generated")
73+
74+
6175
####
6276
# Set build options
6377
# MSVC generates SSE/SSE2 code by default. No support for SSE3 as of 7/15/2018

Diff for: applications/performance/ir/roundAndReplace.cpp

+12-7
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
#include <universal/blas/blas.hpp>
2727
#include <universal/blas/ext/solvers/fused_backsub.hpp>
2828
#include <universal/blas/ext/solvers/fused_forwsub.hpp>
29-
#include <universal/blas/matrices/testsuite.hpp>
29+
// get the test matrix database API
30+
#include <universal/blas/serialization/test_matrix.hpp>
3031

3132
/// <summary>
3233
/// run one LUIR experiment with Round-and-Replace preconditioning
@@ -92,16 +93,20 @@ try {
9293
using namespace sw::universal;
9394
using namespace sw::universal::blas;
9495

95-
std::string testMatrix = std::string("west0132");
96+
std::string testMatrix;
9697
std::streamsize old_precision = std::cout.precision();
9798
std::streamsize new_precision = 7;
9899
std::cout << std::setprecision(new_precision);
99100

100-
testMatrix = std::string("lu4");
101-
matrix<double> ref = getTestMatrix(testMatrix);
102-
std::cout << "Size: (" << ref.rows() << ", " << ref.cols() << ")\n";
103-
std::cout << "Condition Number = " << kappa(testMatrix) << '\n';
104-
// std::cout << "Condition estimate: " << condest(ref) << '\n';
101+
for (auto & matrixName : TestMatrixList) {
102+
std::cout << matrixName << '\n';
103+
testMatrix = std::string(matrixName);
104+
matrix<double> ref = getTestMatrix(testMatrix);
105+
std::cout << "Size: (" << ref.rows() << ", " << ref.cols() << ")\n";
106+
std::cout << "Condition Number = " << kappa(testMatrix) << '\n';
107+
// std::cout << "Condition estimate: " << condest(ref) << '\n';
108+
}
109+
105110

106111
// we want to create a table of results for the different low precision types
107112
// matrix fp64 fp32 fp16 fp8 fp4 bf16 posit32 posit24 posit16 posit12 posit8

Diff for: config/TestMatrixDataDirConfig.hpp.in

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// TestMatrixDataDirConfig.hpp.in
2+
#pragma once
3+
4+
// Define the path to the test matrix data directory
5+
#define TEST_MATRIX_DATA_DIRECTORY "${CMAKE_SOURCE_DIR}/data/matrices"

Diff for: include/universal/blas/matrix.hpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -297,18 +297,20 @@ std::ostream& operator<<(std::ostream& ostr, const matrix<Scalar>& A) {
297297

298298
template<typename Scalar>
299299
std::istream& operator>>(std::istream& istr, matrix<Scalar>& A) {
300+
constexpr bool trace = false;
300301
using size_type = typename matrix<Scalar>::size_type;
301302
size_type m, n;
302303
istr >> m >> n;
303-
std::cout << m << ' ' << n << '\n';
304+
if constexpr (trace) std::cout << m << ' ' << n << '\n';
305+
A.resize(m, n);
304306
for (size_type i = 0; i < m; ++i) {
305307
double item;
306308
for (size_type j = 0; j < n; ++j) {
307309
istr >> item;
308-
std::cout << ' ' << item;
310+
if constexpr (trace) std::cout << ' ' << item;
309311
A(i, j) = Scalar(item);
310312
}
311-
std::cout << '\n';
313+
if constexpr (trace) std::cout << '\n';
312314
}
313315
return istr;
314316
}

Diff for: include/universal/blas/serialization/test_matrix.hpp

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
#pragma once
2+
// test_matrix.hpp: gather a test matrix from the Universal test matrix database
3+
//
4+
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
5+
// SPDX-License-Identifier: MIT
6+
//
7+
// This file is part of the universal numbers project
8+
#include <filesystem>
9+
#include <iostream>
10+
#include <fstream>
11+
#include <map>
12+
#include "TestMatrixDataDirConfig.hpp"
13+
14+
namespace sw {
15+
namespace universal {
16+
namespace blas {
17+
18+
// pick up the common data directory for the test suite
19+
std::string dataDirectory() {
20+
return std::string(TEST_MATRIX_DATA_DIRECTORY);
21+
}
22+
inline matrix<double> getTestMatrix(const std::string &testMatrix) {
23+
//std::cout << "Current working directory: " << std::filesystem::current_path() << '\n';
24+
std::string filename = dataDirectory() + std::string("/") + testMatrix + ".dat";
25+
matrix<double> A;
26+
std::ifstream fi;
27+
fi.open(filename);
28+
if (fi.good()) {
29+
fi >> A;
30+
fi.close();
31+
}
32+
else {
33+
std::cerr << "Unable to open matrix file " << filename << std::endl;
34+
fi.close();
35+
return A;
36+
}
37+
fi.close();
38+
39+
std::cout << "Matrix " << testMatrix << " loaded\n";
40+
return A;
41+
42+
}
43+
44+
const std::vector<std::string> TestMatrixList{
45+
"lambers_well",
46+
"lambers_ill",
47+
"h3",
48+
"q3",
49+
"int3",
50+
"faires74x3",
51+
"q4",
52+
"lu4",
53+
"s4",
54+
"rand4",
55+
"q5",
56+
"west0132",
57+
"west0167",
58+
"steam1",
59+
"steam3",
60+
"fs_183_1",
61+
"fs_183_3",
62+
"bwm200",
63+
"gre_343",
64+
"b1_ss",
65+
"cage3",
66+
"pores_1",
67+
"Stranke94",
68+
"saylr1",
69+
"Trefethen_20",
70+
"bcsstk01",
71+
"bcsstk03",
72+
"bcsstk04",
73+
"bcsstk05",
74+
"bcsstk22",
75+
"lund_a",
76+
"nos1",
77+
"arc130",
78+
"tumorAntiAngiogenesis_2"
79+
};
80+
81+
const std::map<std::string, double> ConditionNumber {
82+
{"lambers_well", 10.0},
83+
{"lambers_ill", 1.869050824603144e+08},
84+
{"h3", 1.8478e+11},
85+
{"q3", 1.2857e+06},
86+
{"int3", 43.6115},
87+
{"faires74x3", 15999},
88+
{"q4", 2.35},
89+
{"lu4", 11.6810},
90+
{"s4", 4.19},
91+
{"rand4", 27.81},
92+
{"q5", 1.1e+04},
93+
{"west0132", 4.2e+11},
94+
{"west0167", 2.827e+07},
95+
{"steam1", 2.827501e+07},
96+
{"steam3", 5.51e+10},
97+
{"fs_183_1", 1.5129e+13},
98+
{"fs_183_3", 1.5129e+13},
99+
{"bwm200", 2.412527e+03},
100+
{"gre_343", 1.119763e+02},
101+
{"b1_ss", 1.973732e+02},
102+
{"cage3", 1.884547e+01},
103+
{"pores_1", 1.812616e+06},
104+
{"Stranke94", 5.173300e+01},
105+
{"saylr1", 7.780581e+08},
106+
{"Trefethen_20", 6.308860e+01},
107+
{"bcsstk01", 8.8234e+05},
108+
{"bcsstk03", 6.791333e+06},
109+
{"bcsstk04", 2.292466e+06},
110+
{"bcsstk05", 1.428114e+04},
111+
{"bcsstk22", 1.107165e+05},
112+
{"lund_a", 2.796948e+06},
113+
{"nos1", 1.991546e+07},
114+
{"arc130", 6.0542e+10},
115+
{"tumorAntiAngiogenesis_2", 1.9893e+10}
116+
};
117+
118+
// Condition Number
119+
double kappa(const std::string& testMatrix) {
120+
if (ConditionNumber.find(testMatrix) != ConditionNumber.end()) {
121+
return ConditionNumber.at(testMatrix);
122+
}
123+
else {
124+
std::cerr << "Condition number for matrix " << testMatrix << " not found" << std::endl;
125+
}
126+
return 0.0;
127+
}
128+
}
129+
}
130+
}
131+

Diff for: linalg/data/serialization.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ try {
265265

266266
return 0;
267267

268+
// TODO: datafiles are not working yet: ETLO 3/25/2024
268269
TestCollectionSerialization();
269270

270271
TestVectorSerialization<double>();
@@ -302,7 +303,7 @@ try {
302303
#else
303304

304305
#if REGRESSION_LEVEL_1
305-
//nrOfFailedTestCases += ReportTestResult(VerifyCompress<lns<8,4>>(reportTestCases), "compress to lns<8,4>", "lns<8,4>");
306+
306307
#endif
307308

308309
#if REGRESSION_LEVEL_2

Diff for: linalg/data/test_matrices.cpp

+162
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
// test_matrices.cpp: convert test matrix include files to data files
2+
//
3+
// Copyright (C) 2017 Stillwater Supercomputing, Inc.
4+
// SPDX-License-Identifier: MIT
5+
//
6+
// This file is part of the universal numbers project, which is released under an MIT Open Source license.
7+
#include <universal/utility/directives.hpp>
8+
#include <cmath>
9+
#include <iostream>
10+
#include <iomanip>
11+
#include <fstream>
12+
#include <universal/blas/blas.hpp>
13+
#include <universal/blas/generators.hpp>
14+
#include <universal/blas/ext/solvers/fused_backsub.hpp>
15+
#include <universal/blas/ext/solvers/fused_forwsub.hpp>
16+
// Serialization
17+
#include <universal/blas/serialization/datafile.hpp>
18+
19+
#include <universal/verification/test_suite.hpp>
20+
#include <universal/blas/matrices/testsuite.hpp>
21+
22+
namespace sw {
23+
namespace universal {
24+
namespace blas {
25+
26+
static void WriteMatrixDataFile(const std::string& filename, const matrix<double>& A) {
27+
std::ofstream fo;
28+
fo.open(filename);
29+
fo << A;
30+
fo.close();
31+
}
32+
33+
static void GenerateMatrixDataFiles(const std::vector<std::string>& testMatrixNames) {
34+
for (auto matrixName : testMatrixNames) {
35+
WriteMatrixDataFile(matrixName + std::string(".dat"), getTestMatrix(matrixName));
36+
}
37+
}
38+
39+
}
40+
}
41+
}
42+
43+
// This is a program that we ran once to get the test matrices converted to data files
44+
//
45+
// We have no code in the regression side of the test so CI is a NOP
46+
47+
48+
// Regression testing guards: typically set by the cmake configuration, but MANUAL_TESTING is an override
49+
#define MANUAL_TESTING 0
50+
// REGRESSION_LEVEL_OVERRIDE is set by the cmake file to drive a specific regression intensity
51+
// It is the responsibility of the regression test to organize the tests in a quartile progression.
52+
//#undef REGRESSION_LEVEL_OVERRIDE
53+
#ifndef REGRESSION_LEVEL_OVERRIDE
54+
#undef REGRESSION_LEVEL_1
55+
#undef REGRESSION_LEVEL_2
56+
#undef REGRESSION_LEVEL_3
57+
#undef REGRESSION_LEVEL_4
58+
#define REGRESSION_LEVEL_1 1
59+
#define REGRESSION_LEVEL_2 1
60+
#define REGRESSION_LEVEL_3 1
61+
#define REGRESSION_LEVEL_4 1
62+
#endif
63+
64+
int main()
65+
try {
66+
using namespace sw::universal;
67+
using namespace sw::universal::blas;
68+
69+
std::string test_suite = "test matrices serialization";
70+
std::string test_tag = "test_matrices";
71+
bool reportTestCases = true;
72+
int nrOfFailedTestCases = 0;
73+
74+
ReportTestSuiteHeader(test_suite, reportTestCases);
75+
76+
#if MANUAL_TESTING
77+
78+
// set up the set of test matrices
79+
std::vector<std::string> allTestMatrices = {
80+
"lambers_well", // 2 x 2 well-conditioned matrix, K = 10.0
81+
"lambers_ill", // 2 x 2 ill-conditioned matrix, K = 1.869050824603144e+08
82+
"h3", // 3 x 3 test matrix, K = 1.8478e+11
83+
"int3", // 3 x 3 integer test matrix (low condition number), K = 43.6115
84+
"faires74x3", // 3 x 3 Burden Faires Ill-conditioned, K = 15999
85+
"q3", // 3 x 3 Variable test matrix (edit entries), K = 1.2857e+06
86+
"q4", // 4 x 4 test matrix, K = 2.35
87+
"q5", // 5 x 5 test matrix, K = 1.1e+04
88+
"lu4", // 4 x 4 test matrix, K = 11.6810
89+
"s4", // 4 x 4 test matrix, K = 4.19
90+
"rand4", // 4 x 4 random (low condition), K = 27.81
91+
"cage3", // 5 x 5 Directed Weighted Graph, K = 1.884547e+01
92+
"b1_ss", // 7 x 7 Chemical Process Simulation Problem, K = 1.973732e+02
93+
94+
"west0132", // 132 x 132 Chem. Simulation Process, K = 4.2e+11
95+
"west0167", // 167 x 167 Chemical Simulation Process, K = 2.827e+07
96+
"steam1", // 240 x 240 Computational Fluid Dynamics, K = 2.827501e+07
97+
"steam3", // 83 x 83 Computational Fluid Dynamics, K = 5.51e+10
98+
"fs_183_1", // 183 x 183 2D/3D Problem Sequence, K = 1.5129e+13
99+
"fs_183_3", // 183 x 183 2D/3D Problem Sequence, K = 1.5129e+13
100+
"bwm200", // 200 x 200 Chemical simulation, K = 2.412527e+03
101+
"gre_343", // 343 x 343 Directed Weighted Graph, K = 1.119763e+02
102+
"pores_1", // 30 x 30 Computational Fluid Dynamics, K = 1.812616e+06
103+
"Stranke94", // 10 x 10 Undirected Weighted Graph, K = 5.173300e+01
104+
"Trefethen_20", // 20 x 20 Combinatorial Problem, K = 6.308860e+01
105+
"bcsstk01", // 48 x 48 Structural Engineering, K = 8.8234e+05
106+
"bcsstk03", // 112 x 112 Structural Engineering, K = 6.791333e+06
107+
"bcsstk04", // 132 x 132 Structural Engineering, K = 2.292466e+06
108+
"bcsstk05", // 153 x 153 Structural Engineering, K = 1.428114e+04
109+
"bcsstk22", // 138 x 138 Structural Engineering, K = 1.107165e+05
110+
"lund_a", // 147 x 147 Structural Engineering, K = 2.796948e+06
111+
"nos1", // 237 x 237 Structural Engineering K = 1.991546e+07
112+
"arc130", // 130 x 130 K = 6.0542e+10
113+
"saylr1", // 238 x 238 Computational Fluid Dynamics, K = 7.780581e+08
114+
"tumorAntiAngiogenesis_2" // , K 1.9893e+10
115+
};
116+
GenerateMatrixDataFiles(allTestMatrices);
117+
118+
ReportTestSuiteResults(test_suite, nrOfFailedTestCases);
119+
return EXIT_SUCCESS;
120+
#else
121+
// CI is a NOP
122+
// we have no code in the regression side of the test
123+
#if REGRESSION_LEVEL_1
124+
125+
#endif
126+
127+
#if REGRESSION_LEVEL_2
128+
129+
#endif
130+
131+
#if REGRESSION_LEVEL_3
132+
133+
#endif
134+
135+
#if REGRESSION_LEVEL_4
136+
137+
#endif
138+
139+
ReportTestSuiteResults(test_suite, nrOfFailedTestCases);
140+
return (nrOfFailedTestCases > 0 ? EXIT_FAILURE : EXIT_SUCCESS);
141+
#endif
142+
}
143+
catch (char const* msg) {
144+
std::cerr << msg << std::endl;
145+
return EXIT_FAILURE;
146+
}
147+
catch (const sw::universal::universal_arithmetic_exception& err) {
148+
std::cerr << "Uncaught universal arithmetic exception: " << err.what() << std::endl;
149+
return EXIT_FAILURE;
150+
}
151+
catch (const sw::universal::universal_internal_exception& err) {
152+
std::cerr << "Uncaught universal internal exception: " << err.what() << std::endl;
153+
return EXIT_FAILURE;
154+
}
155+
catch (const std::runtime_error& err) {
156+
std::cerr << "Uncaught runtime exception: " << err.what() << std::endl;
157+
return EXIT_FAILURE;
158+
}
159+
catch (...) {
160+
std::cerr << "Caught unknown exception" << std::endl;
161+
return EXIT_FAILURE;
162+
}

0 commit comments

Comments
 (0)