@@ -59,29 +59,27 @@ struct Error{
59
59
inline std::optional<Error> global_error_settings;
60
60
61
61
struct ErrorInjectionTracking {
62
- inline static int64_t error_counter;
62
+ inline static size_t error_counter;
63
63
inline static std::mt19937 random_gen{0 };
64
64
inline static size_t global_next_inject = 0 ;
65
65
inline static std::chrono::duration<long int , std::nano> elapsed_seconds{};
66
66
inline static std::chrono::duration<long int , std::nano> total_error_time{};
67
- inline static std::mutex global_time_mutex;
68
67
};
69
68
70
69
// Calculates coordinate formulas from linear iterator
71
70
template < typename View>
72
71
auto get_inject_indices_array ( const View &view, std::size_t next_inject ){
73
72
74
73
std::array<std::size_t , 8 > indices {};
75
- size_t dim_product = 1 ;
74
+ size_t next_inject_copy = next_inject ;
76
75
77
76
// View.extent() returns 1 for uninitialized dimensions
78
- // this array returns accurate coordinates up to the existing view rank
79
- // coordinates past rank are inaccurate, but are truncated by view.access() in the main injector
80
- indices[0 ] = next_inject % view.extent (0 );
81
-
82
- for (int i=1 ;i<8 ;i++){
83
- indices[i] = ((next_inject - (indices[i-1 ] * dim_product)) / (dim_product * view.extent (i-1 ) )) % view.extent (i);
84
- dim_product = dim_product * view.extent (i-1 );
77
+ // this array returns accurate coordinates up to the existing view rank
78
+ // and zero for the rest, which are truncated by view.access() in the main injector
79
+ // assumes column-major (Fortran) ordering
80
+ for (int i=0 ;i<8 ;i++){
81
+ indices[i] = next_inject_copy % view.extent (i);
82
+ next_inject_copy /= view.extent (i);
85
83
}
86
84
87
85
return indices;
@@ -104,6 +102,7 @@ void error_injection(View& original, View& copy_0, View& copy_1)
104
102
105
103
size_t next_inject = ErrorInjectionTracking::global_next_inject;
106
104
std::array<size_t , 8 > indices {};
105
+ // auto access = std::mem_fn(&View::access);
107
106
108
107
for (int j = 0 ; j<=2 ; j++){
109
108
while (next_inject < total_extent)
@@ -112,19 +111,28 @@ void error_injection(View& original, View& copy_0, View& copy_1)
112
111
if (j==0 ){// Inject in the original if j is 0
113
112
// replace value with noise
114
113
original.access (indices[0 ],indices[1 ],indices[2 ],indices[3 ],indices[4 ],indices[5 ],indices[6 ],indices[7 ])
115
- = static_cast <typename View::value_type>(ErrorInjectionTracking::random_gen ());
114
+ // Incorrect because access expects individual indices, not a tuple.
115
+ // Hence the need to use apply with a tuple
116
+ // access(original, indices)
117
+ // auto tuple = std::make_tuple(original, indices);
118
+ // std::apply(access, tuple)
119
+ = static_cast <typename View::value_type>(ErrorInjectionTracking::random_gen ());
116
120
ErrorInjectionTracking::error_counter++;
117
121
}
122
+ // #if 0
118
123
else if (j==1 ){// Else inject in one of the other two copies, copy[0]
119
124
copy_0.access (indices[0 ],indices[1 ],indices[2 ],indices[3 ],indices[5 ],indices[5 ],indices[6 ],indices[7 ])
120
- = static_cast <typename View::value_type>(ErrorInjectionTracking::random_gen ());
125
+ // access(copy_0, indices)
126
+ = static_cast <typename View::value_type>(ErrorInjectionTracking::random_gen ());
121
127
ErrorInjectionTracking::error_counter++;
122
128
}
123
129
else {// or copy[1]
124
130
copy_1.access (indices[0 ],indices[1 ],indices[2 ],indices[3 ],indices[5 ],indices[5 ],indices[6 ],indices[7 ])
125
- = static_cast <typename View::value_type>(ErrorInjectionTracking::random_gen ());
131
+ // access(copy_1, indices)
132
+ = static_cast <typename View::value_type>(ErrorInjectionTracking::random_gen ());
126
133
ErrorInjectionTracking::error_counter++;
127
134
}
135
+ // #endif
128
136
next_inject = global_error_settings->geometric (ErrorInjectionTracking::random_gen)+next_inject+1 ;
129
137
}
130
138
if (total_extent != 1 ){
@@ -137,10 +145,11 @@ void error_injection(View& original, View& copy_0, View& copy_1)
137
145
KOKKOS_INLINE_FUNCTION
138
146
void print_total_error_time () {
139
147
140
- ErrorInjectionTracking::global_time_mutex.lock ();
148
+ static std::mutex global_time_mutex;
149
+ global_time_mutex.lock ();
141
150
std::cout << " The value of ErrorInjectionTracking::total_error_time.count() is " << ErrorInjectionTracking::total_error_time.count () << " nanoseconds." << std::endl;
142
151
std::cout << " The total number of errors inserted is " << ErrorInjectionTracking::error_counter << " errors." << std::endl;
143
- ErrorInjectionTracking:: global_time_mutex.unlock ();
152
+ global_time_mutex.unlock ();
144
153
145
154
}
146
155
0 commit comments