def _SetAndConfirmGpuClocks(vm): """Sets and confirms the GPU clock speed. The clock values are provided in the gpu_pcie_bandwidth_clock_speeds flag. If a device is queried and its clock speed does not allign with what it was just set to, an expection will be raised. Args: vm: the virtual machine to operate on. Raises: UnsupportedClockSpeedException if a GPU did not accept the provided clock speeds. """ desired_memory_clock = FLAGS.gpu_pcie_bandwidth_clock_speeds[0] desired_graphics_clock = FLAGS.gpu_pcie_bandwidth_clock_speeds[1] cuda_toolkit_8.SetGpuClockSpeed(vm, desired_memory_clock, desired_graphics_clock) num_gpus = cuda_toolkit_8.QueryNumberOfGpus(vm) for i in range(num_gpus): if cuda_toolkit_8.QueryGpuClockSpeed( vm, i) != (desired_memory_clock, desired_graphics_clock): raise UnsupportedClockSpeedException( 'Unrecoverable error setting ' 'GPU #{} clock speed to {},{}'.format(i, desired_memory_clock, desired_graphics_clock))
def testQueryGpuClockSpeed(self): vm = mock.MagicMock() vm.RemoteCommand = mock.MagicMock( return_value=("clocks.applications.graphics [MHz], " "clocks.applications.memory [Mhz]\n" "324 MHz, 527 MHz", None)) self.assertEqual((324, 527), cuda_toolkit_8.QueryGpuClockSpeed(vm, 3)) vm.RemoteCommand.assert_called_with( "sudo nvidia-smi " "--query-gpu=clocks.applications.memory," "clocks.applications.graphics --format=csv --id=3", should_log=True)