1 #include "caffe2/core/context.h" 2 #include "caffe2/core/logging.h" 3 #include "caffe2/core/tensor.h" 4 #include "caffe2/core/typeid.h" 7 caffe2_report_cpu_memory_usage,
9 "If set, print out detailed memory usage");
12 caffe2_cpu_allocator_do_zero_fill,
14 "If set, do memory zerofilling when allocating on CPU");
18 void NoDelete(
void*) {}
20 static std::unique_ptr<CPUAllocator> g_cpu_allocator(
new DefaultCPUAllocator());
21 CPUAllocator* GetCPUAllocator() {
22 return g_cpu_allocator.get();
25 void SetCPUAllocator(CPUAllocator* alloc) {
26 g_cpu_allocator.reset(alloc);
29 MemoryAllocationReporter CPUContext::reporter_;
31 void MemoryAllocationReporter::New(
void* ptr,
size_t nbytes) {
32 std::lock_guard<std::mutex> guard(mutex_);
33 size_table_[ptr] = nbytes;
35 LOG(INFO) <<
"Caffe2 alloc " << nbytes <<
" bytes, total alloc " << allocated_
39 void MemoryAllocationReporter::Delete(
void* ptr) {
40 std::lock_guard<std::mutex> guard(mutex_);
41 auto it = size_table_.find(ptr);
42 CHECK(it != size_table_.end());
43 allocated_ -= it->second;
44 LOG(INFO) <<
"Caffe2 deleted " << it->second <<
" bytes, total alloc " 45 << allocated_ <<
" bytes.";
46 size_table_.erase(it);
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...