Skip to content
Open
Changes from all 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
13 changes: 13 additions & 0 deletions kernel_tuner/observers/nvml.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@
self.use_locked_clocks = False

def __del__(self):
try:
self.restore_defaults()
except ImportError:
# ImportError happens when trying to reset clocks with
# nvidia-smi-fallback while Python is shutting down
# In this case clocks are reset using atexit, and we
# can safely ignore the exception
pass

def restore_defaults(self):
# try to restore to defaults
if self.pwr_limit_default is not None:
self.pwr_limit = self.pwr_limit_default
Expand Down Expand Up @@ -169,7 +179,7 @@
subprocess.run(args, check=True)
self._persistence_mode = pynvml.nvmlDeviceGetPersistenceMode(self.dev)

def set_clocks(self, mem_clock, gr_clock):

Check failure on line 182 in kernel_tuner/observers/nvml.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=KernelTuner_kernel_tuner&issues=AZ7U5MKJ3lU8bKZut-Ju&open=AZ7U5MKJ3lU8bKZut-Ju&pullRequest=392
"""Set the memory and graphics clock for this device (may require permission)."""

mem_clock = min(self.supported_mem_clocks, key=lambda x: abs(x - mem_clock))
Expand Down Expand Up @@ -210,6 +220,9 @@
self.applications_mem_clock = mem_clock

# Store the fact that we have modified the clocks
if not self.modified_clocks:
import atexit
atexit.register(self.reset_clocks)
self.modified_clocks = True

def reset_clocks(self):
Expand Down
Loading