def _get_power_for_gpus(self, gpu_ids: Iterable[int]) -> Power: """ Get total power consumed by specific GPUs identified by `gpu_ids` :param gpu_ids: :return: power in kW """ all_gpu_details: List[Dict] = get_gpu_details() return Power.from_milli_watts( sum([ gpu_details["power_usage"] for idx, gpu_details in enumerate(all_gpu_details) if idx in gpu_ids ]))
def test_gpu_no_power_limit(self): from codecarbon.core.gpu import get_gpu_details import pynvml def raiseException(handle): raise Exception("Some bad exception") pynvml.nvmlDeviceGetEnforcedPowerLimit = raiseException expected_power_limit = deepcopy(self.expected) expected_power_limit[0]["power_limit"] = None expected_power_limit[1]["power_limit"] = None assert get_gpu_details() == expected_power_limit
def from_utils(cls, gpu_ids: Optional[List] = None) -> "GPU": return cls(num_gpus=len(get_gpu_details()), gpu_ids=gpu_ids)
def __repr__(self) -> str: return super().__repr__() + " ({})".format(", ".join( [d["name"] for d in get_gpu_details()]))
def test_gpu_details_not_available(self): from codecarbon.core.gpu import get_gpu_details assert get_gpu_details() == []
def test_gpu_details(self): from codecarbon.core.gpu import get_gpu_details assert get_gpu_details() == self.expected