-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_platform_detection.py
More file actions
512 lines (402 loc) · 23.1 KB
/
test_platform_detection.py
File metadata and controls
512 lines (402 loc) · 23.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
import pytest
from torchruntime.device_db import GPU
from torchruntime.platform_detection import get_torch_platform, AMD, NVIDIA, INTEL, os_name, arch, py_version
def test_no_discrete_gpus_windows(monkeypatch):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Windows")
monkeypatch.setattr("torchruntime.platform_detection.arch", "amd64")
assert get_torch_platform([]) == "cpu"
def test_no_discrete_gpus_linux(monkeypatch):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Linux")
monkeypatch.setattr("torchruntime.platform_detection.arch", "x86_64")
assert get_torch_platform([]) == "cpu"
def test_no_discrete_gpus_mac(monkeypatch):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Darwin")
monkeypatch.setattr("torchruntime.platform_detection.arch", "arm64")
assert get_torch_platform([]) == "cpu"
def test_amd_gpu_windows(monkeypatch):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Windows")
monkeypatch.setattr("torchruntime.platform_detection.arch", "amd64")
gpu_infos = [GPU(AMD, "AMD", 0x1234, "Radeon", True)]
assert get_torch_platform(gpu_infos) == "directml"
def test_amd_gpu_navi4_linux(monkeypatch):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Linux")
monkeypatch.setattr("torchruntime.platform_detection.arch", "x86_64")
gpu_infos = [GPU(AMD, "AMD", 0x1234, "Navi 41", True)]
if py_version < (3, 9):
with pytest.raises(NotImplementedError):
get_torch_platform(gpu_infos)
else:
assert get_torch_platform(gpu_infos) == "cpu"
assert get_torch_platform(gpu_infos, preview=True) == "rocm6.4"
def test_amd_gpu_navi3_linux(monkeypatch, capsys):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Linux")
monkeypatch.setattr("torchruntime.platform_detection.arch", "x86_64")
gpu_infos = [GPU(AMD, "AMD", 0x1234, "Navi 31", True)]
expected = "rocm6.1" if py_version < (3, 9) else "rocm6.2"
assert get_torch_platform(gpu_infos) == expected
if py_version < (3, 9):
captured = capsys.readouterr()
assert "Support for Python 3.8 was dropped in ROCm 6.2" in captured.out
def test_amd_gpu_navi2_linux(monkeypatch, capsys):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Linux")
monkeypatch.setattr("torchruntime.platform_detection.arch", "x86_64")
gpu_infos = [GPU(AMD, "AMD", 0x1234, "Navi 22", True)]
expected = "rocm6.1" if py_version < (3, 9) else "rocm6.2"
assert get_torch_platform(gpu_infos) == expected
if py_version < (3, 9):
captured = capsys.readouterr()
assert "Support for Python 3.8 was dropped in ROCm 6.2" in captured.out
def test_amd_gpu_navi1_linux(monkeypatch):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Linux")
monkeypatch.setattr("torchruntime.platform_detection.arch", "x86_64")
gpu_infos = [GPU(AMD, "AMD", 0x1234, "Navi 10", True)]
assert get_torch_platform(gpu_infos) == "rocm5.2"
def test_amd_gpu_vega2_linux(monkeypatch):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Linux")
monkeypatch.setattr("torchruntime.platform_detection.arch", "x86_64")
gpu_infos = [GPU(AMD, "AMD", 0x1234, "Vega 20", True)]
assert get_torch_platform(gpu_infos) == "rocm5.7"
def test_amd_gpu_vega1_linux(monkeypatch):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Linux")
monkeypatch.setattr("torchruntime.platform_detection.arch", "x86_64")
gpu_infos = [GPU(AMD, "AMD", 0x1234, "Vega 10", True)]
assert get_torch_platform(gpu_infos) == "rocm5.2"
def test_amd_gpu_ellesmere_linux(monkeypatch):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Linux")
monkeypatch.setattr("torchruntime.platform_detection.arch", "x86_64")
gpu_infos = [GPU(AMD, "AMD", 0x1234, "Ellesmere", True)]
assert get_torch_platform(gpu_infos) == "rocm4.2"
def test_amd_gpu_ellesmere_linux_unsupported_false_raises(monkeypatch):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Linux")
monkeypatch.setattr("torchruntime.platform_detection.arch", "x86_64")
gpu_infos = [GPU(AMD, "AMD", 0x1234, "Ellesmere", True)]
with pytest.raises(ValueError, match="End-of-Life"):
get_torch_platform(gpu_infos, unsupported=False)
def test_amd_gpu_unsupported_linux(monkeypatch, capsys):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Linux")
monkeypatch.setattr("torchruntime.platform_detection.arch", "x86_64")
gpu_infos = [GPU(AMD, "AMD", 0x1234, "UnknownModel", True)]
assert get_torch_platform(gpu_infos) == "cpu"
captured = capsys.readouterr()
assert "[WARNING] Unsupported AMD graphics card" in captured.out
def test_amd_gpu_mac(monkeypatch):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Darwin")
monkeypatch.setattr("torchruntime.platform_detection.arch", "arm64")
gpu_infos = [GPU(AMD, "AMD", 0x1234, "Radeon", True)]
assert get_torch_platform(gpu_infos) == "mps"
def test_nvidia_gpu_windows(monkeypatch):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Windows")
monkeypatch.setattr("torchruntime.platform_detection.arch", "amd64")
gpu_infos = [GPU(NVIDIA, "NVIDIA", 0x1234, "GeForce", True)]
expected = "cu124" if py_version < (3, 9) else "cu128"
assert get_torch_platform(gpu_infos) == expected
def test_nvidia_gpu_linux(monkeypatch):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Linux")
monkeypatch.setattr("torchruntime.platform_detection.arch", "x86_64")
gpu_infos = [GPU(NVIDIA, "NVIDIA", 0x1234, "GeForce", True)]
expected = "cu124" if py_version < (3, 9) else "cu128"
assert get_torch_platform(gpu_infos) == expected
def test_nvidia_gpu_demotes_to_cu124_for_pinned_torch_below_2_7(monkeypatch):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Windows")
monkeypatch.setattr("torchruntime.platform_detection.arch", "amd64")
monkeypatch.setattr("torchruntime.platform_detection.py_version", (3, 11))
monkeypatch.setattr("torchruntime.platform_detection.get_nvidia_arch", lambda device_names: 8.6)
gpu_infos = [GPU(NVIDIA, "NVIDIA", 0x1234, "GeForce", True)]
assert get_torch_platform(gpu_infos) == "cu128"
assert get_torch_platform(gpu_infos, packages=["torch==2.6.0"]) == "cu124"
assert get_torch_platform(gpu_infos, packages=["torch<2.7.0"]) == "cu124"
assert get_torch_platform(gpu_infos, packages=["torch<=2.7.0"]) == "cu128"
assert get_torch_platform(gpu_infos, packages=["torch!=2.7.0"]) == "cu128"
assert get_torch_platform(gpu_infos, packages=["torch>=2.7.0,!=2.7.0,!=2.7.1,<2.8.0"]) == "cu128"
assert get_torch_platform(gpu_infos, packages=["torchvision==0.21.0"]) == "cu124"
def test_nvidia_gpu_mac(monkeypatch):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Darwin")
monkeypatch.setattr("torchruntime.platform_detection.arch", "arm64")
gpu_infos = [GPU(NVIDIA, "NVIDIA", 0x1234, "GeForce", True)]
with pytest.raises(NotImplementedError):
get_torch_platform(gpu_infos)
def test_nvidia_7xx_gpu_windows(monkeypatch):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Windows")
monkeypatch.setattr("torchruntime.platform_detection.arch", "amd64")
gpu_infos = [GPU(NVIDIA, "NVIDIA", "1004", "GK110 [GeForce GTX 780]", True)]
assert get_torch_platform(gpu_infos) == "cu118"
def test_nvidia_10xx_gpu_windows(monkeypatch):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Windows")
monkeypatch.setattr("torchruntime.platform_detection.arch", "amd64")
gpu_infos = [GPU(NVIDIA, "NVIDIA", "1c02", "GP106 [GeForce GTX 1060 3GB]", True)]
assert get_torch_platform(gpu_infos) == "cu124"
def test_nvidia_16xx_gpu_windows(monkeypatch):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Windows")
monkeypatch.setattr("torchruntime.platform_detection.arch", "amd64")
gpu_infos = [GPU(NVIDIA, "NVIDIA", "21c4", "TU116 [GeForce GTX 1660 SUPER]", True)]
expected = "cu124" if py_version < (3, 9) else "cu128"
assert get_torch_platform(gpu_infos) == expected
def test_nvidia_20xx_gpu_windows(monkeypatch):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Windows")
monkeypatch.setattr("torchruntime.platform_detection.arch", "amd64")
gpu_infos = [GPU(NVIDIA, "NVIDIA", "1f11", "TU106M [GeForce RTX 2060 Mobile]", True)]
expected = "cu124" if py_version < (3, 9) else "cu128"
assert get_torch_platform(gpu_infos) == expected
def test_nvidia_30xx_gpu_windows(monkeypatch):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Windows")
monkeypatch.setattr("torchruntime.platform_detection.arch", "amd64")
gpu_infos = [GPU(NVIDIA, "NVIDIA", "2489", "GA104 [GeForce RTX 3060 Ti Lite Hash Rate]", True)]
expected = "cu124" if py_version < (3, 9) else "cu128"
assert get_torch_platform(gpu_infos) == expected
def test_nvidia_40xx_gpu_windows(monkeypatch):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Windows")
monkeypatch.setattr("torchruntime.platform_detection.arch", "amd64")
gpu_infos = [GPU(NVIDIA, "NVIDIA", "2705", "AD103 [GeForce RTX 4070 Ti SUPER]", True)]
expected = "cu124" if py_version < (3, 9) else "cu128"
assert get_torch_platform(gpu_infos) == expected
def test_nvidia_5xxx_gpu_windows(monkeypatch):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Windows")
monkeypatch.setattr("torchruntime.platform_detection.arch", "amd64")
gpu_infos = [GPU(NVIDIA, "NVIDIA", "2c02", "GB203 [GeForce RTX 5080]", True)]
if py_version < (3, 9):
with pytest.raises(NotImplementedError):
get_torch_platform(gpu_infos)
else:
assert get_torch_platform(gpu_infos) == "cu128"
def test_intel_gpu_windows(monkeypatch):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Windows")
monkeypatch.setattr("torchruntime.platform_detection.arch", "amd64")
gpu_infos = [GPU(INTEL, "Intel", 0x1234, "Iris", True)]
expected = "directml" if py_version < (3, 9) else "xpu"
assert get_torch_platform(gpu_infos) == expected
def test_intel_gpu_linux(monkeypatch):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Linux")
monkeypatch.setattr("torchruntime.platform_detection.arch", "x86_64")
gpu_infos = [GPU(INTEL, "Intel", 0x1234, "Iris", True)]
expected = "ipex" if py_version < (3, 9) else "xpu"
assert get_torch_platform(gpu_infos) == expected
def test_nvidia_5xxx_gpu_linux(monkeypatch):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Linux")
monkeypatch.setattr("torchruntime.platform_detection.arch", "x86_64")
gpu_infos = [GPU(NVIDIA, "NVIDIA", "2c02", "GB203 [GeForce RTX 5080]", True)]
if py_version < (3, 9):
with pytest.raises(NotImplementedError):
get_torch_platform(gpu_infos)
else:
assert get_torch_platform(gpu_infos) == "cu128"
def test_intel_gpu_mac(monkeypatch):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Darwin")
monkeypatch.setattr("torchruntime.platform_detection.arch", "arm64")
gpu_infos = [GPU(INTEL, "Intel", 0x1234, "Iris", True)]
with pytest.raises(NotImplementedError):
get_torch_platform(gpu_infos)
def test_multiple_gpu_vendors_with_NVIDIA(monkeypatch):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Windows")
monkeypatch.setattr("torchruntime.platform_detection.arch", "amd64")
gpu_infos = [
GPU(AMD, "AMD", 0x1234, "Radeon", True),
GPU(NVIDIA, "NVIDIA", 0x5678, "GeForce", True),
]
expected = "cu124" if py_version < (3, 9) else "cu128"
assert get_torch_platform(gpu_infos) == expected
def test_multiple_gpu_vendors_without_NVIDIA(monkeypatch):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Windows")
monkeypatch.setattr("torchruntime.platform_detection.arch", "amd64")
gpu_infos = [
GPU(AMD, "AMD", 0x1234, "Radeon", True),
GPU(INTEL, "Intel", 0x5678, "Iris", True),
]
with pytest.raises(NotImplementedError):
get_torch_platform(gpu_infos)
def test_multiple_gpu_NVIDIA(monkeypatch):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Linux")
monkeypatch.setattr("torchruntime.platform_detection.arch", "x86_64")
gpu_infos = [
GPU(NVIDIA, "NVIDIA", "2504", "GA106 [GeForce RTX 3060 Lite Hash Rate]", True),
GPU(NVIDIA, "NVIDIA", "1c02", "GP106 [GeForce GTX 1060 3GB]", True),
]
expected = "cu124" if py_version < (3, 9) else "cu128"
assert get_torch_platform(gpu_infos) == expected
def test_multiple_gpu_NVIDIA_maxwell(monkeypatch):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Linux")
monkeypatch.setattr("torchruntime.platform_detection.arch", "x86_64")
gpu_infos = [
GPU(NVIDIA, "NVIDIA", "17fd", "GM200GL [Tesla M40]", True),
GPU(NVIDIA, "NVIDIA", "1401", "GM206 [GeForce GTX 960]", True),
]
expected = "cu124"
assert get_torch_platform(gpu_infos) == expected
def test_multiple_gpu_AMD_Navi3_Navi2(monkeypatch, capsys):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Linux")
monkeypatch.setattr("torchruntime.platform_detection.arch", "x86_64")
gpu_infos = [
GPU(AMD, "AMD", "73f0", "Navi 33 [Radeon RX 7600M XT]", True),
GPU(AMD, "AMD", "73bf", "Navi 21 [Radeon RX 6800/6800 XT / 6900 XT]", True),
]
expected = "rocm6.1" if py_version < (3, 9) else "rocm6.2"
assert get_torch_platform(gpu_infos) == expected
if py_version < (3, 9):
captured = capsys.readouterr()
assert "Support for Python 3.8 was dropped in ROCm 6.2" in captured.out
def test_multiple_gpu_AMD_Navi3_Vega2(monkeypatch):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Linux")
monkeypatch.setattr("torchruntime.platform_detection.arch", "x86_64")
gpu_infos = [
GPU(AMD, "AMD", "73f0", "Navi 33 [Radeon RX 7600M XT]", True),
GPU(AMD, "AMD", "66af", "Vega 20 [Radeon VII]", True),
]
assert get_torch_platform(gpu_infos) == "rocm5.7"
def test_multiple_gpu_AMD_Vega2_Navi2(monkeypatch):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Linux")
monkeypatch.setattr("torchruntime.platform_detection.arch", "x86_64")
gpu_infos = [
GPU(AMD, "AMD", "66af", "Vega 20 [Radeon VII]", True),
GPU(AMD, "AMD", "73bf", "Navi 21 [Radeon RX 6800/6800 XT / 6900 XT]", True),
]
assert get_torch_platform(gpu_infos) == "rocm5.7"
def test_multiple_gpu_AMD_Vega1_Navi2__incompatible_rocm_version(monkeypatch, capsys):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Linux")
monkeypatch.setattr("torchruntime.platform_detection.arch", "x86_64")
gpu_infos = [
GPU(AMD, "AMD", "6867", "Vega 10 XL [Radeon Pro Vega 56]", True),
GPU(AMD, "AMD", "73bf", "Navi 21 [Radeon RX 6800/6800 XT / 6900 XT]", True),
]
expected = "rocm6.1" if py_version < (3, 9) else "rocm6.2"
assert get_torch_platform(gpu_infos) == expected
if py_version < (3, 9):
captured = capsys.readouterr()
assert "Support for Python 3.8 was dropped in ROCm 6.2" in captured.out
print("For lack of a better solution at the moment")
def test_multiple_gpu_AMD_Ellesmere_Navi3__incompatible_rocm_version(monkeypatch, capsys):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Linux")
monkeypatch.setattr("torchruntime.platform_detection.arch", "x86_64")
gpu_infos = [
GPU(AMD, "AMD", "67df", "Ellesmere [Radeon RX 470/480/570/570X/580/580X/590]", True),
GPU(AMD, "AMD", "73f0", "Navi 33 [Radeon RX 7600M XT]", True),
]
expected = "rocm6.1" if py_version < (3, 9) else "rocm6.2"
assert get_torch_platform(gpu_infos) == expected
if py_version < (3, 9):
captured = capsys.readouterr()
assert "Support for Python 3.8 was dropped in ROCm 6.2" in captured.out
print("For lack of a better solution at the moment")
def test_unsupported_architecture(monkeypatch):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Linux")
monkeypatch.setattr("torchruntime.platform_detection.arch", "sparc")
with pytest.raises(NotImplementedError):
get_torch_platform([])
def test_unrecognized_gpu_vendor(monkeypatch):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Windows")
monkeypatch.setattr("torchruntime.platform_detection.arch", "amd64")
gpu_infos = [GPU("9999", "UnknownVendor", 0x1234, "Unknown", True)]
assert get_torch_platform(gpu_infos) == "cpu"
def test_integrated_amd_gfx11_linux(monkeypatch, capsys):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Linux")
monkeypatch.setattr("torchruntime.platform_detection.arch", "x86_64")
gpu_infos = [GPU(AMD, "AMD", "164f", "Phoenix", False)] # gfx1103
expected = "rocm6.1" if py_version < (3, 9) else "rocm6.2"
assert get_torch_platform(gpu_infos) == expected
if py_version < (3, 9):
captured = capsys.readouterr()
assert "Support for Python 3.8 was dropped in ROCm 6.2" in captured.out
def test_integrated_amd_gfx103_linux(monkeypatch, capsys):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Linux")
monkeypatch.setattr("torchruntime.platform_detection.arch", "x86_64")
gpu_infos = [GPU(AMD, "AMD", "163f", "VanGogh", False)] # gfx1033
expected = "rocm6.1" if py_version < (3, 9) else "rocm6.2"
assert get_torch_platform(gpu_infos) == expected
if py_version < (3, 9):
captured = capsys.readouterr()
assert "Support for Python 3.8 was dropped in ROCm 6.2" in captured.out
def test_integrated_amd_gfx90_linux(monkeypatch):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Linux")
monkeypatch.setattr("torchruntime.platform_detection.arch", "x86_64")
gpu_infos = [GPU(AMD, "AMD", "1636", "Renoir", False)] # gfx90c
assert get_torch_platform(gpu_infos) == "rocm5.5"
def test_integrated_amd_unsupported_linux(monkeypatch, capsys):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Linux")
monkeypatch.setattr("torchruntime.platform_detection.arch", "x86_64")
gpu_infos = [GPU(AMD, "AMD", "ffff", "Unknown", False)] # Not in GPU_DEVICES
assert get_torch_platform(gpu_infos) == "cpu"
captured = capsys.readouterr()
assert "[WARNING] Unsupported AMD APU" in captured.out
def test_integrated_amd_windows(monkeypatch):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Windows")
monkeypatch.setattr("torchruntime.platform_detection.arch", "amd64")
gpu_infos = [GPU(AMD, "AMD", "164f", "Phoenix", False)]
assert get_torch_platform(gpu_infos) == "directml"
def test_integrated_amd_mac(monkeypatch, capsys):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Darwin")
monkeypatch.setattr("torchruntime.platform_detection.arch", "arm64")
gpu_infos = [GPU(AMD, "AMD", "164f", "Phoenix", False)]
assert get_torch_platform(gpu_infos) == "cpu"
captured = capsys.readouterr()
assert "torchruntime does not currently support integrated graphics cards on Macs" in captured.out
def test_integrated_intel_linux(monkeypatch, capsys):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Linux")
monkeypatch.setattr("torchruntime.platform_detection.arch", "x86_64")
gpu_infos = [GPU(INTEL, "Intel", "0x56c1", "UHD Graphics", False)]
expected = "ipex" if py_version < (3, 9) else "xpu"
assert get_torch_platform(gpu_infos) == expected
if py_version < (3, 9):
captured = capsys.readouterr()
assert "Support for Python 3.8 was dropped in torch 2.5" in captured.out
def test_integrated_intel_windows(monkeypatch):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Windows")
monkeypatch.setattr("torchruntime.platform_detection.arch", "amd64")
gpu_infos = [GPU(INTEL, "Intel", "0x56c1", "UHD Graphics", False)]
assert get_torch_platform(gpu_infos) == "directml"
def test_integrated_intel_mac(monkeypatch, capsys):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Darwin")
monkeypatch.setattr("torchruntime.platform_detection.arch", "arm64")
gpu_infos = [GPU(INTEL, "Intel", "0x56c1", "UHD Graphics", False)]
assert get_torch_platform(gpu_infos) == "cpu"
captured = capsys.readouterr()
assert "torchruntime does not currently support integrated graphics cards on Macs" in captured.out
def test_mixed_amd_discrete_integrated_linux(monkeypatch, capsys):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Linux")
monkeypatch.setattr("torchruntime.platform_detection.arch", "x86_64")
gpu_infos = [
GPU(AMD, "AMD", "164f", "Phoenix", False), # integrated
GPU(AMD, "AMD", "73f0", "Navi 33", True), # discrete
]
expected = "rocm6.1" if py_version < (3, 9) else "rocm6.2"
assert get_torch_platform(gpu_infos) == expected
if py_version < (3, 9):
captured = capsys.readouterr()
assert "Support for Python 3.8 was dropped in ROCm 6.2" in captured.out
def test_mixed_nvidia_discrete_amd_integrated_linux(monkeypatch):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Linux")
monkeypatch.setattr("torchruntime.platform_detection.arch", "x86_64")
gpu_infos = [
GPU(AMD, "AMD", "164f", "Phoenix", False), # integrated
GPU(NVIDIA, "NVIDIA", "2504", "RTX 3060", True), # discrete
]
expected = "cu124" if py_version < (3, 9) else "cu128"
assert get_torch_platform(gpu_infos) == expected
def test_mixed_nvidia_discrete_intel_integrated_windows(monkeypatch):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Windows")
monkeypatch.setattr("torchruntime.platform_detection.arch", "amd64")
gpu_infos = [
GPU(INTEL, "Intel", "0x56c1", "UHD Graphics", False), # integrated
GPU(NVIDIA, "NVIDIA", "2504", "RTX 3060", True), # discrete
]
expected = "cu124" if py_version < (3, 9) else "cu128"
assert get_torch_platform(gpu_infos) == expected
def test_mixed_amd_discrete_intel_integrated_linux(monkeypatch, capsys):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Linux")
monkeypatch.setattr("torchruntime.platform_detection.arch", "x86_64")
gpu_infos = [
GPU(INTEL, "Intel", "0x56c1", "UHD Graphics", False), # integrated
GPU(AMD, "AMD", "73f0", "Navi 33", True), # discrete
]
expected = "rocm6.1" if py_version < (3, 9) else "rocm6.2"
assert get_torch_platform(gpu_infos) == expected
if py_version < (3, 9):
captured = capsys.readouterr()
assert "Support for Python 3.8 was dropped in ROCm 6.2" in captured.out
def test_mixed_multiple_discrete_and_integrated(monkeypatch):
monkeypatch.setattr("torchruntime.platform_detection.os_name", "Linux")
monkeypatch.setattr("torchruntime.platform_detection.arch", "x86_64")
gpu_infos = [
GPU(AMD, "AMD", "164f", "Phoenix", False), # integrated AMD
GPU(NVIDIA, "NVIDIA", "2504", "RTX 3060", True), # discrete NVIDIA
GPU(AMD, "AMD", "73f0", "Navi 33", True), # discrete AMD
]
expected = "cu124" if py_version < (3, 9) else "cu128"
assert get_torch_platform(gpu_infos) == expected