Which NVML API call do I use to set the SM clock of an NVIDIA GPU?

I’m trying to use libnvml “myself”, rather than nvidia-smi, to set the SM clock of my GPU.

I have no problem getting the current clock frequency with nvmlDeviceGetClockInfo, but - I can’t figure out how to do the opposite: Set the frequency. There’s nvmlDeviceSetGpuLockedClocks(), but that’s not it (i.e. when I call it, and query again, I get the same frequency as before I made the call). And the other device commands don’t seem like they’re what I need.

So, which API call is it? Or - could it be that this isn’t supported?

(PS - Posted this on StackOverflow but didn’t get an answer.)

Anybody?

nvmlDeviceSetGpcClkVfOffset allows you to set clocks offsets compared to default p-state limits, while nvmlDeviceSetGpuLockedClocks allows you to lock clocks within already permitted frequencies to avoid fluctuations outside of preferred range.

@v19930312 :

nvmlDeviceSetGpuLockedClocks allows you to lock clocks within already permitted frequencies to avoid fluctuations outside of preferred range.

Do you mean, lock the clocks to a value I’ve already set them to? Because, otherwise, this doesn’t work for me.

nvmlDeviceSetGpcClkVfOffset allows you to set clocks offsets compared to default p-state limits,

The manual says that’s deprecated, though. There is nvmlDeviceSetClockOffset()… but reading the doxygen for that one, I have no idea what I’m supposed to provide as input, what the p-state is, what “p-state limits” are etc.

So I’m still stuck… do you think you could provide a short code snippet to setting the clock rate to some single value?

It won’t allow you to do overclocking or underclocking (i.e. if GPU would not normally go to the specified frequency this call won’t make it), but it will try to keep clocks within/as close as possible to specified limit otherwise.

Honestly, just go with nvmlDeviceSetGpcClkVfOffset for now, it says “will be deprecated in a future release” anyways. I’ve tried out new functions and they don’t seem to be particularly production ready: nvmlDeviceGetMinMaxClockOfPState/nvmlDeviceSetClockOffsets issues.

If you want to lock clocks to a specified frequency that your device already goes to, just nvmlDeviceSetGpuLockedClocks should do. If it’s above the normal limit (i.e. you want to overclock), call nvmlDeviceSetGpcClkVfOffset with target frequency - normal max frequency as offset, then nvmlDeviceSetGpuLockedClocks with the target frequency as both values only if you want GPU to stay at that frequency at all times (not needed to just reach it under appropriately high load).

P.S.: here’s a short summary by Nvidia itself on pstates: NVAPI Reference Documentation; in NVML you’d want to look at nvmlDeviceGetSupportedPerformanceStates and from there nvmlDeviceGetMinMaxClockOfPState, but the caveat from linked post applies.

I tried plain vanilla clock rates within the sets supported by the device, as reported by nvidia-smi… and the call succeeded (i.e. no error was reported) :-(

I’ll give it another shot, maybe on more than a single machine, and will report back on this thread. Maybe I got something wrong last time. Thanks for taking the time to reply.

Locking GPU clocks to specified frequency definitely works for me (NVML_CLOCK_LIMIT_ID_* values are a little broken, though). Try using NVML_CLOCK_GRAPHICS instead of NVML_CLOCK_SM if you’re using that and see if it makes any difference.

1 Like