(self)
| 31 | |
| 32 | class FakeGPUEnv: |
| 33 | def setup_method(self): |
| 34 | self.old_sys_path = copy(sys.path) |
| 35 | fake_module_path = os.path.join(os.path.dirname(__file__), "fake_modules") |
| 36 | sys.path.insert(0, fake_module_path) |
| 37 | |
| 38 | # Clean old modules |
| 39 | try: |
| 40 | del sys.modules["pynvml"] |
| 41 | except KeyError: |
| 42 | pass |
| 43 | |
| 44 | try: |
| 45 | del sys.modules["codecarbon.core.gpu"] |
| 46 | except KeyError: |
| 47 | pass |
| 48 | for module_name in ( |
| 49 | "codecarbon.core.gpu_amd", |
| 50 | "codecarbon.core.gpu_nvidia", |
| 51 | "codecarbon.core.gpu_device", |
| 52 | ): |
| 53 | sys.modules.pop(module_name, None) |
| 54 | |
| 55 | import codecarbon.core |
| 56 | |
| 57 | for attr in ["gpu", "gpu_nvidia", "gpu_amd", "gpu_device"]: |
| 58 | if hasattr(codecarbon.core, attr): |
| 59 | delattr(codecarbon.core, attr) |
| 60 | |
| 61 | import codecarbon.core |
| 62 | |
| 63 | for attr in ["gpu", "gpu_nvidia", "gpu_amd", "gpu_device"]: |
| 64 | if hasattr(codecarbon.core, attr): |
| 65 | delattr(codecarbon.core, attr) |
| 66 | |
| 67 | # Setup the state, strings are returned as bytes |
| 68 | self.DETAILS = { |
| 69 | "handle_0": { |
| 70 | "name": b"GeForce GTX 1080", |
| 71 | "uuid": b"uuid-1", |
| 72 | "memory": real_pynvml.c_nvmlMemory_t(1024, 100, 924), |
| 73 | "temperature": 75, |
| 74 | "power_usage": 26000, |
| 75 | "total_energy_consumption": 1000, |
| 76 | "power_limit": 149000, |
| 77 | "utilization_rate": real_pynvml.c_nvmlUtilization_t(96, 0), |
| 78 | "compute_mode": 0, |
| 79 | "compute_processes": [ |
| 80 | real_pynvml.c_nvmlProcessInfo_t(16, 1024 * 1024), |
| 81 | real_pynvml.c_nvmlProcessInfo_t(32, 2 * 1024 * 1024), |
| 82 | ], |
| 83 | "graphics_processes": [], |
| 84 | }, |
| 85 | "handle_1": { |
| 86 | "name": b"GeForce GTX 1080", |
| 87 | "uuid": b"uuid-2", |
| 88 | "memory": real_pynvml.c_nvmlMemory_t(1024, 200, 824), |
| 89 | "temperature": 79, |
| 90 | "power_usage": 29000, |
nothing calls this directly
no outgoing calls
no test coverage detected