-
Notifications
You must be signed in to change notification settings - Fork 24
Dynamic Loading IB verbs #253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: candidate
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,6 +9,7 @@ MPI_PATH ?= /usr/local/openmpi | |||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Optional features (set to 0 to disable, 1 to enable) | ||||||||||||||||||||||
| # DISABLE_NIC_EXEC: Disable RDMA/NIC executor support (default: 0) | ||||||||||||||||||||||
| # DISABLE_IBV_DIRECT: When NIC support is on, use dlsym for libibverbs instead of direct linkage (default: 0) | ||||||||||||||||||||||
| # DISABLE_MPI_COMM: Disable MPI communicator support (default: 0) | ||||||||||||||||||||||
| # DISABLE_DMA_BUF: Disable DMA-BUF support for GPU Direct RDMA (default: 1) | ||||||||||||||||||||||
| # DISABLE_AMD_SMI: Disable AMD-SMI pod membership checking support (default: 0) | ||||||||||||||||||||||
|
|
@@ -85,7 +86,9 @@ ifeq ($(filter clean,$(MAKECMDGOALS)),) | |||||||||||||||||||||
| # 1) DISABLE_NIC_EXEC is not set to 1 | ||||||||||||||||||||||
| # 2) IBVerbs is found in the Dynamic Linker cache | ||||||||||||||||||||||
| # 3) infiniband/verbs.h is found in the default include path | ||||||||||||||||||||||
| # When enabled, -DIBV_DIRECT=1 is added unless DISABLE_IBV_DIRECT=1 (verbs via direct link + constexpr pfn_*) | ||||||||||||||||||||||
| DISABLE_NIC_EXEC ?= 0 | ||||||||||||||||||||||
| DISABLE_IBV_DIRECT ?= 0 | ||||||||||||||||||||||
| ifneq ($(DISABLE_NIC_EXEC),1) | ||||||||||||||||||||||
| $(info Attempting to build with NIC executor support) | ||||||||||||||||||||||
| ifeq ("$(shell ldconfig -p | grep -c ibverbs)", "0") | ||||||||||||||||||||||
|
|
@@ -96,6 +99,9 @@ ifeq ($(filter clean,$(MAKECMDGOALS)),) | |||||||||||||||||||||
| COMMON_FLAGS += -DNIC_EXEC_ENABLED | ||||||||||||||||||||||
| LDFLAGS += -libverbs | ||||||||||||||||||||||
| NIC_ENABLED = 1 | ||||||||||||||||||||||
| ifneq ($(DISABLE_IBV_DIRECT),1) | ||||||||||||||||||||||
| COMMON_FLAGS += -DIBV_DIRECT=1 | ||||||||||||||||||||||
|
Comment on lines
100
to
+103
|
||||||||||||||||||||||
| LDFLAGS += -libverbs | |
| NIC_ENABLED = 1 | |
| ifneq ($(DISABLE_IBV_DIRECT),1) | |
| COMMON_FLAGS += -DIBV_DIRECT=1 | |
| NIC_ENABLED = 1 | |
| ifneq ($(DISABLE_IBV_DIRECT),1) | |
| COMMON_FLAGS += -DIBV_DIRECT=1 | |
| LDFLAGS += -libverbs | |
| else | |
| LDFLAGS += -ldl |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -55,6 +55,12 @@ THE SOFTWARE. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #ifdef NIC_EXEC_ENABLED | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <infiniband/verbs.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #if IBV_DIRECT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #define IBV_FN(name, rettype, arglist) constexpr rettype(*pfn_##name)arglist = name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <dlfcn.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #define IBV_FN(name, rettype, arglist) rettype(*pfn_##name)arglist = nullptr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #ifdef MPI_COMM_ENABLED | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -736,11 +742,36 @@ namespace TransferBench | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return false; \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } while (0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| namespace { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| IBV_FN(ibv_alloc_pd, ibv_pd*, (ibv_context*)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| IBV_FN(ibv_close_device, int, (ibv_context*)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| IBV_FN(ibv_create_cq, ibv_cq*, (ibv_context*, int, void*, ibv_comp_channel*, int)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| IBV_FN(ibv_create_qp, ibv_qp*, (ibv_pd*, ibv_qp_init_attr*)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| IBV_FN(ibv_dealloc_pd, int, (ibv_pd*)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| IBV_FN(ibv_dereg_mr, int, (ibv_mr*)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| IBV_FN(ibv_destroy_cq, int, (ibv_cq*)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| IBV_FN(ibv_destroy_qp, int, (ibv_qp*)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| IBV_FN(ibv_free_device_list, void, (ibv_device**)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| IBV_FN(ibv_get_device_list, ibv_device**, (int*)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| IBV_FN(ibv_get_device_name, const char*, (ibv_device*)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| IBV_FN(ibv_modify_qp, int, (ibv_qp*, ibv_qp_attr*, int)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| IBV_FN(ibv_open_device, ibv_context*, (ibv_device*)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| IBV_FN(ibv_poll_cq, int, (ibv_cq*, int, ibv_wc*)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| IBV_FN(ibv_post_send, int, (ibv_qp*, ibv_send_wr*, ibv_send_wr**)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| IBV_FN(ibv_query_device, int, (ibv_context*, ibv_device_attr*)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| IBV_FN(ibv_query_gid, int, (ibv_context*, uint8_t, int, ibv_gid*)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| IBV_FN(ibv_query_port, int, (ibv_context*, uint8_t, ibv_port_attr*)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #ifdef HAVE_DMABUF_SUPPORT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| IBV_FN(ibv_reg_dmabuf_mr, ibv_mr*, (ibv_pd*, uint64_t, size_t, uint64_t, int, int)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| IBV_FN(ibv_reg_mr, ibv_mr*, (ibv_pd*, void*, size_t, int)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+745
to
+768
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Helper macros for calling RDMA functions and reporting errors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #ifdef VERBS_DEBUG | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #define IBV_CALL(__func__, ...) \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| do { \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int error = __func__(__VA_ARGS__); \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int error = pfn_##__func__(__VA_ARGS__); \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (error != 0) { \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return {ERR_FATAL, "Encountered IbVerbs error (%d) at line (%d) " \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "and function (%s)", (error), __LINE__, #__func__}; \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -749,7 +780,7 @@ namespace TransferBench | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #define IBV_PTR_CALL(__ptr__, __func__, ...) \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| do { \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| __ptr__ = __func__(__VA_ARGS__); \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| __ptr__ = pfn_##__func__(__VA_ARGS__); \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (__ptr__ == nullptr) { \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return {ERR_FATAL, "Encountered IbVerbs nullptr error at line (%d) " \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "and function (%s)", __LINE__, #__func__}; \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -758,7 +789,7 @@ namespace TransferBench | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #define IBV_CALL(__func__, ...) \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| do { \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int error = __func__(__VA_ARGS__); \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int error = pfn_##__func__(__VA_ARGS__); \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (error != 0) { \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return {ERR_FATAL, "Encountered IbVerbs error (%d=%s) in func (%s)" \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| , error, strerror(errno), #__func__}; \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -767,7 +798,7 @@ namespace TransferBench | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #define IBV_PTR_CALL(__ptr__, __func__, ...) \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| do { \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| __ptr__ = __func__(__VA_ARGS__); \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| __ptr__ = pfn_##__func__(__VA_ARGS__); \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (__ptr__ == nullptr) { \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return {ERR_FATAL, "Encountered IbVerbs nullptr error (%s) in func (%s) " \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| , strerror(errno), #__func__}; \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1006,6 +1037,7 @@ namespace { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bool IsSamePod(int targetRank, int sourceRank) const; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::string GetExecutorName(ExeDevice exeDevice) const; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int NicIsActive(int nicIndex, int targetRank) const; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bool IbvLoaded() const; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #if !defined(__NVCC__) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ErrResult GetHsaAgent(ExeDevice const& exeDevice, hsa_agent_t& agent) const; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1032,6 +1064,8 @@ namespace { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bool verbose = false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bool rankDoesOutput = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FILE* dumpCfgFile = nullptr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bool ibvLoaded = false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void* ibvLibHandle = nullptr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #if !defined(__NVCC__) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::vector<hsa_agent_t> cpuAgents; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -2341,6 +2375,11 @@ namespace { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case EXE_NIC: case EXE_NIC_NEAREST: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #ifdef NIC_EXEC_ENABLED | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!System::Get().IbvLoaded()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errors.push_back({ERR_FATAL, "Transfer %d: NIC executor is requested but IB verbs is not loaded.", i}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| hasFatalError = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // NIC Executors can only execute a copy operation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (t.srcs.size() != 1 || t.dsts.size() != 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errors.push_back({ERR_FATAL, "Transfer %d: NIC executor requires single SRC and single DST", i}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -2671,7 +2710,7 @@ namespace { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #ifdef NIC_EXEC_ENABLED | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Function to collect information about IBV devices | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| //======================================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| static bool IsConfiguredGid(union ibv_gid const& gid) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| static bool IsConfiguredGid(union ibv_gid const& gid) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const struct in6_addr *a = (struct in6_addr *) gid.raw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int trailer = (a->s6_addr32[1] | a->s6_addr32[2] | a->s6_addr32[3]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -2696,7 +2735,8 @@ static bool IsConfiguredGid(union ibv_gid const& gid) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int const& gidIndex, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int& version) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| char const* deviceName = ibv_get_device_name(context->device); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| char const* deviceName; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| IBV_PTR_CALL(deviceName, ibv_get_device_name, context->device); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| char gidRoceVerStr[16] = {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| char roceTypePath[PATH_MAX] = {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sprintf(roceTypePath, "/sys/class/infiniband/%s/ports/%d/gid_attrs/types/%d", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -2778,17 +2818,68 @@ static bool IsConfiguredGid(union ibv_gid const& gid) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return ERR_NONE; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Should only be called with IBV_DIRECT guard | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| static void* Ibvdl() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+2821
to
+2822
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| static void* ibvLibHandle = nullptr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (ibvLibHandle) return ibvLibHandle; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void *handle = dlopen("libibverbs.so.1", RTLD_NOW); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (handle != nullptr) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+2821
to
+2827
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| struct Symbol { void **ppfn; char const *name; }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Symbol symbols[] = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { (void**)&pfn_ibv_alloc_pd, "ibv_alloc_pd" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { (void**)&pfn_ibv_close_device, "ibv_close_device" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { (void**)&pfn_ibv_create_cq, "ibv_create_cq" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { (void**)&pfn_ibv_create_qp, "ibv_create_qp" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { (void**)&pfn_ibv_dealloc_pd, "ibv_dealloc_pd" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { (void**)&pfn_ibv_dereg_mr, "ibv_dereg_mr" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { (void**)&pfn_ibv_destroy_cq, "ibv_destroy_cq" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { (void**)&pfn_ibv_destroy_qp, "ibv_destroy_qp" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { (void**)&pfn_ibv_free_device_list, "ibv_free_device_list" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { (void**)&pfn_ibv_get_device_list, "ibv_get_device_list" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { (void**)&pfn_ibv_get_device_name, "ibv_get_device_name" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { (void**)&pfn_ibv_modify_qp, "ibv_modify_qp" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { (void**)&pfn_ibv_open_device, "ibv_open_device" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { (void**)&pfn_ibv_poll_cq, "ibv_poll_cq" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { (void**)&pfn_ibv_post_send, "ibv_post_send" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { (void**)&pfn_ibv_query_device, "ibv_query_device" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { (void**)&pfn_ibv_query_gid, "ibv_query_gid" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { (void**)&pfn_ibv_query_port, "ibv_query_port" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #ifdef HAVE_DMABUF_SUPPORT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { (void**)&pfn_ibv_reg_dmabuf_mr, "ibv_reg_dmabuf_mr" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { (void**)&pfn_ibv_reg_mr, "ibv_reg_mr" }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (size_t i = 0; i < sizeof(symbols) / sizeof(symbols[0]); i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| *symbols[i].ppfn = dlsym(handle, symbols[i].name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (*symbols[i].ppfn == nullptr) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Log("[WARN] Failed to load symbol %s", symbols[i].name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dlclose(handle); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+2853
to
+2860
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (size_t i = 0; i < sizeof(symbols) / sizeof(symbols[0]); i++) { | |
| *symbols[i].ppfn = dlsym(handle, symbols[i].name); | |
| if (*symbols[i].ppfn == nullptr) { | |
| // Log("[WARN] Failed to load symbol %s", symbols[i].name); | |
| dlclose(handle); | |
| break; | |
| } | |
| } | |
| auto resetSymbols = [&symbols]() { | |
| for (size_t i = 0; i < sizeof(symbols) / sizeof(symbols[0]); i++) { | |
| *symbols[i].ppfn = nullptr; | |
| } | |
| }; | |
| bool loadedAllSymbols = true; | |
| for (size_t i = 0; i < sizeof(symbols) / sizeof(symbols[0]); i++) { | |
| *symbols[i].ppfn = dlsym(handle, symbols[i].name); | |
| if (*symbols[i].ppfn == nullptr) { | |
| // Log("[WARN] Failed to load symbol %s", symbols[i].name); | |
| loadedAllSymbols = false; | |
| break; | |
| } | |
| } | |
| if (!loadedAllSymbols) { | |
| resetSymbols(); | |
| dlclose(handle); | |
| handle = nullptr; | |
| } |
Copilot
AI
Apr 8, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetIbvDeviceList() checks ibvLibHandle == nullptr, but ibvLibHandle here refers to no visible variable (the System member isn’t accessible from this free function, and the Ibvdl() local static isn’t in scope). This is a compile error. Use a reachable source of truth (e.g., System::Get().IbvLoaded(), store the handle in a shared internal static with external linkage in this anonymous namespace, or call Ibvdl() and cache its result) instead of referencing an out-of-scope identifier.
| if (ibvLibHandle == nullptr) { | |
| if (Ibvdl() == nullptr) { |
Copilot
AI
Apr 8, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Within GetIbvDeviceList(), most verbs calls were converted to pfn_* (e.g., pfn_ibv_get_device_list/pfn_ibv_open_device/etc.), but the function still calls ibv_free_device_list(deviceList) directly later in the same function. In the dlsym path this reintroduces a direct libibverbs symbol reference and breaks the “all calls through pfn_*” model. Switch that cleanup call to pfn_ibv_free_device_list as well.
Copilot
AI
Apr 8, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
System::~System() calls dlclose(ibvLibHandle) unconditionally. When IBV_DIRECT=1, <dlfcn.h> is not included, so dlclose will be undeclared and compilation can fail. Also, Ibvdl() keeps its own internal static handle, so closing only the System member can leave Ibvdl() returning a stale (already-closed) handle on future calls. Guard dlclose with #if !IBV_DIRECT and keep a single owner for the handle (either System or Ibvdl, but not both).
| if (ibvLibHandle) { | |
| dlclose(ibvLibHandle); | |
| ibvLibHandle = nullptr; | |
| } | |
| #ifdef NIC_EXEC_ENABLED | |
| #if !IBV_DIRECT | |
| // Ibvdl() owns the dynamically loaded libibverbs handle. Avoid closing a | |
| // cached copy here so future Ibvdl() calls cannot observe a stale handle. | |
| ibvLibHandle = nullptr; | |
| #endif | |
| #endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ENABLE_IBV_DIRECT=OFF claims to resolve symbols via dlsym at runtime, but the target still links against ${IBVERBS_LIBRARY} unconditionally when IBVERBS_FOUND. This keeps libibverbs as a hard dependency and defeats optional loading. If runtime optionality is intended, avoid linking ${IBVERBS_LIBRARY} when ENABLE_IBV_DIRECT is OFF and ensure all ibv_* usage is through the loaded function pointers.