Caffe2 - C++ API
A deep learning, cross platform ML framework
blob_stats.cc
1 
17 #include "caffe2/core/blob_stats.h"
18 
19 namespace caffe2 {
20 
21 const BlobStatGetter* BlobStatRegistry::get(CaffeTypeId id) {
22  auto it = map_.find(id);
23  if (it == map_.end()) {
24  return nullptr;
25  }
26  return it->second.get();
27 }
28 
29 BlobStatRegistry& BlobStatRegistry::instance() {
30  static BlobStatRegistry registry;
31  return registry;
32 }
33 
34 void BlobStatRegistry::doRegister(
35  CaffeTypeId id,
36  std::unique_ptr<BlobStatGetter>&& v) {
37  // don't use CAFFE_ENFORCE_EQ to avoid static initialization order fiasco.
38  if (map_.count(id) > 0) {
39  throw std::runtime_error("BlobStatRegistry: Type already registered.");
40  }
41  map_[id] = std::move(v);
42 }
43 
44 namespace BlobStat {
45 
46 size_t sizeBytes(const Blob& blob) {
47  auto* p = BlobStatRegistry::instance().get(blob.meta().id());
48  return p ? p->sizeBytes(blob) : 0;
49 }
50 
51 } // namespace BlobStats
52 }
Copyright (c) 2016-present, Facebook, Inc.