Skip to content

Commit

Permalink
Ensure nvbench initializes nvml context when built statically
Browse files Browse the repository at this point in the history
  • Loading branch information
robertmaynard committed Nov 14, 2023
1 parent b446a6f commit 328a18c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
39 changes: 39 additions & 0 deletions cpp/cmake/thirdparty/patches/nvbench_nvml_setup.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
diff --git a/nvbench/device_info.cu b/nvbench/device_info.cu
index 8edad22..a09def3 100644
--- a/nvbench/device_info.cu
+++ b/nvbench/device_info.cu
@@ -25,6 +25,10 @@

#include <cuda_runtime_api.h>

+#ifdef NVBENCH_HAS_NVML
+#include <nvbench/internal/nvml.cxx>
+#endif
+
#define UNUSED(x) (void)(x)

namespace nvbench
@@ -47,6 +51,10 @@ device_info::device_info(int id)
NVBENCH_CUDA_CALL(cudaGetDeviceProperties(&m_prop, m_id));

#ifdef NVBENCH_HAS_NVML
+ // NVML's lifetime should extend for the entirety of the process, so store in a
+ // global.
+ [[maybe_unused]] static auto nvml_lifetime = NVMLLifetimeManager();
+
// Retrieve the current device's pci_id as a null-terminated string.
// Docs say 13 chars should always be sufficient.
constexpr int pci_id_len = 13;
diff --git a/nvbench/internal/nvml.cxx b/nvbench/internal/nvml.cxx
index 4f750bc..ce7d874 100644
--- a/nvbench/internal/nvml.cxx
+++ b/nvbench/internal/nvml.cxx
@@ -64,8 +64,4 @@ private:
bool m_inited{false};
};

-// NVML's lifetime should extend for the entirety of the process, so store in a
-// global.
-auto nvml_lifetime = NVMLLifetimeManager{};
-
} // namespace
5 changes: 5 additions & 0 deletions cpp/cmake/thirdparty/patches/nvbench_override.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
"file" : "${current_json_dir}/nvbench_global_setup.diff",
"issue" : "Fix add support for global setup to initialize RMM in nvbench [https://github.com/NVIDIA/nvbench/pull/123]",
"fixed_in" : ""
},
{
"file" : "${current_json_dir}/nvbench_nvml_setup.diff",
"issue" : "Add support for nvml with static nvbench [https://github.com/NVIDIA/nvbench/pull/148]",
"fixed_in" : ""
}
]
}
Expand Down

0 comments on commit 328a18c

Please sign in to comment.