| 216 | } |
| 217 | |
| 218 | int NUMAGetThreadNodeAffinity() { |
| 219 | int node_index = kNUMANoAffinity; |
| 220 | #ifdef TENSORFLOW_USE_NUMA |
| 221 | if (HaveHWLocTopology()) { |
| 222 | hwloc_cpuset_t thread_cpuset = hwloc_bitmap_alloc(); |
| 223 | hwloc_get_cpubind(hwloc_topology_handle, thread_cpuset, |
| 224 | HWLOC_CPUBIND_THREAD); |
| 225 | hwloc_obj_t obj = nullptr; |
| 226 | // Return the first NUMA node whose cpuset is a (non-proper) superset of |
| 227 | // that of the current thread. |
| 228 | while ((obj = hwloc_get_next_obj_by_type( |
| 229 | hwloc_topology_handle, HWLOC_OBJ_NUMANODE, obj)) != nullptr) { |
| 230 | if (hwloc_bitmap_isincluded(thread_cpuset, obj->cpuset)) { |
| 231 | node_index = obj->os_index; |
| 232 | break; |
| 233 | } |
| 234 | } |
| 235 | hwloc_bitmap_free(thread_cpuset); |
| 236 | } |
| 237 | #endif // TENSORFLOW_USE_NUMA |
| 238 | return node_index; |
| 239 | } |
| 240 | |
| 241 | void* AlignedMalloc(size_t size, int minimum_alignment) { |
| 242 | #if defined(__ANDROID__) |