Skip to content
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

Update nvml interface #308

Merged
merged 6 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 7 additions & 6 deletions include/cudawrappers/nvml.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,27 @@ 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_);
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;
Expand Down
8 changes: 4 additions & 4 deletions tests/test_nvml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ 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);
}

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);
}
Expand All @@ -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);
}
Loading