ATLAS Offline Software
Loading...
Searching...
No Matches
CaloRecGPU::Helpers Namespace Reference

Namespaces

namespace  Constants
 !
namespace  MemoryContext
 ! Holds dummy classes just to identify the place in which memory lives.

Classes

struct  maybe_allocate
 Possibly holds an object in its internal buffer. More...
class  MemoryManagement
 ! Handles allocation of a type T, using indexer as the integer type to indicate sizes. More...
struct  separate_thread_accessor
 ! More...
class  separate_thread_holder
 Manages objects of type T in a thread-safe way, ensuring that there's an object available for each separate thread while minimizing the number of allocations. More...
class  SimpleContainer
 Holds a run-time amount of objects of type \T, measuring sizes with indexer, in memory context Context. More...
class  SimpleContainer< T, indexer, Context, false >
class  SimpleContainer< T, indexer, Context, true >
class  SimpleHolder
 Holds one objects of type \T in memory context Context. More...
class  SimpleHolder< T, Context, false >
class  SimpleHolder< T, Context, true >

Typedefs

template<class T, class indexer = unsigned int>
using CPU_array = SimpleContainer<T, indexer, MemoryContext::CPU, true>
 Holds a run-time specified amount of objects of type T in CPU memory.
template<class T, class indexer = unsigned int>
using CUDA_array = SimpleContainer<T, indexer, MemoryContext::CUDAGPU, true>
 Holds a run-time specified amount of objects of type T in CUDA GPU memory.
template<class T, class indexer = unsigned int>
using CUDA_kernel_array = SimpleContainer<T, indexer, MemoryContext::CUDAGPU, false>
 Non-owning pointer to an array of T in CUDA GPU memory.
template<class T>
using CPU_object = SimpleHolder<T, MemoryContext::CPU, true>
 Holds an object of type T in CPU memory.
template<class T>
using CUDA_object = SimpleHolder<T, MemoryContext::CUDAGPU, true>
 Holds an object of type T in CUDA GPU memory.
template<class T>
using CUDA_kernel_object = SimpleHolder<T, MemoryContext::CUDAGPU, false>
 Non-owning pointer to an object of type T in CUDA GPU memory.
template<class T>
using CUDA_pinned_CPU_object = SimpleHolder<T, MemoryContext::CUDAPinnedCPU, true>
 Holds an object of type T in CUDA GPU memory.

Functions

template<class T1, class T2>
constexpr auto int_ceil_div (const T1 num, const T2 denom)
 Returns the ceiling of num/denom, with proper rounding.
template<class T1, class T2>
constexpr auto int_floor_div (const T1 num, const T2 denom)
 Returns the floor of num/denom, with proper rounding.
template<class Base = float, class Exp = int>
constexpr Base compile_time_pow2 (const Exp exp)
 Returns 2 to the power of exp.
template<class T>
constexpr unsigned int int_ceil_log_2 (T num)
 Returns the ceiling of the base-2 logarithm of a number (i.
template<class T>
constexpr unsigned char Pearson_hash (const T number)
 Calculates a Pearson hash from @ number.
template<class T>
constexpr unsigned short Pearson_hash_16_bit (const T number)
 Calculates a 16-bit Pearson hash from @ number.
static CUDA_HOS_DEV float erf_inv_wrapper (const float x)
static CUDA_HOS_DEV float regularize_angle (const float b, const float a=0.f)
static CUDA_HOS_DEV double regularize_angle (const double b, const double a=0.)
template<class T>
static CUDA_HOS_DEVangular_difference (const T x, const T y)
static CUDA_HOS_DEV float eta_from_coordinates (const float x, const float y, const float z)
static CUDA_HOS_DEV double eta_from_coordinates (const double x, const double y, const double z)
static CUDA_HOS_DEV void partial_kahan_babushka_neumaier_sum (const float &to_add, float &sum, float &corr)
 Implements one step of a Kahan-Babushka-Neumaier sum by adding to_add to sum with the correction term corr.
template<class ... Floats, class disabler = std::enable_if_t < (std::is_same_v<std::decay_t<Floats>, float> && ...) >>
CUDA_HOS_DEV float sum_kahan_babushka_neumaier (const Floats &... fs)
 Adds a list of floats using the Kahan-Babushka-Neumaier algorithm for greater precision (at the cost of additional operations).
static CUDA_HOS_DEV float product_sum_cornea_harrison_tang (const float a, const float b, const float c, const float d)
static CUDA_HOS_DEV float corrected_dot_product (const float a_1, const float a_2, const float a_3, const float b_1, const float b_2, const float b_3)
CUDA_HOS_DEV float corrected_dot_product (const float(&a)[3], const float(&b)[3])
static CUDA_HOS_DEV void corrected_cross_product (float(&res)[3], const float a1, const float a2, const float a3, const float b1, const float b2, const float b3)
static CUDA_HOS_DEV void corrected_cross_product (float(&res)[3], const float(&x)[3], const float(&y)[3])
static CUDA_HOS_DEV float corrected_magn_cross_product (const float a1, const float a2, const float a3, const float b1, const float b2, const float b3)
static CUDA_HOS_DEV float corrected_magn_cross_product (const float(&x)[3], const float(&y)[3])

Typedef Documentation

◆ CPU_array

template<class T, class indexer = unsigned int>
using CaloRecGPU::Helpers::CPU_array = SimpleContainer<T, indexer, MemoryContext::CPU, true>

Holds a run-time specified amount of objects of type T in CPU memory.

Definition at line 1241 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

◆ CPU_object

Holds an object of type T in CPU memory.

Definition at line 1659 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

◆ CUDA_array

template<class T, class indexer = unsigned int>
using CaloRecGPU::Helpers::CUDA_array = SimpleContainer<T, indexer, MemoryContext::CUDAGPU, true>

Holds a run-time specified amount of objects of type T in CUDA GPU memory.

Definition at line 1245 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

◆ CUDA_kernel_array

template<class T, class indexer = unsigned int>
using CaloRecGPU::Helpers::CUDA_kernel_array = SimpleContainer<T, indexer, MemoryContext::CUDAGPU, false>

Non-owning pointer to an array of T in CUDA GPU memory.

Definition at line 1249 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

◆ CUDA_kernel_object

Non-owning pointer to an object of type T in CUDA GPU memory.

Definition at line 1667 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

◆ CUDA_object

Holds an object of type T in CUDA GPU memory.

Definition at line 1663 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

◆ CUDA_pinned_CPU_object

Holds an object of type T in CUDA GPU memory.

Definition at line 1671 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

Function Documentation

◆ angular_difference()

template<class T>
CUDA_HOS_DEV T CaloRecGPU::Helpers::angular_difference ( const T x,
const T y )
inlinestatic

Definition at line 444 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

445 {
447 }
#define y
#define x
static CUDA_HOS_DEV float regularize_angle(const float b, const float a=0.f)

◆ compile_time_pow2()

template<class Base = float, class Exp = int>
Base CaloRecGPU::Helpers::compile_time_pow2 ( const Exp exp)
inlineconstexpr

Returns 2 to the power of exp.

Definition at line 233 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

234 {
235 Base ret = 1;
236 if (exp < 0)
237 {
238 for (Exp i = 0; i < -exp; ++i)
239 {
240 ret /= Base(2);
241 }
242 }
243 else
244 {
245 for (Exp i = 0; i < exp; ++i)
246 {
247 ret *= Base(2);
248 }
249 }
250 return ret;
251 }
H5Mergers.

◆ corrected_cross_product() [1/2]

CUDA_HOS_DEV void CaloRecGPU::Helpers::corrected_cross_product ( float(&) res[3],
const float a1,
const float a2,
const float a3,
const float b1,
const float b2,
const float b3 )
inlinestatic

Definition at line 589 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

590 {
591 res[0] = product_sum_cornea_harrison_tang(a2, b3, -a3, b2);
592 res[1] = product_sum_cornea_harrison_tang(a3, b1, -a1, b3);
593 res[2] = product_sum_cornea_harrison_tang(a1, b2, -a2, b1);
594 }
std::pair< std::vector< unsigned int >, bool > res
static CUDA_HOS_DEV float product_sum_cornea_harrison_tang(const float a, const float b, const float c, const float d)

◆ corrected_cross_product() [2/2]

CUDA_HOS_DEV void CaloRecGPU::Helpers::corrected_cross_product ( float(&) res[3],
const float(&) x[3],
const float(&) y[3] )
inlinestatic

Definition at line 598 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

599 {
600 corrected_cross_product(res, x[0], x[1], x[2], y[0], y[1], y[2]);
601 }
static CUDA_HOS_DEV void corrected_cross_product(float(&res)[3], const float a1, const float a2, const float a3, const float b1, const float b2, const float b3)

◆ corrected_dot_product() [1/2]

CUDA_HOS_DEV float CaloRecGPU::Helpers::corrected_dot_product ( const float a_1,
const float a_2,
const float a_3,
const float b_1,
const float b_2,
const float b_3 )
inlinestatic

Definition at line 564 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

566 {
567 using namespace std;
568
569 const float w_1 = a_1 * b_1;
570 const float w_2 = a_2 * b_2;
571 const float w_3 = a_3 * b_3;
572
573 const float e_1 = fmaf(a_1, b_1, -w_1);
574 const float e_2 = fmaf(a_2, b_2, -w_2);
575 const float e_3 = fmaf(a_3, b_3, -w_3);
576
577 return sum_kahan_babushka_neumaier(w_1, w_2, w_3, e_1, e_2, e_3);
578 }
CUDA_HOS_DEV float sum_kahan_babushka_neumaier(const Floats &... fs)
Adds a list of floats using the Kahan-Babushka-Neumaier algorithm for greater precision (at the cost ...
STL namespace.

◆ corrected_dot_product() [2/2]

CUDA_HOS_DEV float CaloRecGPU::Helpers::corrected_dot_product ( const float(&) a[3],
const float(&) b[3] )
inline

Definition at line 582 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

583 {
584 return corrected_dot_product(a[0], a[1], a[2], b[0], b[1], b[2]);
585 }
static Double_t a
static CUDA_HOS_DEV float corrected_dot_product(const float a_1, const float a_2, const float a_3, const float b_1, const float b_2, const float b_3)

◆ corrected_magn_cross_product() [1/2]

CUDA_HOS_DEV float CaloRecGPU::Helpers::corrected_magn_cross_product ( const float a1,
const float a2,
const float a3,
const float b1,
const float b2,
const float b3 )
inlinestatic

Definition at line 605 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

606 {
607 using namespace std;
608
609 const float r_1 = product_sum_cornea_harrison_tang(a2, b3, -a3, b2);
610 const float r_2 = product_sum_cornea_harrison_tang(a3, b1, -a1, b3);
611 const float r_3 = product_sum_cornea_harrison_tang(a1, b2, -a2, b1);
612
613#ifdef __CUDA_ARCH__
614 return norm3df(r_1, r_2, r_3);
615#else
616 return hypot(r_1, r_2, r_3);
617#endif
618
619 }

◆ corrected_magn_cross_product() [2/2]

CUDA_HOS_DEV float CaloRecGPU::Helpers::corrected_magn_cross_product ( const float(&) x[3],
const float(&) y[3] )
inlinestatic

Definition at line 623 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

624 {
625 return corrected_magn_cross_product(x[0], x[1], x[2], y[0], y[1], y[2]);
626 }
static CUDA_HOS_DEV float corrected_magn_cross_product(const float a1, const float a2, const float a3, const float b1, const float b2, const float b3)

◆ erf_inv_wrapper()

CUDA_HOS_DEV float CaloRecGPU::Helpers::erf_inv_wrapper ( const float x)
inlinestatic

Definition at line 357 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

358 {
359 using namespace std;
360#ifdef __CUDA_ARCH__
361 return erfinvf(x);
362#else
363 //Copied directly from ROOT...
364
365 int kMaxit = 50;
366 float kEps = 1e-14f;
367 float kConst = 0.8862269254527579f; // sqrt(pi)/2.0
368
369 if (abs(x) <= kEps)
370 {
371 return kConst * x;
372 }
373
374 // Newton iterations
375 float erfi, derfi, y0, y1, dy0, dy1;
376 if (fabsf(x) < 1.0f)
377 {
378 erfi = kConst * fabsf(x);
379 y0 = erff(0.9f * erfi);
380 derfi = 0.1f * erfi;
381 for (int iter = 0; iter < kMaxit; iter++)
382 {
383 y1 = 1.f - erfc(erfi);
384 dy1 = fabsf(x) - y1;
385 if (fabsf(dy1) < kEps)
386 {
387 if (x < 0)
388 {
389 return -erfi;
390 }
391 else
392 {
393 return erfi;
394 }
395 }
396 dy0 = y1 - y0;
397 derfi *= dy1 / dy0;
398 y0 = y1;
399 erfi += derfi;
400 if (fabsf(derfi / erfi) < kEps)
401 {
402 if (x < 0.f)
403 {
404 return -erfi;
405 }
406 else
407 {
408 return erfi;
409 }
410 }
411 }
412 }
413 return 0; //did not converge
414#endif
415 }

◆ eta_from_coordinates() [1/2]

CUDA_HOS_DEV double CaloRecGPU::Helpers::eta_from_coordinates ( const double x,
const double y,
const double z )
inlinestatic

Definition at line 471 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

472 {
473 using namespace std;
474 if (x != 0 || y != 0)
475 {
476#ifdef __CUDA_ARCH__
477 const float m = norm3d(x, y, z);
478#else
479 const float m = hypot(x, y, z);
480#endif
481 return 0.5 * log((m + z) / (m - z));
482 }
483 else
484 {
485 constexpr double s_etaMax = 22756.0;
486 return z + ((z > 0) - (z < 0)) * s_etaMax;
487 }
488 }
#define z

◆ eta_from_coordinates() [2/2]

CUDA_HOS_DEV float CaloRecGPU::Helpers::eta_from_coordinates ( const float x,
const float y,
const float z )
inlinestatic

Definition at line 450 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

451 {
452 using namespace std;
453
454 if (x != 0 || y != 0)
455 {
456#ifdef __CUDA_ARCH__
457 const float m = norm3df(x, y, z);
458#else
459 const float m = hypot(x, y, z);
460#endif
461 return 0.5f * logf((m + z) / (m - z));
462 }
463 else
464 {
465 constexpr float s_etaMax = 22756.0f;
466 return z + ((z > 0) - (z < 0)) * s_etaMax;
467 }
468 }

◆ int_ceil_div()

template<class T1, class T2>
auto CaloRecGPU::Helpers::int_ceil_div ( const T1 num,
const T2 denom )
inlineconstexpr

Returns the ceiling of num/denom, with proper rounding.

Definition at line 219 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

220 {
221 return num / denom + (num % denom != 0);
222 }

◆ int_ceil_log_2()

template<class T>
unsigned int CaloRecGPU::Helpers::int_ceil_log_2 ( T num)
inlineconstexpr

Returns the ceiling of the base-2 logarithm of a number (i.

e. the minimum number of bits to represent this number).

Definition at line 259 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

260 {
261#if __cpp_lib_bitops
262 return sizeof(T) * CHAR_BIT - std::countl_zero(num);
263#else
264 unsigned int ret = 64;
265
266 for (unsigned long long int mask = 0x8000000000000000U; mask > 0; mask >>= 1U)
267 {
268 if (num & mask)
269 {
270 return ret;
271 }
272 --ret;
273 }
274
275 return ret;
276#endif
277 }

◆ int_floor_div()

template<class T1, class T2>
auto CaloRecGPU::Helpers::int_floor_div ( const T1 num,
const T2 denom )
inlineconstexpr

Returns the floor of num/denom, with proper rounding.

Definition at line 226 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

227 {
228 return num / denom;
229 }

◆ partial_kahan_babushka_neumaier_sum()

CUDA_HOS_DEV void CaloRecGPU::Helpers::partial_kahan_babushka_neumaier_sum ( const float & to_add,
float & sum,
float & corr )
inlinestatic

Implements one step of a Kahan-Babushka-Neumaier sum by adding to_add to sum with the correction term corr.

Definition at line 493 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

494 {
495 const float t = sum + to_add;
496
497 const bool test = fabsf(sum) >= fabsf(to_add);
498
499 const float opt_1 = (sum - t) + to_add;
500 const float opt_2 = (to_add - t) + sum;
501
502 corr += (test) * opt_1 + (!test) * opt_2;
503
504 sum = t;
505 }

◆ Pearson_hash()

template<class T>
unsigned char CaloRecGPU::Helpers::Pearson_hash ( const T number)
inlineconstexpr

Calculates a Pearson hash from @ number.

Definition at line 282 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

283 {
284 constexpr unsigned char initial_value = 42;
285 //The answer.
286
287 constexpr unsigned char c_mult = 7;
288 constexpr unsigned char c_add = 1;
289 //For our "look up table": table[i] = c_mult * i + c_add
290 //For an appropriate choice of constants (such as this),
291 //this will be bijective (modulo 255), as required.
292
293 unsigned char ret = initial_value;
294
295 for (unsigned int i = 0; i < sizeof(T); i += sizeof(unsigned char))
296 {
297 const unsigned char to_hash = number >> (i * CHAR_BIT);
298 const unsigned char operand = ret ^ to_hash;
299 ret = c_mult * operand + c_add;
300 }
301
302 return ret;
303 }
std::string number(const double &d, const std::string &s)
Definition utils.cxx:186

◆ Pearson_hash_16_bit()

template<class T>
unsigned short CaloRecGPU::Helpers::Pearson_hash_16_bit ( const T number)
inlineconstexpr

Calculates a 16-bit Pearson hash from @ number.

Definition at line 309 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

310 {
311 constexpr unsigned short initial_value = 42754;
312 //The answer and the standard.
313
314 constexpr unsigned short c_mult = 7;
315 constexpr unsigned short c_add = 1;
316 //For our "look up table": table[i] = c_mult * i + c_add
317 //For an appropriate choice of constants (such as this),
318 //this will be bijective (modulo 255), as required.
319
320 unsigned short ret = initial_value;
321
322 for (unsigned int i = 0; i < sizeof(T); i += sizeof(unsigned short))
323 {
324 const unsigned short to_hash = number >> (i * CHAR_BIT);
325 const unsigned short operand = ret ^ to_hash;
326 ret = c_mult * operand + c_add;
327 }
328
329 return ret;
330 }

◆ product_sum_cornea_harrison_tang()

CUDA_HOS_DEV float CaloRecGPU::Helpers::product_sum_cornea_harrison_tang ( const float a,
const float b,
const float c,
const float d )
inlinestatic

Definition at line 549 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

550 {
551 using namespace std;
552
553 const float w_1 = a * b;
554 const float w_2 = c * d;
555
556 const float e_1 = fmaf(a, b, -w_1);
557 const float e_2 = fmaf(c, d, -w_2);
558
559 return sum_kahan_babushka_neumaier(w_1, w_2, e_1, e_2);
560 }

◆ regularize_angle() [1/2]

CUDA_HOS_DEV double CaloRecGPU::Helpers::regularize_angle ( const double b,
const double a = 0. )
inlinestatic

Definition at line 432 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

434 {
435 using namespace std;
436 constexpr double pi = Helpers::Constants::pi<double>;
437 constexpr double two_pi = 2 * pi;
438 const double ret = remainderf(b, two_pi);
439 return ret + ((ret < a - pi) - (ret > a + pi)) * two_pi;
440 }
#define pi

◆ regularize_angle() [2/2]

CUDA_HOS_DEV float CaloRecGPU::Helpers::regularize_angle ( const float b,
const float a = 0.f )
inlinestatic

Definition at line 421 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

423 {
424 using namespace std;
425 constexpr float pi = Helpers::Constants::pi<float>;
426 constexpr float two_pi = 2 * pi;
427 const float ret = remainderf(b, two_pi);
428 return ret + ((ret < a - pi) - (ret > a + pi)) * two_pi;
429 }

◆ sum_kahan_babushka_neumaier()

template<class ... Floats, class disabler = std::enable_if_t < (std::is_same_v<std::decay_t<Floats>, float> && ...) >>
CUDA_HOS_DEV float CaloRecGPU::Helpers::sum_kahan_babushka_neumaier ( const Floats &... fs)
inline

Adds a list of floats using the Kahan-Babushka-Neumaier algorithm for greater precision (at the cost of additional operations).

Definition at line 511 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

512 {
513 float ret = 0.f;
514 float corr = 0.f;
515
516 (partial_kahan_babushka_neumaier_sum(fs, ret, corr), ...);
517
518 return ret + corr;
519 }
static Double_t fs
static CUDA_HOS_DEV void partial_kahan_babushka_neumaier_sum(const float &to_add, float &sum, float &corr)
Implements one step of a Kahan-Babushka-Neumaier sum by adding to_add to sum with the correction term...