Caffe2 - C++ API
A deep learning, cross platform ML framework
blob_stats.h
1 #pragma once
2 
3 #include "caffe2/core/blob.h"
4 #include "caffe2/core/registry.h"
5 #include "caffe2/core/typeid.h"
6 
7 #include <unordered_map>
8 
9 namespace caffe2 {
10 
12  virtual size_t sizeBytes(const Blob& blob) const = 0;
13  virtual ~BlobStatGetter() {}
14 };
15 
17  private:
18  std::unordered_map<CaffeTypeId, std::unique_ptr<BlobStatGetter>> map_;
19  void doRegister(CaffeTypeId id, std::unique_ptr<BlobStatGetter>&& v);
20 
21  public:
22  template <typename T, typename Getter>
23  struct Registrar {
24  Registrar() {
25  BlobStatRegistry::instance().doRegister(
26  TypeMeta::Id<T>(), std::unique_ptr<Getter>(new Getter));
27  }
28  };
29 
30  const BlobStatGetter* get(CaffeTypeId id);
31  static BlobStatRegistry& instance();
32 };
33 
34 #define REGISTER_BLOB_STAT_GETTER(Type, BlobStatGetterClass) \
35  static BlobStatRegistry::Registrar<Type, BlobStatGetterClass> \
36  CAFFE_ANONYMOUS_VARIABLE(BlobStatRegistry)
37 
38 namespace BlobStat {
39 
44 size_t sizeBytes(const Blob& blob);
45 }
46 }
Simple registry implementation in Caffe2 that uses static variables to register object creators durin...
Blob is a general container that hosts a typed pointer.
Definition: blob.h:25