|
| 1 | +// Copyright 2019-2026 CERN and copyright holders of ALICE O2. |
| 2 | +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. |
| 3 | +// All rights not expressly granted are reserved. |
| 4 | +// |
| 5 | +// This software is distributed under the terms of the GNU General Public |
| 6 | +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". |
| 7 | +// |
| 8 | +// In applying this license CERN does not waive the privileges and immunities |
| 9 | +// granted to it by virtue of its status as an Intergovernmental Organization |
| 10 | +// or submit itself to any jurisdiction. |
| 11 | +/// |
| 12 | +/// \file CapacityEstimator.h |
| 13 | +/// \brief Cross-timeframe output-size prediction. |
| 14 | +/// |
| 15 | + |
| 16 | +#ifndef TRACKINGITSU_INCLUDE_CAPACITYESTIMATOR_H_ |
| 17 | +#define TRACKINGITSU_INCLUDE_CAPACITYESTIMATOR_H_ |
| 18 | + |
| 19 | +#include <cstddef> |
| 20 | +#include <cstdint> |
| 21 | +#include <memory> |
| 22 | + |
| 23 | +namespace o2::its |
| 24 | +{ |
| 25 | + |
| 26 | +enum SlabSite : uint8_t { |
| 27 | + Tracklets = 0, |
| 28 | + Cells, |
| 29 | + Neighbours, |
| 30 | + Roads, |
| 31 | + NSlabSite, |
| 32 | +}; |
| 33 | +constexpr const char* const SlabSiteNames[SlabSite::NSlabSite]{"Tracklets", "Cells", "Neighbours", "Roads"}; |
| 34 | + |
| 35 | +class CapacityEstimator |
| 36 | +{ |
| 37 | + public: |
| 38 | + struct Config { |
| 39 | + float alpha{0.2f}; |
| 40 | + float marginInit{1.30f}; |
| 41 | + float marginMin{1.10f}; |
| 42 | + float marginMax{4.00f}; |
| 43 | + float marginUp{1.50f}; |
| 44 | + float marginOverflowSlack{1.05f}; |
| 45 | + float marginDown{0.98f}; |
| 46 | + float lowWatermark{0.60f}; |
| 47 | + uint32_t decayAfter{2}; |
| 48 | + size_t floorSlots{1024}; |
| 49 | + }; |
| 50 | + |
| 51 | + using KeyType = uint64_t; |
| 52 | + |
| 53 | + struct Decoded { |
| 54 | + SlabSite site; |
| 55 | + int iteration; |
| 56 | + int variant; |
| 57 | + int slot; |
| 58 | + }; |
| 59 | + |
| 60 | + static constexpr KeyType makeKey(SlabSite site, int iteration, int variant, int slot) noexcept |
| 61 | + { |
| 62 | + return (static_cast<KeyType>(site) << 56) | |
| 63 | + (static_cast<KeyType>(iteration & 0xFF) << 48) | |
| 64 | + (static_cast<KeyType>(variant & 0xFFFF) << 32) | |
| 65 | + static_cast<KeyType>(static_cast<uint32_t>(slot)); |
| 66 | + } |
| 67 | + |
| 68 | + static constexpr Decoded decodeKey(KeyType key) noexcept |
| 69 | + { |
| 70 | + return { |
| 71 | + .site = static_cast<SlabSite>((key >> 56) & 0xFF), |
| 72 | + .iteration = static_cast<int>((key >> 48) & 0xFF), |
| 73 | + .variant = static_cast<int>((key >> 32) & 0xFFFF), |
| 74 | + .slot = static_cast<int>(static_cast<uint32_t>(key & 0xFFFFFFFF))}; |
| 75 | + } |
| 76 | + |
| 77 | + static constexpr int makeVariant(int high, int low) noexcept |
| 78 | + { |
| 79 | + return ((high & 0xFF) << 8) | (low & 0xFF); |
| 80 | + } |
| 81 | + |
| 82 | + static constexpr int getVariantHigh(int variant) noexcept |
| 83 | + { |
| 84 | + return (variant >> 8) & 0xFF; |
| 85 | + } |
| 86 | + |
| 87 | + static constexpr int getVariantLow(int variant) noexcept |
| 88 | + { |
| 89 | + return variant & 0xFF; |
| 90 | + } |
| 91 | + |
| 92 | + CapacityEstimator(); |
| 93 | + explicit CapacityEstimator(Config cfg); |
| 94 | + ~CapacityEstimator(); |
| 95 | + CapacityEstimator(const CapacityEstimator&) = delete; |
| 96 | + CapacityEstimator& operator=(const CapacityEstimator&) = delete; |
| 97 | + |
| 98 | + void reset(); |
| 99 | + size_t capacity(uint64_t key, double scale) const; |
| 100 | + void update(uint64_t key, double scale, size_t emitted, size_t capacityUsed, bool overflowed, bool memoryLimited); |
| 101 | + void print() const; |
| 102 | + |
| 103 | + private: |
| 104 | + struct Impl; |
| 105 | + std::unique_ptr<Impl> mImpl; |
| 106 | +}; |
| 107 | + |
| 108 | +} // namespace o2::its |
| 109 | + |
| 110 | +#endif /* TRACKINGITSU_INCLUDE_CAPACITYESTIMATOR_H_ */ |
0 commit comments