Skip to content

Commit

Permalink
[ENG-324] Make libnuma a soft dependency using dlopen.
Browse files Browse the repository at this point in the history
If loading fails we behave the same as if numa_available() returns
false.
  • Loading branch information
arthurp committed Apr 29, 2021
1 parent 333d1fd commit f76f21f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
4 changes: 3 additions & 1 deletion libgalois/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ endif()

if(NUMA_FOUND)
target_compile_definitions(katana_galois PRIVATE KATANA_USE_NUMA)
target_link_libraries(katana_galois PRIVATE ${NUMA_LIBRARY})
file(REAL_PATH ${NUMA_LIBRARY} NUMA_LIBRARY_RESOLVED)
cmake_path(GET NUMA_LIBRARY_RESOLVED FILENAME KATANA_LIBNUMA_SO_NAME)
target_compile_definitions(katana_galois PRIVATE "KATANA_LIBNUMA_SO_NAME=\"${KATANA_LIBNUMA_SO_NAME}\"")
else()
message(WARNING "No NUMA Support. Likely poor performance for multi-socket systems.")
endif()
Expand Down
31 changes: 27 additions & 4 deletions libgalois/src/HWTopoLinux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* Documentation, or loss or inaccuracy of data of any kind.
*/

#include <dlfcn.h>

#include <algorithm>
#include <array>
#include <cassert>
Expand All @@ -34,7 +36,6 @@

#ifdef KATANA_USE_NUMA
#include <numa.h>
#include <numaif.h>
#endif

#ifdef KATANA_USE_SCHED_SETAFFINITY
Expand Down Expand Up @@ -66,6 +67,27 @@ operator<(const cpuinfo& lhs, const cpuinfo& rhs) {
return lhs.proc < rhs.proc;
}

#ifdef KATANA_USE_NUMA
int (*dynamic_numa_available)() = nullptr;
int (*dynamic_numa_num_configured_nodes)() = nullptr;
int (*dynamic_numa_node_of_cpu)(int cpu) = nullptr;

void
LoadLibNuma() {
// KATANA_LIBNUMA_SO_NAME is defined in libgalois/CMakeLists.txt
auto* lib = dlopen(KATANA_LIBNUMA_SO_NAME, RTLD_LAZY);
if (!lib) {
return;
}
#define LOAD_SYM(name) \
dynamic_##name = reinterpret_cast<decltype(&name)>(dlsym(lib, #name))
LOAD_SYM(numa_available);
LOAD_SYM(numa_num_configured_nodes);
LOAD_SYM(numa_node_of_cpu);
#undef LOAD_SYM
}
#endif

unsigned
getNumaNode(cpuinfo& c) {
static bool warnOnce = false;
Expand All @@ -74,8 +96,9 @@ getNumaNode(cpuinfo& c) {

if (!warnOnce) {
warnOnce = true;
numaAvail = numa_available() >= 0;
numaAvail = numaAvail && numa_num_configured_nodes() > 0;
LoadLibNuma();
numaAvail = dynamic_numa_available && dynamic_numa_available() >= 0;
numaAvail = numaAvail && dynamic_numa_num_configured_nodes() > 0;
if (!numaAvail)
katana::gWarn(
"Numa support configured but not present at runtime. "
Expand All @@ -84,7 +107,7 @@ getNumaNode(cpuinfo& c) {

if (!numaAvail)
return c.physid;
int i = numa_node_of_cpu(c.proc);
int i = dynamic_numa_node_of_cpu(c.proc);
if (i < 0)
KATANA_SYS_DIE("failed finding numa node for ", c.proc);
return i;
Expand Down

0 comments on commit f76f21f

Please sign in to comment.