From 7cfee028427103e8cf555800acd2ff5e6cb8f6cb Mon Sep 17 00:00:00 2001 From: Bram Veenboer Date: Mon, 6 Jan 2025 13:01:38 +0100 Subject: [PATCH 1/6] Remove unused context agument from nvml::Device --- include/cudawrappers/nvml.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/cudawrappers/nvml.hpp b/include/cudawrappers/nvml.hpp index 7891a80..d4e3da0 100644 --- a/include/cudawrappers/nvml.hpp +++ b/include/cudawrappers/nvml.hpp @@ -35,11 +35,11 @@ class Context { class Device { public: - Device(Context& context, int index) { + Device(int index) { checkNvmlCall(nvmlDeviceGetHandleByIndex(index, &device_)); } - Device(Context& context, cu::Device& device) { + Device(cu::Device& device) { const std::string uuid = device.getUuid(); nvmlDeviceGetHandleByUUID(uuid.c_str(), &device_); } From 4f2d48cab765746c89d5012bd2b7811bd0679af3 Mon Sep 17 00:00:00 2001 From: Bram Veenboer Date: Mon, 6 Jan 2025 13:02:40 +0100 Subject: [PATCH 2/6] Add missing checkNvmlCall --- include/cudawrappers/nvml.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/cudawrappers/nvml.hpp b/include/cudawrappers/nvml.hpp index d4e3da0..57a139f 100644 --- a/include/cudawrappers/nvml.hpp +++ b/include/cudawrappers/nvml.hpp @@ -41,7 +41,7 @@ class Device { Device(cu::Device& device) { const std::string uuid = device.getUuid(); - nvmlDeviceGetHandleByUUID(uuid.c_str(), &device_); + checkNvmlCall(nvmlDeviceGetHandleByUUID(uuid.c_str(), &device_)); } void getFieldValues(int valuesCount, nvmlFieldValue_t* values) { From c051207a4777f7eab2ffccb68257536cf8bb77c7 Mon Sep 17 00:00:00 2001 From: Bram Veenboer Date: Mon, 6 Jan 2025 13:03:14 +0100 Subject: [PATCH 3/6] Make nvml::Device functions const --- include/cudawrappers/nvml.hpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/cudawrappers/nvml.hpp b/include/cudawrappers/nvml.hpp index 57a139f..62d353e 100644 --- a/include/cudawrappers/nvml.hpp +++ b/include/cudawrappers/nvml.hpp @@ -44,17 +44,18 @@ class Device { checkNvmlCall(nvmlDeviceGetHandleByUUID(uuid.c_str(), &device_)); } - void getFieldValues(int valuesCount, nvmlFieldValue_t* values) { + void getFieldValues(int valuesCount, nvmlFieldValue_t* values) const { checkNvmlCall(nvmlDeviceGetFieldValues(device_, valuesCount, values)); } - unsigned int getClock(nvmlClockType_t clockType, nvmlClockId_t clockId) { + unsigned int getClock(nvmlClockType_t clockType, + nvmlClockId_t clockId) const { unsigned int clockMhz; checkNvmlCall(nvmlDeviceGetClock(device_, clockType, clockId, &clockMhz)); return clockMhz; } - unsigned int getPower() { + unsigned int getPower() const { unsigned int power; checkNvmlCall(nvmlDeviceGetPowerUsage(device_, &power)); return power; From d302ee3da60f5fbfacbe1b4a639cebd360b62141 Mon Sep 17 00:00:00 2001 From: Bram Veenboer Date: Mon, 6 Jan 2025 13:04:32 +0100 Subject: [PATCH 4/6] Update test_nvml --- tests/test_nvml.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_nvml.cpp b/tests/test_nvml.cpp index bc450e7..da8d638 100644 --- a/tests/test_nvml.cpp +++ b/tests/test_nvml.cpp @@ -9,12 +9,12 @@ TEST_CASE("Test nvml::Context", "[context]") { nvml::Context context; } TEST_CASE("Test nvml::Device with device number", "[device]") { nvml::Context context; - nvml::Device device(context, 0); + nvml::Device device(0); } TEST_CASE("Test nvml::Device::getClock", "[device]") { nvml::Context context; - nvml::Device device(context, 0); + nvml::Device device(0); const unsigned int clockMHz = device.getClock(NVML_CLOCK_GRAPHICS, NVML_CLOCK_ID_CURRENT); REQUIRE(clockMHz > 0); @@ -22,7 +22,7 @@ TEST_CASE("Test nvml::Device::getClock", "[device]") { TEST_CASE("Test nvml::Device::getPower", "[device]") { nvml::Context context; - nvml::Device device(context, 0); + nvml::Device device(0); const unsigned int power = device.getPower(); REQUIRE(power > 0); } @@ -31,5 +31,5 @@ TEST_CASE("Test nvml::Device with device", "[device]") { cu::init(); cu::Device cu_device(0); nvml::Context nvml_context; - nvml::Device nvml_device(nvml_context, cu_device); + nvml::Device nvml_device(cu_device); } From b48e80fd332f00b1df17d67d675595c181a149fd Mon Sep 17 00:00:00 2001 From: Bram Veenboer Date: Mon, 6 Jan 2025 13:06:09 +0100 Subject: [PATCH 5/6] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d379acf..d6079a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ project adheres to [Semantic Versioning](http://semver.org/). - `target_embed_source` is now more robust: it properly tracks dependencies and runs again whenever any of them changes - Expanded tests to cover the new 2D memory operations and FFT support +- Removed the `context` from `nvml::Device` constructors ## \[0.8.0\] - 2024-07-05 From 44ee7b9f83a455d3ecc9a7ea671150329c13e368 Mon Sep 17 00:00:00 2001 From: Bram Veenboer Date: Mon, 6 Jan 2025 16:33:56 +0100 Subject: [PATCH 6/6] Add pass_filenames option to workaround cppcheck error --- .pre-commit-config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c3580bc..55af010 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,6 +15,7 @@ repos: - '--suppress=unreadVariable:tests/*' - '--suppress=missingIncludeSystem' - '--suppress=unmatchedSuppression' + pass_filenames: false - repo: https://github.com/cheshirekow/cmake-format-precommit rev: v0.6.13 hooks: