1 #include "caffe2/core/blob_stats.h" 5 const BlobStatGetter* BlobStatRegistry::get(CaffeTypeId
id) {
6 auto it = map_.find(
id);
7 if (it == map_.end()) {
10 return it->second.get();
13 BlobStatRegistry& BlobStatRegistry::instance() {
14 static BlobStatRegistry registry;
18 void BlobStatRegistry::doRegister(
20 std::unique_ptr<BlobStatGetter>&& v) {
22 map_.count(
id), 0,
"BlobStatRegistry: Type already registered.");
23 map_[id] = std::move(v);
28 size_t sizeBytes(
const Blob& blob) {
29 auto* p = BlobStatRegistry::instance().get(blob.meta().id());
30 return p ? p->sizeBytes(blob) : 0;
Simple registry implementation in Caffe2 that uses static variables to register object creators durin...