Skip to content

Commit 7cb2dcd

Browse files
jushgpytorchmergebot
authored andcommitted
[c10d][nvshmem] modify is_nvshmem_available runtime check to work with static-linked library (pytorch#159558) (pytorch#159561)
Summary: Currently this function rely on the logic that we load `libnvshmem_device.a` statically and load `libnvshmem_host.so` at runtime. For loading `libnvshmem.a` (the combine 2 thing together) statically this will fail. Add a section to check if the symbol from host API exist at runtime to check if nvshmem is loaded statically Test Plan: CI + sample run Rollback Plan: Differential Revision: D79177525 Pull Request resolved: pytorch#159561 Approved by: https://github.com/kwen2501
1 parent e5a81aa commit 7cb2dcd

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

torch/csrc/distributed/c10d/symm_mem/nvshmem_extension.cu

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,20 @@ namespace c10d::nvshmem_extension {
2828

2929
constexpr int MiB = 1024 * 1024;
3030

31+
extern "C" void nvshmem_init() __attribute__((weak));
32+
3133
// Check if NVSHMEM is available
3234
bool is_nvshmem_available() {
3335
// Runtime check
3436
static std::mutex mutex;
3537
static int is_available = -2;
3638
std::lock_guard<std::mutex> lock(mutex);
39+
40+
// Checked if the symbol is statically linked
41+
if(is_available == -2 && nvshmem_init) {
42+
is_available = 1;
43+
}
44+
3745
if (is_available == -2) {
3846
void* handle{};
3947
// Open the shared library, RTLD_LAZY defers symbol resolution until needed

0 commit comments

Comments
 (0)