1 #include "c10/util/numa.h" 3 C10_DEFINE_bool(caffe2_cpu_numa_enabled,
false,
"Use NUMA whenever possible.");
5 #if defined(__linux__) && !defined(C10_DISABLE_NUMA) && !defined(C10_MOBILE) 9 #define C10_ENABLE_NUMA 17 #ifdef C10_ENABLE_NUMA 19 return FLAGS_caffe2_cpu_numa_enabled && numa_available() >= 0;
23 if (numa_node_id < 0) {
31 numa_node_id <= numa_max_node(),
36 auto bm = numa_allocate_nodemask();
37 numa_bitmask_setbit(bm, numa_node_id);
39 numa_bitmask_free(bm);
54 const_cast<void*>(ptr),
55 MPOL_F_NODE | MPOL_F_ADDR) == 0,
56 "Unable to get memory policy, errno:",
66 return numa_num_configured_nodes();
69 void NUMAMove(
void* ptr,
size_t size,
int numa_node_id) {
70 if (numa_node_id < 0) {
78 uintptr_t page_start_ptr =
79 ((
reinterpret_cast<uintptr_t
>(ptr)) & ~(getpagesize() - 1));
80 ptrdiff_t offset =
reinterpret_cast<uintptr_t
>(ptr) - page_start_ptr;
84 static_cast<unsigned>(numa_node_id) <
sizeof(
unsigned long) * 8);
85 unsigned long mask = 1UL << numa_node_id;
88 reinterpret_cast<void*>(page_start_ptr),
93 MPOL_MF_MOVE | MPOL_MF_STRICT) == 0,
94 "Could not move memory to a NUMA node");
102 auto n = numa_node_of_cpu(sched_getcpu());
106 #else // C10_ENABLE_NUMA 123 void NUMAMove(
void* ptr,
size_t size,
int numa_node_id) {
130 #endif // C10_NUMA_ENABLED void NUMAMove(void *ptr, size_t size, int numa_node_id)
Move the memory pointed to by ptr of a given size to another NUMA node.
int GetCurrentNUMANode()
Get the current NUMA node id.
int GetNUMANode(const void *ptr)
Get the NUMA id for a given pointer ptr
bool IsNUMAEnabled()
Check whether NUMA is enabled.
To register your own kernel for an operator, do in one (!) cpp file: C10_REGISTER_KERNEL(OperatorHand...
void NUMABind(int numa_node_id)
Bind to a given NUMA node.
int GetNumNUMANodes()
Get number of NUMA nodes.