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)
 
 ~BatchStrategy ()=default
 

Private Attributes

std::map< size_t, BatchRulerules_
 

Detailed Description

Definition at line 52 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 48 of file Batching.cc.

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

48  {
49  const auto it = rules_.find(batchSize);
50  if (it == rules_.end()) {
51  throw cms::Exception("UnknownBatchSize") << "batchSize " << batchSize << " not known to batching strategy";
52  }
53  return it->second;
54  }
std::map< size_t, BatchRule > rules_
Definition: Batching.h:73

◆ hasRule()

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

Definition at line 64 of file Batching.h.

References HLT_FULL_cff::batchSize, and rules_.

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

◆ setDefaultRule()

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

Definition at line 64 of file Batching.cc.

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

64  {
65  std::vector<size_t> sizes;
66  size_t lastPadding = 0;
67 
68  // many implementations are possible here, but for simplicity assume the most simple one:
69  // if there is an exact match, use it, and otherwise repeat the smallest available size
70  // n times and potentially add padding
71  if (std::find(availableBatchSizes.begin(), availableBatchSizes.end(), batchSize) != availableBatchSizes.end()) {
72  sizes.push_back(batchSize);
73  } else {
74  size_t smallestBatchSize = *std::min_element(availableBatchSizes.begin(), availableBatchSizes.end());
75  size_t rest = batchSize % smallestBatchSize;
76  size_t n = (batchSize / smallestBatchSize) + (rest == 0 ? 0 : 1);
77  lastPadding = rest == 0 ? 0 : (smallestBatchSize - rest);
78  sizes.resize(n, smallestBatchSize);
79  }
80 
81  // create and register the rule
82  setRule(BatchRule(batchSize, sizes, lastPadding));
83  }
void setRule(const BatchRule &rule)
Definition: Batching.h:61
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19

◆ setRule()

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

Definition at line 61 of file Batching.h.

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

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

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

Member Data Documentation

◆ rules_

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

Definition at line 73 of file Batching.h.

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