10
10
'GPU. Otherwise the GPU RAM and GPU utilization values will remain 0.0.' )
11
11
12
12
13
+ @pt .fixture (name = 'gpu_brand' , params = ['amd' , 'nvidia' ])
14
+ def get_gpu_brand (request ) -> str :
15
+ yield request .param
16
+
17
+
13
18
@pt .fixture (name = 'operating_system' , params = ['Linux' , 'not-linux' ])
14
19
def get_operating_system (request ) -> str :
15
20
yield request .param
@@ -30,8 +35,8 @@ def get_use_context_manager(request) -> bool:
30
35
31
36
@pt .mark .parametrize ('ram_unit,gpu_ram_unit,time_unit,gpu_uuids,n_expected_cores' , test_tracker_data )
32
37
def test_tracker (
33
- mocker , use_context_manager : bool , operating_system : str , ram_unit : str , gpu_ram_unit : str , time_unit : str , gpu_uuids : set [ str ] ,
34
- n_expected_cores : int ):
38
+ mocker , gpu_brand : str , use_context_manager : bool , operating_system : str , ram_unit : str , gpu_ram_unit : str , time_unit : str ,
39
+ gpu_uuids : set [ str ], n_expected_cores : int ):
35
40
class EventMock :
36
41
def __init__ (self ):
37
42
self .count = 0
@@ -126,17 +131,31 @@ def start_mock(self):
126
131
'gpu_tracker.tracker.psutil.virtual_memory' , side_effect = [
127
132
mocker .MagicMock (total = 67 * 1e9 ), mocker .MagicMock (used = 30 * 1e9 ), mocker .MagicMock (used = 31 * 1e9 ),
128
133
mocker .MagicMock (used = 29 * 1e9 )])
129
- nvidia_smi_outputs = [
130
- b'' ,
131
- b'' ,
132
- b' uuid,memory.total [MiB]\n gpu-id1,12198 MiB\n gpu-id2,12198 MiB\n gpu-id3 , 12198MiB' ,
133
- b'pid, used_gpu_memory [MiB]\n ' ,
134
- b'uuid, memory.used [MiB], utilization.gpu [%]\n gpu-id1, 0 MiB, 0 %\n gpu-id2 , 0 MiB, 0 %\n gpu-id3 , 0 MiB, 0 %' ,
135
- b'pid, used_gpu_memory [MiB]\n 12,1600 MiB\n 21,700 MiB\n 22,200 MiB' ,
136
- b'uuid, memory.used [MiB], utilization.gpu [%]\n gpu-id1, 1600 MiB,75 %\n gpu-id2,900 MiB , 50 %\n gpu-id3, 500 MiB, 25 %' ,
137
- b'pid, used_gpu_memory [MiB]\n 12,1500 MiB\n 21,2100 MiB\n 22,2200 MiB' ,
138
- b'uuid, memory.used [MiB], utilization.gpu [%]\n gpu-id1, 1500 MiB, 55 %\n gpu-id2, 4300 MiB, 45%\n gpu-id3,700MiB,35%' ]
139
- check_output_mock = mocker .patch ('gpu_tracker.tracker.subp.check_output' , side_effect = nvidia_smi_outputs )
134
+ if gpu_brand == 'nvidia' :
135
+ check_output_side_effect = [
136
+ b'' ,
137
+ b'' ,
138
+ b' uuid,memory.total [MiB]\n gpu-id1,12198 MiB\n gpu-id2,12198 MiB\n gpu-id3 , 12198MiB' ,
139
+ b'pid, used_gpu_memory [MiB]\n ' ,
140
+ b'uuid, memory.used [MiB], utilization.gpu [%]\n gpu-id1, 0 MiB, 0 %\n gpu-id2 , 0 MiB, 0 %\n gpu-id3 , 0 MiB, 0 %' ,
141
+ b'pid, used_gpu_memory [MiB]\n 12,1600 MiB\n 21,700 MiB\n 22,200 MiB' ,
142
+ b'uuid, memory.used [MiB], utilization.gpu [%]\n gpu-id1, 1600 MiB,75 %\n gpu-id2,900 MiB , 50 %\n gpu-id3, 500 MiB, 25 %' ,
143
+ b'pid, used_gpu_memory [MiB]\n 12,1500 MiB\n 21,2100 MiB\n 22,2200 MiB' ,
144
+ b'uuid, memory.used [MiB], utilization.gpu [%]\n gpu-id1, 1500 MiB, 55 %\n gpu-id2, 4300 MiB, 45%\n gpu-id3,700MiB,35%' ]
145
+ else :
146
+ check_output_side_effect = [
147
+ FileNotFoundError ,
148
+ b'' ,
149
+ b'gpu,size,extraneous-col\n 0,12198,some-val\n 1,12198,some-val\n 2 , 12198,some-val' ,
150
+ b'gpu,gpu_uuid,extraneous-col\n 0,gpu-id1,some-val\n 1,gpu-id2,some-val\n 2,gpu-id3 ,some-val' ,
151
+ b'pid,vram_mem\n ' ,
152
+ b'gpu,vram_used,gfx\n 0,0,0\n 1 ,0,0\n 2 ,0,0' ,
153
+ b'pid,vram_mem\n 12,1600000000\n 21,700000000\n 22,200000000' ,
154
+ b'gpu,vram_used,gfx\n 0,1600,75\n 1,900,50\n 2,500,25' ,
155
+ b'pid,vram_mem\n 12,1500000000\n 21,2100000000\n 22,2200000000' ,
156
+ b'gpu,vram_used,gfx\n 0,1500,55\n 1,4300,45\n 2,700,35'
157
+ ]
158
+ check_output_mock = mocker .patch ('gpu_tracker.tracker.subp.check_output' , side_effect = check_output_side_effect )
140
159
cpu_count_mock = mocker .patch ('gpu_tracker.tracker.psutil.cpu_count' , return_value = 4 )
141
160
cpu_percent_mock = mocker .patch (
142
161
'gpu_tracker.tracker.psutil.cpu_percent' , side_effect = [[67.5 , 27.3 , 77.8 , 97.9 ], [57.6 , 58.2 , 23.5 , 99.8 ], [78.3 , 88.3 , 87.2 , 22.5 ]])
@@ -157,6 +176,7 @@ def start_mock(self):
157
176
gpu_uuids = gpu_uuids , n_expected_cores = n_expected_cores )
158
177
tracker .start ()
159
178
tracker .stop ()
179
+ gput .tracker ._AMDQuerier ._AMDQuerier__id_to_uuid = None
160
180
assert start_mock .called
161
181
assert not os .path .isfile (tracker ._resource_usage_file )
162
182
assert not log_spy .called
@@ -175,7 +195,7 @@ def start_mock(self):
175
195
utils .assert_args_list (mock = main_process_mock .memory_info , expected_args_list = [()] * 3 )
176
196
utils .assert_args_list (mock = child1_mock .memory_info , expected_args_list = [()] * 3 )
177
197
utils .assert_args_list (mock = child2_mock .memory_info , expected_args_list = [()] * 3 )
178
- assert len (check_output_mock .call_args_list ) == 9
198
+ assert len (check_output_mock .call_args_list ) == 10 if gpu_brand == 'amd' else 9
179
199
os_mock .getpid .assert_called_once_with ()
180
200
utils .assert_args_list (mock = time_mock .time , expected_args_list = [()] * 5 )
181
201
cpu_percent_interval = gput .tracker ._TrackingProcess ._CPU_PERCENT_INTERVAL
@@ -211,7 +231,7 @@ def side_effect_func(command, *_, **__) -> None:
211
231
# The check_output mock is called 3 times before it's supposed to, causing a "RuntimeError: generator raised StopIteration".
212
232
if command in ('nvidia-smi' , 'amd-smi' ):
213
233
raise exceptions .pop ()
214
- raise FileNotFoundError ()
234
+ raise FileNotFoundError () # pragma: nocover
215
235
mocker .patch ('gpu_tracker.tracker.subp.check_output' , side_effect = side_effect_func )
216
236
gput .Tracker ()
217
237
gput .Tracker ()
0 commit comments