Caffe2 - C++ API
A deep learning, cross platform ML framework
blob_stats.cc
1 #include "caffe2/core/blob_stats.h"
2 
3 namespace caffe2 {
4 
5 const BlobStatGetter* BlobStatRegistry::get(CaffeTypeId id) {
6  auto it = map_.find(id);
7  if (it == map_.end()) {
8  return nullptr;
9  }
10  return it->second.get();
11 }
12 
13 BlobStatRegistry& BlobStatRegistry::instance() {
14  static BlobStatRegistry registry;
15  return registry;
16 }
17 
18 void BlobStatRegistry::doRegister(
19  CaffeTypeId id,
20  std::unique_ptr<BlobStatGetter>&& v) {
21  CAFFE_ENFORCE_EQ(
22  map_.count(id), 0, "BlobStatRegistry: Type already registered.");
23  map_[id] = std::move(v);
24 }
25 
26 namespace BlobStat {
27 
28 size_t sizeBytes(const Blob& blob) {
29  auto* p = BlobStatRegistry::instance().get(blob.meta().id());
30  return p ? p->sizeBytes(blob) : 0;
31 }
32 
33 } // namespace BlobStats
34 }
Simple registry implementation in Caffe2 that uses static variables to register object creators durin...