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(TypeIdentifier 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  TypeIdentifier id,
20  std::unique_ptr<BlobStatGetter>&& v) {
21  // don't use CAFFE_ENFORCE_EQ to avoid static initialization order fiasco.
22  if (map_.count(id) > 0) {
23  throw std::runtime_error("BlobStatRegistry: Type already registered.");
24  }
25  map_[id] = std::move(v);
26 }
27 
28 namespace BlobStat {
29 
30 size_t sizeBytes(const Blob& blob) {
31  auto* p = BlobStatRegistry::instance().get(blob.meta().id());
32  return p ? p->sizeBytes(blob) : 0;
33 }
34 
35 } // namespace BlobStats
36 }
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13