STORMM Source Documentation
Loading...
Searching...
No Matches
split_fixed_precision.h
1// -*-c++-*-
2#ifndef STORMM_SPLIT_FIXED_PRECISION_H
3#define STORMM_SPLIT_FIXED_PRECISION_H
4
5#include <string>
6#include <climits>
7#include "copyright.h"
8#include "Accelerator/hybrid.h"
9#include "Constants/behavior.h"
10#include "Constants/scaling.h"
11#include "DataTypes/stormm_vector_types.h"
12#include "numeric_enumerators.h"
13
14namespace stormm {
15namespace numerics {
16
17using card::Hybrid;
18using constants::ExceptionResponse;
19using constants::PrecisionModel;
20
30constexpr llint max_int_accumulation_ll = (1LL << (int_bit_count_int - 1));
31constexpr double max_int_accumulation = max_int_accumulation_ll;
32constexpr float max_int_accumulation_f = max_int_accumulation;
33constexpr double max_llint_accumulation = max_int_accumulation * max_int_accumulation * 2.0;
34constexpr float max_llint_accumulation_f = max_llint_accumulation;
35constexpr int max_short_accumulation = (1 << 15);
37
42AccumulationMethod translateAccumulationMethod(const std::string &choice,
43 ExceptionResponse policy);
44
48std::string getAccumulationMethodName(AccumulationMethod method);
49
54AccumulationMethod chooseAccumulationMethod(int frc_bits);
55
62std::string fixedPrecisionRangeErrorMessage(int choice, int min_val, int max_val);
63
68void checkGlobalPositionBits(int choice);
69
74void checkLocalPositionBits(int choice);
75
80void checkVelocityBits(int choice);
81
86void checkForceBits(int choice);
87
92void checkEnergyBits(int choice);
93
99void checkChargeMeshBits(int choice, PrecisionModel pmodel);
100
108void checkFPVectorLength(size_t primary_length, size_t overflow_length, const char* caller,
109 const std::string &message = std::string(""));
110
133int2 hostFloatToInt63(const float fval);
134
135void hostFloatToInt63(const float fval, int *primary, int *overflow);
136
137void hostFloatToInt63(const float* fval, int* primary, int* overflow, size_t n_values,
138 float scale = 1.0f);
139
140void hostFloatToInt63(const float* fval_x, const float* fval_y, const float* fval_z,
141 int* primary_x, int* overflow_x, int* primary_y, int* overflow_y,
142 int* primary_z, int* overflow_z, size_t n_values, float scale = 1.0f);
143
144void hostFloatToInt63(const std::vector<float> &fval, std::vector<int> *primary,
145 std::vector<int> *overflow, float scale = 1.0f);
146
147void hostFloatToInt63(const Hybrid<float> &fval, Hybrid<int> *primary, Hybrid<int> *overflow,
148 float scale = 1.0f);
149
150void hostFloatToInt63(const std::vector<float> &fval_x, const std::vector<float> &fval_y,
151 const std::vector<float> &fval_z, std::vector<int> *primary_x,
152 std::vector<int> *overflow_x, std::vector<int> *primary_y,
153 std::vector<int> *overflow_y, std::vector<int> *primary_z,
154 std::vector<int> *overflow_z, float scale = 1.0f);
155
156void hostFloatToInt63(const Hybrid<float> &fval_x, const Hybrid<float> &fval_y,
157 const Hybrid<float> &fval_z, Hybrid<int> *primary_x, Hybrid<int> *overflow_x,
158 Hybrid<int> *primary_y, Hybrid<int> *overflow_y, Hybrid<int> *primary_z,
159 Hybrid<int> *overflow_z, float scale = 1.0f);
160
161int2 hostLongLongToInt63(const llint val);
162
163void hostLongLongToInt63(const llint val, int *primary, int *overflow);
164
165void hostLongLongToInt63(const llint* val, int* primary, int* overflow, size_t n_values);
166
167void hostLongLongToInt63(const llint* val_x, const llint* val_y, const llint* val_z,
168 int* primary_x, int* overflow_x, int* primary_y, int* overflow_y,
169 int* primary_z, int* overflow_z, size_t n_values);
170
171void hostLongLongToInt63(const std::vector<llint> &val, std::vector<int> *primary,
172 std::vector<int> *overflow);
173
174void hostLongLongToInt63(const std::vector<llint> &val_x, const std::vector<llint> &val_y,
175 const std::vector<llint> &val_z, std::vector<int> *primary_x,
176 std::vector<int> *overflow_x, std::vector<int> *primary_y,
177 std::vector<int> *overflow_y, std::vector<int> *primary_z,
178 std::vector<int> *overflow_z);
179
180void hostLongLongToInt63(const Hybrid<llint> &val, Hybrid<int> *primary, Hybrid<int> *overflow);
181
182void hostLongLongToInt63(const Hybrid<llint> &val_x, const Hybrid<llint> &val_y,
183 const Hybrid<llint> &val_z, Hybrid<int> *primary_x,
184 Hybrid<int> *overflow_x, Hybrid<int> *primary_y, Hybrid<int> *overflow_y,
185 Hybrid<int> *primary_z, Hybrid<int> *overflow_z);
186
187int2 hostDoubleToInt63(const double fval);
188
189void hostDoubleToInt63(const double fval, int *primary, int *overflow);
190
191int95_t hostDoubleToInt95(const double fval);
192
193void hostDoubleToInt95(const double fval, llint *primary, int *overflow);
194
195void hostDoubleToInt95(const double* dval, llint* primary, int* overflow, size_t n_values,
196 double scale = 1.0);
197
198void hostDoubleToInt95(const std::vector<double> &dval, std::vector<llint> *primary,
199 std::vector<int> *overflow, double scale = 1.0);
200
201void hostDoubleToInt95(const Hybrid<double> &dval, Hybrid<llint> *primary, Hybrid<int> *overflow,
202 double scale = 1.0);
203
204void hostDoubleToInt95(const double* dval_x, const double* dval_y, const double* dval_z,
205 llint* primary_x, int* overflow_x, llint* primary_y, int* overflow_y,
206 llint* primary_z, int* overflow_z, size_t n_values, double scale = 1.0);
207
208void hostDoubleToInt95(const std::vector<double> &dval_x, const std::vector<double> &dval_y,
209 const std::vector<double> &dval_z, std::vector<llint> *primary_x,
210 std::vector<int> *overflow_x, std::vector<llint> *primary_y,
211 std::vector<int> *overflow_y, std::vector<llint> *primary_z,
212 std::vector<int> *overflow_z, double scale = 1.0);
213
214void hostDoubleToInt95(const Hybrid<double> &dval_x, const Hybrid<double> &dval_y,
215 const Hybrid<double> &dval_z, Hybrid<llint> *primary_x,
216 Hybrid<int> *overflow_x, Hybrid<llint> *primary_y, Hybrid<int> *overflow_y,
217 Hybrid<llint> *primary_z, Hybrid<int> *overflow_z, double scale = 1.0);
219
240llint hostInt63ToLongLong(int primary, int overflow);
241
242void hostInt63ToLongLong(llint* result, const int* primary, const int* overflow, size_t n_values);
243
244void hostInt63ToLongLong(std::vector<llint> *result, const std::vector<int> &primary,
245 const std::vector<int> &overflow, size_t n_values);
246
247void hostInt63ToLongLong(Hybrid<llint> *result, const Hybrid<int> &primary,
248 const Hybrid<int> &overflow, size_t n_values);
249
250void hostInt63ToLongLong(llint* result_x, llint* result_y, llint* result_z, const int* primary_x,
251 const int* overflow_x, const int* primary_y, const int* overflow_y,
252 const int* primary_z, const int* overflow_z, size_t n_values);
253
254void hostInt63ToLongLong(std::vector<llint> *result_x, std::vector<llint> *result_y,
255 std::vector<llint> *result_z, const std::vector<int> &primary_x,
256 const std::vector<int> &overflow_x, const std::vector<int> &primary_y,
257 const std::vector<int> &overflow_y, const std::vector<int> &primary_z,
258 const std::vector<int> &overflow_z, size_t n_values);
259
260void hostInt63ToLongLong(Hybrid<llint> *result_x, Hybrid<llint> *result_y, Hybrid<llint> *result_z,
261 const Hybrid<int> &primary_x, const Hybrid<int> &overflow_x,
262 const Hybrid<int> &primary_y, const Hybrid<int> &overflow_y,
263 const Hybrid<int> &primary_z, const Hybrid<int> &overflow_z,
264 size_t n_values);
265
266double hostInt63ToDouble(int primary, int overflow);
267
268void hostInt63ToDouble(double* result, const int* primary, const int* overflow, size_t n_values,
269 double descale = 1.0);
270
271void hostInt63ToDouble(std::vector<double> *result, const std::vector<int> &primary,
272 const std::vector<int> &overflow, double descale = 1.0);
273
274void hostInt63ToDouble(Hybrid<double> *result, const Hybrid<int> &primary,
275 const Hybrid<int> &overflow, double descale = 1.0);
276
277float hostInt63ToFloat(int primary, int overflow);
278
279void hostInt63ToFloat(float* result, const int* primary, const int* overflow, size_t n_values,
280 float descale = 1.0f);
281
282void hostInt63ToFloat(std::vector<float> *result, const std::vector<int> &primary,
283 const std::vector<int> &overflow, float descale = 1.0f);
284
285void hostInt63ToFloat(Hybrid<float> *result, const Hybrid<int> &primary,
286 const Hybrid<int> &overflow, float descale = 1.0f);
287
288void hostInt63ToDouble(double* result_x, double* result_y, double* result_z, const int* primary_x,
289 const int* overflow_x, const int* primary_y, const int* overflow_y,
290 const int* primary_z, const int* overflow_z, size_t n_values,
291 double descale = 1.0);
292
293void hostInt63ToDouble(std::vector<double> *result_x, std::vector<double> *result_y,
294 std::vector<double> *result_z, const std::vector<int> &primary_x,
295 const std::vector<int> &overflow_x, const std::vector<int> &primary_y,
296 const std::vector<int> &overflow_y, const std::vector<int> &primary_z,
297 const std::vector<int> &overflow_z, size_t n_values, double descale = 1.0);
298
299void hostInt63ToDouble(Hybrid<double> *result_x, Hybrid<double> *result_y,
300 Hybrid<double> *result_z, const Hybrid<int> &primary_x,
301 const Hybrid<int> &overflow_x, const Hybrid<int> &primary_y,
302 const Hybrid<int> &overflow_y, const Hybrid<int> &primary_z,
303 const Hybrid<int> &overflow_z, size_t n_values, double descale = 1.0);
304
305void hostInt63ToFloat(float* result_x, float* result_y, float* result_z, const int* primary_x,
306 const int* overflow_x, const int* primary_y, const int* overflow_y,
307 const int* primary_z, const int* overflow_z, size_t n_values,
308 float descale = 1.0f);
309
310void hostInt63ToFloat(std::vector<float> *result_x, std::vector<float> *result_y,
311 std::vector<float> *result_z, const std::vector<int> &primary_x,
312 const std::vector<int> &overflow_x, const std::vector<int> &primary_y,
313 const std::vector<int> &overflow_y, const std::vector<int> &primary_z,
314 const std::vector<int> &overflow_z, float descale = 1.0f);
315
316void hostInt63ToFloat(Hybrid<float> *result_x, Hybrid<float> *result_y, Hybrid<float> *result_z,
317 const Hybrid<int> &primary_x, const Hybrid<int> &overflow_x,
318 const Hybrid<int> &primary_y, const Hybrid<int> &overflow_y,
319 const Hybrid<int> &primary_z, const Hybrid<int> &overflow_z,
320 float descale = 1.0f);
321
322double hostInt63ToDouble(int2 ival);
323
324float hostInt63ToFloat(int2 ival);
325
326double hostInt95ToDouble(const int95_t ival);
327
328double hostInt95ToDouble(llint primary, int overflow);
329
330void hostInt95ToDouble(double* result, const llint* primary, const int* overflow, size_t n_values,
331 double descale = 1.0);
332
333void hostInt95ToDouble(std::vector<double> *result, const std::vector<llint> &primary,
334 const std::vector<int> &overflow, double descale = 1.0);
335
336void hostInt95ToDouble(Hybrid<double> *result, const Hybrid<llint> &primary,
337 const Hybrid<int> &overflow, double descale = 1.0);
338
339void hostInt95ToDouble(double* result_x, double* result_y, double* result_z,
340 const llint* primary_x, const int* overflow_x, const llint* primary_y,
341 const int* overflow_y, const llint* primary_z, const int* overflow_z,
342 size_t n_values, double descale = 1.0);
343
344void hostInt95ToDouble(std::vector<double> *result_x, std::vector<double> *result_y,
345 std::vector<double> *result_z, const std::vector<llint> &primary_x,
346 const std::vector<int> &overflow_x, const std::vector<llint> &primary_y,
347 const std::vector<int> &overflow_y, const std::vector<llint> &primary_z,
348 const std::vector<int> &overflow_z, double descale = 1.0);
349
350void hostInt95ToDouble(Hybrid<double> *result_x, Hybrid<double> *result_y,
351 Hybrid<double> *result_z, const Hybrid<llint> &primary_x,
352 const Hybrid<int> &overflow_x, const Hybrid<llint> &primary_y,
353 const Hybrid<int> &overflow_y, const Hybrid<llint> &primary_z,
354 const Hybrid<int> &overflow_z, double descale = 1.0);
355
356double hostSplitFPToReal(const int95_t isfp);
357
358float hostSplitFPToReal(const int2 isfp);
360
361double hostSplitFPToReal(const int95_t isfp);
362
363float hostSplitFPToReal(const int2 isfp);
364
378void hostSplitAccumulation(const float fval, int *primary, int *overflow);
379
380void hostSplitAccumulation(const double fval, llint *primary, int *overflow);
382
408int95_t hostSplitFPSum(const int95_t a, const int95_t b);
409
410int2 hostSplitFPSum(const int2 a, const int2 b);
411
412int95_t hostSplitFPSum(const int95_t a, double breal);
413
414int2 hostSplitFPSum(const int2 a, float breal);
415
416int95_t hostSplitFPSum(const int95_t a, llint b_x, int b_y);
417
418int2 hostSplitFPSum(const int2 a, int b_x, int b_y);
419
420template <typename T> void hostSplitFPSum(T *a_x, int *a_y, const int95_t b);
421
422template <typename T> void hostSplitFPSum(T *a_x, int *a_y, const int2 b);
423
424int95_t hostInt95Sum(llint a_x, int a_y, llint b_x, int b_y);
425
426int2 hostInt63Sum(int a_x, int a_y, int b_x, int b_y);
427
428int95_t hostInt95Sum(llint a_x, int a_y, double breal);
429
430int2 hostInt63Sum(int a_x, int a_y, float breal);
432
438int95_t hostSplitFPSubtract(const int95_t a, const int95_t b);
439
440int2 hostSplitFPSubtract(const int2 a, const int2 b);
441
442int95_t hostSplitFPSubtract(const int95_t a, double breal);
443
444int2 hostSplitFPSubtract(const int2 a, float breal);
445
446int95_t hostSplitFPSubtract(const int95_t a, llint b_x, int b_y);
447
448int2 hostSplitFPSubtract(const int2 a, int b_x, int b_y);
449
450template <typename T> void hostSplitFPSubtract(T *a_x, int *a_y, const int95_t b);
451
452template <typename T> void hostSplitFPSubtract(T *a_x, int *a_y, const int2 b);
453
454int95_t hostInt95Subtract(llint a_x, int a_y, llint b_x, int b_y);
455
456int2 hostInt63Subtract(int a_x, int a_y, int b_x, int b_y);
457
458int95_t hostInt95Subtract(llint a_x, int a_y, double breal);
459
460int2 hostInt63Subtract(int a_x, int a_y, float breal);
462
472int95_t hostSplitFPMult(const int95_t a, int b);
473
474int95_t hostInt95Mult(llint a_x, int a_y, int b);
475
476int2 hostSplitFPMult(const int2 a, int b);
477
478int2 hostInt63Mult(int a_x, int a_y, int b);
480
497int2 hostChangeFPBits(const int2 fp, int native_bits, int output_bits);
498
499int95_t hostChangeFPBits(const int95_t fp, int native_bits, int output_bits);
500
501void hostChangeFPBits(std::vector<int95_t> *fp, int native_bits, int output_bits);
502
503void hostChangeFPBits(int* fp, int* fp_ovrf, size_t length, int native_bits, int output_bits);
504
505void hostChangeFPBits(llint* fp, int* fp_ovrf, size_t length, int native_bits, int output_bits);
506
507void hostChangeFPBits(std::vector<int> *fp, std::vector<int> *fp_ovrf, int native_bits,
508 int output_bits);
509
510void hostChangeFPBits(std::vector<llint> *fp, std::vector<int> *fp_ovrf, int native_bits,
511 int output_bits);
512
513void hostChangeFPBits(Hybrid<int> *fp, Hybrid<int> *fp_ovrf, int native_bits, int output_bits);
514
515void hostChangeFPBits(Hybrid<llint> *fp, Hybrid<int> *fp_ovrf, int native_bits, int output_bits);
517
535void fixedPrecisionGrid(std::vector<int95_t> *coordinates, const int95_t origin,
536 const int95_t increment);
537
538void fixedPrecisionGrid(std::vector<llint> *primary, std::vector<int> *overflow,
539 const int95_t origin, const int95_t increment);
540
541void fixedPrecisionGrid(Hybrid<llint> *primary, Hybrid<int> *overflow, const int95_t origin,
542 const int95_t increment);
543
544void fixedPrecisionGrid(llint *primary, int *overflow, const int95_t origin,
545 const int95_t increment, const size_t grid_size);
547
551int95_t operator+=(const int95_t lhs, const int95_t rhs);
552int95_t operator-=(const int95_t lhs, const int95_t rhs);
553int95_t operator+(const int95_t lhs, const int95_t rhs);
554int95_t operator-(const int95_t lhs, const int95_t rhs);
556
557} // namespace numerics
558} // namespace stormm
559
560#include "split_fixed_precision.tpp"
561
562// Make basic arithmetic functions native to the stormm namespace
563namespace stormm {
564 using numerics::hostFloatToInt63;
565 using numerics::hostDoubleToInt95;
566 using numerics::hostInt63ToDouble;
567 using numerics::hostInt63ToFloat;
568 using numerics::hostInt95ToDouble;
569 using numerics::hostSplitAccumulation;
570 using numerics::hostSplitFPSubtract;
571 using numerics::hostSplitFPSum;
572 using numerics::hostSplitFPToReal;
573 using numerics::hostInt95Subtract;
574 using numerics::hostInt95Sum;
575 using numerics::hostInt63Subtract;
576 using numerics::hostInt63Sum;
577 using numerics::operator+=;
578 using numerics::operator-=;
579 using numerics::operator+;
580 using numerics::operator-;
581 using numerics::max_int_accumulation;
582 using numerics::max_int_accumulation_f;
583 using numerics::max_int_accumulation_ll;
584 using numerics::max_llint_accumulation;
585 using numerics::max_llint_accumulation_f;
586 using numerics::max_short_accumulation;
587} // namespace stormm
588
589#endif
590
An evolution of GpuBuffer in pmemd.cuda, the Composite array has elements that are accessible from ei...
Definition hybrid.h:202