Caffe2 - C++ API
A deep learning, cross platform ML framework
blob_stats.h
1 #pragma once
2 
3 #include "c10/util/Registry.h"
4 #include "caffe2/core/blob.h"
5 #include <c10/util/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<TypeIdentifier, std::unique_ptr<BlobStatGetter>> map_;
19  void doRegister(TypeIdentifier 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(TypeIdentifier id);
31  static BlobStatRegistry& instance();
32 };
33 
34 #define REGISTER_BLOB_STAT_GETTER(Type, BlobStatGetterClass) \
35  static BlobStatRegistry::Registrar<Type, BlobStatGetterClass> \
36  C10_ANONYMOUS_VARIABLE(BlobStatRegistry)
37 
38 namespace BlobStat {
39 
44 CAFFE2_API size_t sizeBytes(const Blob& blob);
45 }
46 }
Blob is a general container that hosts a typed pointer.
Definition: blob.h:24
A type id is a unique id for a given C++ type.
Definition: typeid.h:60
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13