-
Notifications
You must be signed in to change notification settings - Fork 11
/
test_case_cholesky.h
115 lines (91 loc) · 2.88 KB
/
test_case_cholesky.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#ifndef __TEST_CASE_CHOLESKY_H__
#define __TEST_CASE_CHOLESKY_H__
/*
#include <type_traits>
#include <chrono>
#include <iostream>
#include <iomanip>
#include <random>
#include <thread>
#include <vector>
#include <map>
#include <assert.h>
*/
#include "test_case_with_time_measurements.h"
template<class T, bool IS_COL_MAJOR>
class TestCaseCholesky : public TestCaseWithTimeMeasurements {
protected:
const int m_dim;
const int m_num_elements;
T* m_L;
T* m_x;
T* m_y;
T* m_b;
public:
TestCaseCholesky( const int dim )
:m_dim ( dim )
,m_num_elements ( (dim+1) * dim / 2 )
,m_L ( new T [ m_num_elements ] )
,m_x ( new T [ dim ] )
,m_y ( new T [ dim ] )
,m_b ( new T [ dim ] )
{
if constexpr ( is_same<float, T>::value ) {
setDataElementType( FLOAT );
}
else if constexpr ( is_same<double, T>::value ) {
setDataElementType( DOUBLE );
}
else {
assert(true);
}
if constexpr (IS_COL_MAJOR) {
setMatrixColMajor( dim, dim );
}
else {
setMatrixRowMajor( dim, dim );
}
setVerificationType( RMS );
}
virtual ~TestCaseCholesky() {
delete[] m_L;
delete[] m_x;
delete[] m_y;
delete[] m_b;
}
virtual void compareTruth( const T* const L_baseline, const T* const x_baseline )
{
static_assert( is_same< float,T >::value || is_same< double,T >::value );
auto rms_on_matrix = getRMSDiffTwoVectors( getOutputPointer_L(), L_baseline, m_num_elements );
auto rms_on_x = getRMSDiffTwoVectors( getOutputPointer_x(), x_baseline, m_dim );
T accumm = 0.0;
T* L = getOutputPointer_L();
T* x = getOutputPointer_x();
for ( int i = 0; i < m_dim; i++ ) {
T sum = 0.0;
for (int j = 0; j < m_dim; j++ ) {
if ( i >= j ) {
sum += ( L[ lower_mat_index<IS_COL_MAJOR>( i, j, m_dim ) ] * x[j] );
}
else {
sum += ( L[ lower_mat_index<IS_COL_MAJOR>( j, i, m_dim ) ] * x[j] );
}
}
accumm += fabs( sum - m_b[i] );
}
auto residual_diff = accumm / ( m_dim * m_dim );
this->setRMS( rms_on_x );
}
virtual void setInitialStates( T* A, T* b ) {
memcpy( m_L, A, sizeof(T) * m_num_elements );
memcpy( m_b, b, sizeof(T) * m_dim );
}
virtual T* getOutputPointer_L() {
return m_L;
}
virtual T* getOutputPointer_x() {
return m_x;
}
virtual void run() = 0;
};
#endif /*__TEST_CASE_CHOLESKY_H__*/