CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
tfaot::BatchStrategy Class Reference

#include <Batching.h>

Public Member Functions

 BatchStrategy ()=default
 
const BatchRulegetRule (size_t batchSize) const
 
bool hasRule (size_t batchSize) const
 
void setDefaultRule (size_t batchSize, const std::vector< size_t > &availableBatchSizes)
 
void setRule (const BatchRule &rule)
 
void setRule (const std::string &ruleString)
 
 ~BatchStrategy ()=default
 

Private Attributes

std::map< size_t, BatchRulerules_
 

Detailed Description

Definition at line 59 of file Batching.h.

Constructor & Destructor Documentation

◆ BatchStrategy()

tfaot::BatchStrategy::BatchStrategy ( )
explicitdefault

◆ ~BatchStrategy()

tfaot::BatchStrategy::~BatchStrategy ( )
default

Member Function Documentation

◆ getRule()

const BatchRule & tfaot::BatchStrategy::getRule ( size_t  batchSize) const

Definition at line 85 of file Batching.cc.

References HLT_FULL_cff::batchSize, Exception, ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, and rules_.

85  {
86  const auto it = rules_.find(batchSize);
87  if (it == rules_.end()) {
88  throw cms::Exception("UnknownBatchSize") << "batchSize " << batchSize << " not known to batching strategy";
89  }
90  return it->second;
91  }
std::map< size_t, BatchRule > rules_
Definition: Batching.h:83

◆ hasRule()

bool tfaot::BatchStrategy::hasRule ( size_t  batchSize) const
inline

Definition at line 74 of file Batching.h.

References HLT_FULL_cff::batchSize, and rules_.

74 { return rules_.find(batchSize) != rules_.end(); }
std::map< size_t, BatchRule > rules_
Definition: Batching.h:83

◆ setDefaultRule()

void tfaot::BatchStrategy::setDefaultRule ( size_t  batchSize,
const std::vector< size_t > &  availableBatchSizes 
)

Definition at line 101 of file Batching.cc.

References HLT_FULL_cff::batchSize, spr::find(), dqmiodumpmetadata::n, mergeAndRegister::rest, and setRule().

101  {
102  std::vector<size_t> sizes;
103  size_t lastPadding = 0;
104 
105  // many implementations are possible here, but for simplicity assume the most simple one:
106  // if there is an exact match, use it, and otherwise repeat the smallest available size
107  // n times and potentially add padding
108  if (std::find(availableBatchSizes.begin(), availableBatchSizes.end(), batchSize) != availableBatchSizes.end()) {
109  sizes.push_back(batchSize);
110  } else {
111  size_t smallestBatchSize = *std::min_element(availableBatchSizes.begin(), availableBatchSizes.end());
112  size_t rest = batchSize % smallestBatchSize;
113  size_t n = (batchSize / smallestBatchSize) + (rest == 0 ? 0 : 1);
114  lastPadding = rest == 0 ? 0 : (smallestBatchSize - rest);
115  sizes.resize(n, smallestBatchSize);
116  }
117 
118  // create and register the rule
119  setRule(BatchRule(batchSize, sizes, lastPadding));
120  }
void setRule(const BatchRule &rule)
Definition: Batching.h:68
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19

◆ setRule() [1/2]

void tfaot::BatchStrategy::setRule ( const BatchRule rule)
inline

Definition at line 68 of file Batching.h.

References tfaot::BatchRule::getBatchSize(), and rules_.

Referenced by tfaot::Model< W >::setBatchRule(), and setDefaultRule().

68 { rules_.insert_or_assign(rule.getBatchSize(), rule); }
std::map< size_t, BatchRule > rules_
Definition: Batching.h:83

◆ setRule() [2/2]

void tfaot::BatchStrategy::setRule ( const std::string &  ruleString)
inline

Definition at line 71 of file Batching.h.

References setRule().

Referenced by setRule().

71 { this->setRule(BatchRule(ruleString)); }
void setRule(const BatchRule &rule)
Definition: Batching.h:68

Member Data Documentation

◆ rules_

std::map<size_t, BatchRule> tfaot::BatchStrategy::rules_
private

Definition at line 83 of file Batching.h.

Referenced by getRule(), hasRule(), and setRule().