Caffe2 - C++ API
A deep learning, cross platform ML framework
bench_utils.cc
1 #include <cpuinfo.h>
2 #include <stdint.h>
3 #include <stdlib.h>
4 
5 #include "caffe2/core/logging.h"
6 #include "caffe2/utils/bench_utils.h"
7 
8 namespace caffe2 {
9 
10 uint32_t wipe_cache() {
11  static uint32_t* wipe_buffer = nullptr;
12  static size_t wipe_size = 0;
13 
14  if (wipe_buffer == nullptr) {
15  CAFFE_ENFORCE(cpuinfo_initialize(), "failed to initialize cpuinfo");
16  const cpuinfo_processor* processor = cpuinfo_get_processor(0);
17  if (processor->cache.l4 != nullptr) {
18  wipe_size = processor->cache.l4->size;
19  } else if (processor->cache.l3 != nullptr) {
20  wipe_size = processor->cache.l3->size;
21  } else if (processor->cache.l2 != nullptr) {
22  wipe_size = processor->cache.l2->size;
23  } else {
24  wipe_size = processor->cache.l1d->size;
25  }
26 #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
27  /*
28  * On ARM precise cache size is not available, and cpuinfo may
29  * underestimate. Use max for uArch (see src/arm/cache.c)
30  */
31  switch (processor->core->uarch) {
32  case cpuinfo_uarch_cortex_a5:
33  wipe_size = 512 * 1024; /* Max observed */
34  break;
35  case cpuinfo_uarch_cortex_a7:
36  wipe_size = 1024 * 1024; /* uArch max */
37  break;
38  case cpuinfo_uarch_cortex_a8:
39  wipe_size = 1024 * 1024; /* uArch max */
40  break;
41  case cpuinfo_uarch_cortex_a9:
42  wipe_size = 1024 * 1024; /* Max observed */
43  break;
44  case cpuinfo_uarch_cortex_a12:
45  case cpuinfo_uarch_cortex_a17:
46  wipe_size = 8 * 1024 * 1024; /* uArch max */
47  break;
48  case cpuinfo_uarch_cortex_a15:
49  wipe_size = 4 * 1024 * 1024; /* uArch max */
50  break;
51  case cpuinfo_uarch_cortex_a35:
52  wipe_size = 1024 * 1024; /* uArch max */
53  break;
54  case cpuinfo_uarch_cortex_a53:
55  wipe_size = 2 * 1024 * 1024; /* uArch max */
56  break;
57  case cpuinfo_uarch_cortex_a57:
58  wipe_size = 2 * 1024 * 1024; /* uArch max */
59  break;
60  case cpuinfo_uarch_cortex_a72:
61  wipe_size = 4 * 1024 * 1024; /* uArch max */
62  break;
63  case cpuinfo_uarch_cortex_a73:
64  wipe_size = 8 * 1024 * 1024; /* uArch max */
65  break;
66  case cpuinfo_uarch_cortex_a55:
67  case cpuinfo_uarch_cortex_a75:
68  case cpuinfo_uarch_meerkat_m3:
69  wipe_size = 4 * 1024 * 1024; /* DynamIQ max */
70  break;
71  default:
72  wipe_size = 60 * 1024 * 1024;
73  break;
74  }
75 #endif
76  LOG(INFO) << "Allocating cache wipe buffer of size " << wipe_size;
77  wipe_buffer = static_cast<uint32_t*>(malloc(wipe_size));
78  CAFFE_ENFORCE(wipe_buffer != nullptr);
79  }
80  uint32_t hash = 0;
81  for (uint32_t i = 0; i * sizeof(uint32_t) < wipe_size; i += 8) {
82  hash ^= wipe_buffer[i];
83  wipe_buffer[i] = hash;
84  }
85  /* Make sure compiler doesn't optimize the loop away */
86  return hash;
87 }
88 
89 } /* namespace caffe2 */
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13