11#ifndef GPUCA_GPUCODE_DEVICE
35#elif defined(__GNUC__) || defined(__clang__)
36 little = __ORDER_LITTLE_ENDIAN__,
37 big = __ORDER_BIG_ENDIAN__,
38 native = __BYTE_ORDER__,
40#error OrtDataType::detail::endian is not implemented in this environment.
45 endian::native == endian::little || endian::native == endian::big,
46 "Only little-endian or big-endian native byte orders are supported.");
53template <
class Derived>
111 return static_cast<int16_t
>(
val) < 0;
165 auto abs = AbsImpl();
175 auto abs = AbsImpl();
187 auto abs = AbsImpl();
203 GPUd() Derived Negate() const
noexcept {
return Derived::FromBits(NegateImpl()); }
220 if (IsNaN() || rhs.IsNaN()) {
224 return val == rhs.val;
227 GPUd()
bool operator!=(const Float16Impl& rhs) const
noexcept {
return !(*
this == rhs); }
236 const bool left_is_negative = IsNegative();
237 if (left_is_negative !=
rhs.IsNegative()) {
241 return left_is_negative && !AreZero(*
this, rhs);
243 return (
val !=
rhs.val) && ((
val <
rhs.val) ^ left_is_negative);
277template <
class Derived>
283 constexpr detail::float32_bits f32infty = {255 << 23};
284 constexpr detail::float32_bits f16max = {(127 + 16) << 23};
285 constexpr detail::float32_bits denorm_magic = {((127 - 15) + (23 - 10) + 1) << 23};
286 constexpr unsigned int sign_mask = 0x80000000u;
289 unsigned int sign =
f.u & sign_mask;
297 if (
f.u >= f16max.u) {
298 val = (
f.u > f32infty.u) ? 0x7e00 : 0x7c00;
300 if (
f.u < (113 << 23)) {
304 f.f += denorm_magic.f;
309 unsigned int mant_odd = (
f.u >> 13) & 1;
326template <
class Derived>
327GPUdi()
float Float16Impl<Derived>::ToFloatImpl() const noexcept
329 constexpr detail::float32_bits magic = {113 << 23};
330 constexpr unsigned int shifted_exp = 0x7c00 << 13;
331 detail::float32_bits o{};
333 o.u = (
val & 0x7fff) << 13;
334 unsigned int exp = shifted_exp & o.u;
335 o.u += (127 - 15) << 23;
338 if (
exp == shifted_exp) {
339 o.u += (128 - 16) << 23;
340 }
else if (
exp == 0) {
347#if (defined _MSC_VER) && (defined _M_ARM || defined _M_ARM64 || defined _M_ARM64EC)
353 o.u |= (
val & 0x8000U) << 16U;
359template <
class Derived>
373 GPUd()
float ToFloatImpl() const noexcept;
395 static constexpr uint16_t kSignMask = 0x8000U;
396 static constexpr uint16_t kBiasedExponentMask = 0x7F80U;
397 static constexpr uint16_t kPositiveInfinityBits = 0x7F80U;
398 static constexpr uint16_t kNegativeInfinityBits = 0xFF80U;
399 static constexpr uint16_t kPositiveQNaNBits = 0x7FC1U;
400 static constexpr uint16_t kNegativeQNaNBits = 0xFFC1U;
401 static constexpr uint16_t kSignaling_NaNBits = 0x7F80U;
402 static constexpr uint16_t kEpsilonBits = 0x0080U;
403 static constexpr uint16_t kMinValueBits = 0xFF7FU;
404 static constexpr uint16_t kMaxValueBits = 0x7F7FU;
405 static constexpr uint16_t kRoundToNearest = 0x7FFFU;
406 static constexpr uint16_t kOneBits = 0x3F80U;
407 static constexpr uint16_t kMinusOneBits = 0xBF80U;
417 GPUd()
bool IsNegative() const noexcept
419 return static_cast<int16_t
>(
val) < 0;
428 return AbsImpl() > kPositiveInfinityBits;
435 GPUd()
bool IsFinite() const noexcept
437 return AbsImpl() < kPositiveInfinityBits;
444 GPUd()
bool IsPositiveInfinity() const noexcept
446 return val == kPositiveInfinityBits;
453 GPUd()
bool IsNegativeInfinity() const noexcept
455 return val == kNegativeInfinityBits;
462 GPUd()
bool IsInfinity() const noexcept
464 return AbsImpl() == kPositiveInfinityBits;
471 GPUd()
bool IsNaNOrZero() const noexcept
473 auto abs = AbsImpl();
474 return (abs == 0 || abs > kPositiveInfinityBits);
481 GPUd()
bool IsNormal() const noexcept
483 auto abs = AbsImpl();
484 return (abs < kPositiveInfinityBits)
486 && ((abs & kBiasedExponentMask) != 0);
493 GPUd()
bool IsSubnormal() const noexcept
495 auto abs = AbsImpl();
496 return (abs < kPositiveInfinityBits)
498 && ((abs & kBiasedExponentMask) == 0);
505 GPUd() Derived Abs() const noexcept {
return Derived::FromBits(AbsImpl()); }
511 GPUd() Derived Negate() const noexcept {
return Derived::FromBits(NegateImpl()); }
521 GPUd() static
bool AreZero(const BFloat16Impl& lhs, const BFloat16Impl& rhs) noexcept
526 return static_cast<uint16_t>((
lhs.val |
rhs.val) & ~kSignMask) == 0;
530template <
class Derived>
531GPUdi()
uint16_t BFloat16Impl<Derived>::ToUint16Impl(
float v) noexcept
534 if (o2::gpu::CAMath::IsNaN(
v)) {
535 result = kPositiveQNaNBits;
537 auto get_msb_half = [](
float fl) {
540 o2::gpu::CAMath::memcpy(&
res,
reinterpret_cast<char*
>(&fl) +
sizeof(
uint16_t),
sizeof(
uint16_t));
542#ifdef __cpp_if_constexpr
543 if constexpr (detail::endian::native == detail::endian::little)
545 if (detail::endian::native == detail::endian::little)
562 U32 += (upper_bits & 1) + kRoundToNearest;
563 result = get_msb_half(F32);
568template <
class Derived>
569GPUdi()
float BFloat16Impl<Derived>::ToFloatImpl() const noexcept
573 return o2::gpu::CAMath::QuietNaN();
577 char*
const first =
reinterpret_cast<char*
>(&
result);
581 o2::gpu::CAMath::memcpy(second, &
val,
sizeof(
uint16_t));
583#ifdef __cpp_if_constexpr
584 if constexpr (detail::endian::native == detail::endian::little)
586 if (detail::endian::native == detail::endian::little)
593 std::memset(second, 0,
sizeof(
uint16_t));
617struct Float16_t : OrtDataType::Float16Impl<Float16_t> {
624 constexpr explicit Float16_t(
uint16_t v)
noexcept {
val =
v; }
627 using Base = OrtDataType::Float16Impl<Float16_t>;
639 GPUd() constexpr static Float16_t FromBits(
uint16_t v) noexcept {
return Float16_t(
v); }
645 GPUd() explicit Float16_t(
float v) noexcept {
val = Base::ToUint16Impl(
v); }
651 GPUd()
float ToFloat() const noexcept {
return Base::ToFloatImpl(); }
657 using Base::IsNegative;
669 using Base::IsFinite;
675 using Base::IsPositiveInfinity;
681 using Base::IsNegativeInfinity;
687 using Base::IsInfinity;
693 using Base::IsNaNOrZero;
699 using Base::IsNormal;
705 using Base::IsSubnormal;
732 GPUdi() explicit operator
float() const noexcept {
return ToFloat(); }
734 using Base::operator==;
735 using Base::operator!=;
736 using Base::operator<;
739static_assert(
sizeof(Float16_t) ==
sizeof(
uint16_t),
"Sizes must match");
771 using Base = OrtDataType::BFloat16Impl<BFloat16_t>;
792 GPUd()
float ToFloat() const noexcept {
return Base::ToFloatImpl(); }
798 using Base::IsNegative;
810 using Base::IsFinite;
816 using Base::IsPositiveInfinity;
822 using Base::IsNegativeInfinity;
828 using Base::IsInfinity;
834 using Base::IsNaNOrZero;
840 using Base::IsNormal;
846 using Base::IsSubnormal;
873 GPUdi() explicit operator
float() const noexcept {
return ToFloat(); }
uint64_t exp(uint64_t base, uint8_t exp) noexcept
unsigned short int uint16_t
configStandalone Reconstruction rec_tpc multiplier for the combined cluster track error during track following area in cm for the search of for z only used if decrease removal by when above this local occupancy rowx Shift of TPC revert cluster flag edge bit distance to edge exceeds this ZOffset for secondary multiple of radius max P of electron K BB bands crossing max P of electron p BB bands crossing max P of electron d BB bands crossing max P of electron t BB bands crossing min accepted dEdxMaxTPC of the track Additive extra cluster error for Y2 if edge flag set Additive extra cluster error for Y2 if single set Additive extra cluster error for Y2 if or single set Additive extra cluster error for Z2 if or single set Extra errors to add to track when crossing depending on addErrorsCECrossing Inner portion of y range in sector that is not used in searching for extrapolated track candidates factor2YS for track merging factor2K for track merging Margin in cm of Y position when rejecting edge clusters based on uncorrected track Y Max fraction of shared clusters for tracklet Except pad from cluster finding if total number of charges in a fragment is above this Except pad from cluster finding if number of consecutive charges in a fragment is above this Threshold where a timebin is considered disabling the noisy pad check for that pad Treat signal above this minimum as saturated Smoothing factor for the exponential Highly Ionising Particle tail filter Number of timebins to use for the averaging Add additional custom track errors when crossing relative as fraction of Do N fit passes in final fit of< 0:reject at max -n hits") AddOptionRTC(rejectIFCLowRadiusCluster, uint8_t, 1, "", 0, "Reject clusters that get the IFC mask error during refit") AddOptionRTC(dEdxTruncLow, uint8_t, 2, "", 0, "Low truncation threshold, fraction of 128") AddOptionRTC(dEdxTruncHigh, uint8_t, 77, "", 0, "High truncation threshold, fraction of 128") AddOptionRTC(extrapolationTracking, int8_t, 1, "", 0, "Enable Extrapolation Tracking(prolong tracks to adjacent sectors to find short segments)") AddOptionRTC(disableRefitAttachment, uint8_t, 0, "", 0, "Bitmask to disable certain attachment steps during refit(1:attachment, 2:propagation, 4:loop following, 8:mirroring)") AddOptionRTC(rejectionStrategy, uint8_t, o2::gpu::GPUSettings::RejectionStrategyA, "", 0, "Enable rejection of TPC clusters for compression(0=no, 1=strategy A, 2=strategy B)") AddOptionRTC(mergeLoopersAfterburner, uint8_t, 1, "", 0, "Run afterburner for additional looper merging") AddOptionRTC(compressionTypeMask, uint8_t, o2::gpu::GPUSettings::CompressionFull, "", 0, "TPC Compression mode bits(1=truncate charge/width LSB, 2=differences, 4=track-model)") AddOptionRTC(compressionSortOrder, uint8_t, o2::gpu::GPUSettings::SortTime, "", 0, "Sort order of TPC compression(0=time, 1=pad, 2=Z-time-pad, 3=Z-pad-time, 4=no sorting(use incoming order))") AddOptionRTC(sigBitsCharge, uint8_t, 4, "", 0, "Number of significant bits for TPC cluster charge in compression mode 1") AddOptionRTC(sigBitsWidth, uint8_t, 3, "", 0, "Number of significant bits for TPC cluster width in compression mode 1") AddOptionRTC(dropLoopers, uint8_t, 0, "", 0, "Drop looping tracks starting from second loop") AddOptionRTC(mergerInterpolateErrors, uint8_t, 1, "", 0, "Use interpolation instead of extrapolation for chi2 based cluster rejection") AddOptionRTC(mergerInterpolateRejectAlsoOnCurrentPosition, uint8_t, 1, "", 0, "When using mergerInterpolateErrors, reject based on chi2 twice computed with interpolated and current track position starting from NDF > mergerNonInterpolateRejectMinNDF Merge tracks accross the central electrode Enable PID response Add sub threshold clusters in TPC dEdx computation OR mask of TPC flags that will reject the cluster in alternative dEdx Reject edge clusters based on uncorrected track Y during track fit Increase decrease removal by when on this number of pads from the edge h configStandalone Reconstruction rec_trd Max chi2 for TRD tracklets to be matched to a track Chi2 cut for strict matching mode Number of sigmas for ITS TPC track time error estimate Addition to search road around track prolongation along Y in cm Optimal tracklet rphi resolution in maximum chi2 per attached tracklet for TRD tracks take into account the full likelihood of the slope including exponential tails Tracks with less attached tracklets are discarded after the tracking Post trigger Pile up integration time in BCs fits all iterations but the last one in projections Use material lookup table for TPC refit Apply workarounds to avoid cyclic merge should not be needed tpc dyn configStandalone Processing proc_rtc bool
configStandalone Reconstruction rec_tpc float
GPUdi() const expr uint16_t Float16Impl< Derived > GPUdi() uint16_t BFloat16Impl< Derived >
IEEE 754 half-precision floating point data type.
D const SVectorGPU< T, D > & rhs
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
bfloat16 (Brain Floating Point) data type
GPUdDefault() BFloat16_t()=default
OrtDataType::BFloat16Impl< BFloat16_t > Base
GPUdi() explicit operator float() const noexcept
User defined conversion operator. Converts BFloat16_t to float.
GPUd() float ToFloat() const noexcept
Converts bfloat16 to float.
bool operator!=(const BFloat16_t &rhs) const noexcept
GPUd() explicit BFloat16_t(float v) noexcept
__ctor from float. Float is converted into bfloat16 16-bit representation.
bool operator==(const BFloat16_t &rhs) const noexcept
bool operator<(const BFloat16_t &rhs) const noexcept
GPUd() static const expr BFloat16_t FromBits(uint16_t v) noexcept
Explicit conversion to uint16_t representation of bfloat16.
Shared implementation between public and internal classes. CRTP pattern.
GPUd() bool IsNaNOrZero() const noexcept
Tests if the value is NaN or zero. Useful for comparisons.
const Float16Impl &rhs noexcept
static constexpr uint16_t kSignMask
GPUd() bool IsPositiveInfinity() const noexcept
Tests if the value represents positive infinity.
static constexpr uint16_t kNegativeInfinityBits
GPUd() Derived Abs() const noexcept
Creates an instance that represents absolute value.
static constexpr uint16_t kNegativeQNaNBits
static constexpr uint16_t kPositiveInfinityBits
static constexpr uint16_t kMinusOneBits
GPUd() uint16_t NegateImpl() const noexcept
Creates a new instance with the sign flipped.
GPUd() bool IsNegativeInfinity() const noexcept
Tests if the value represents negative infinity.
GPUd() bool IsNaN() const noexcept
Tests if the value is NaN.
static constexpr uint16_t kBiasedExponentMask
static constexpr uint16_t kOneBits
static constexpr uint16_t kEpsilonBits
static constexpr uint16_t kMaxValueBits
static constexpr uint16_t kMinValueBits
GPUd() bool IsSubnormal() const noexcept
Tests if the value is subnormal (denormal).
GPUd() bool IsInfinity() const noexcept
Tests if the value is either positive or negative infinity.
GPUd() bool IsNormal() const noexcept
Tests if the value is normal (not zero, subnormal, infinite, or NaN).
GPUd() static bool AreZero(const Float16Impl &lhs
IEEE defines that positive and negative zero are equal, this gives us a quick equality check for two ...
GPUdDefault() Float16Impl()=default
GPUd() bool IsFinite() const noexcept
Tests if the value is finite.
GPUd() const expr static uint16_t ToUint16Impl(float v) noexcept
Converts from float to uint16_t float16 representation.
static constexpr uint16_t kPositiveQNaNBits
GPUd() Derived Negate() const noexcept
Creates a new instance with the sign flipped.