From e6552426bf433ff57ea3f03ce6a145e4569998e3 Mon Sep 17 00:00:00 2001 From: Bram Veenboer Date: Tue, 2 Jul 2024 14:32:58 +0200 Subject: [PATCH] Add nvml::Device::getClock (#285) * Add nvml::Device::getClock * Update CHANGELOG * Add test --- CHANGELOG.md | 1 + include/cudawrappers/nvml.hpp | 6 ++++++ tests/test_nvml.cpp | 10 +++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b06e1fa0..6c088d4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ project adheres to [Semantic Versioning](http://semver.org/). - Added `cu::Device::getUUID()` - Added initial cudawrappers::nvml target - Added `nvrtc::findIncludePath()` +- Added `nvml::Device::getClock` ### Changed diff --git a/include/cudawrappers/nvml.hpp b/include/cudawrappers/nvml.hpp index a3310388..4b0e5d27 100644 --- a/include/cudawrappers/nvml.hpp +++ b/include/cudawrappers/nvml.hpp @@ -46,6 +46,12 @@ class Device { checkNvmlCall(nvmlDeviceGetFieldValues(device_, valuesCount, values)); } + unsigned int getClock(nvmlClockType_t clockType, nvmlClockId_t clockId) { + unsigned int clockMhz; + checkNvmlCall(nvmlDeviceGetClock(device_, clockType, clockId, &clockMhz)); + return clockMhz; + } + private: nvmlDevice_t device_; }; diff --git a/tests/test_nvml.cpp b/tests/test_nvml.cpp index 7d17dacd..e5692436 100644 --- a/tests/test_nvml.cpp +++ b/tests/test_nvml.cpp @@ -13,9 +13,17 @@ TEST_CASE("Test nvml::Device with device number", "[device]") { nvml::Device device(context, 0); } +TEST_CASE("Test nvml::Device::getClock", "[device]") { + nvml::Context context; + nvml::Device device(context, 0); + const unsigned int clockMHz = + device.getClock(NVML_CLOCK_GRAPHICS, NVML_CLOCK_ID_CURRENT); + REQUIRE(clockMHz > 0); +} + 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); -} \ No newline at end of file +}