Ejemplo n.º 1
0
 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
         ]))
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
 def from_utils(cls, gpu_ids: Optional[List] = None) -> "GPU":
     return cls(num_gpus=len(get_gpu_details()), gpu_ids=gpu_ids)
Ejemplo n.º 4
0
 def __repr__(self) -> str:
     return super().__repr__() + " ({})".format(", ".join(
         [d["name"] for d in get_gpu_details()]))
Ejemplo n.º 5
0
    def test_gpu_details_not_available(self):
        from codecarbon.core.gpu import get_gpu_details

        assert get_gpu_details() == []
Ejemplo n.º 6
0
    def test_gpu_details(self):
        from codecarbon.core.gpu import get_gpu_details

        assert get_gpu_details() == self.expected