44import os
55from unittest .mock import patch
66
7- import pynvml
87import pytest
98
109try :
1615 Device = cuda .core .experimental .Device
1716
1817
18+ from cuda .core import system
19+
20+
1921from dask .config import canonical_name
2022
2123from dask_cuda .utils import (
3032 nvml_device_index ,
3133 parse_cuda_visible_device ,
3234 parse_device_memory_limit ,
33- unpack_bitmask ,
3435)
3536
3637
@@ -62,30 +63,6 @@ def test_get_n_gpus():
6263 assert get_n_gpus () == 3
6364
6465
65- @pytest .mark .parametrize (
66- "params" ,
67- [
68- {
69- "input" : [1152920405096267775 , 0 ],
70- "output" : [i for i in range (20 )] + [i + 40 for i in range (20 )],
71- },
72- {
73- "input" : [17293823668613283840 , 65535 ],
74- "output" : [i + 20 for i in range (20 )] + [i + 60 for i in range (20 )],
75- },
76- {"input" : [18446744073709551615 , 0 ], "output" : [i for i in range (64 )]},
77- {"input" : [0 , 18446744073709551615 ], "output" : [i + 64 for i in range (64 )]},
78- ],
79- )
80- def test_unpack_bitmask (params ):
81- assert unpack_bitmask (params ["input" ]) == params ["output" ]
82-
83-
84- def test_unpack_bitmask_single_value ():
85- with pytest .raises (TypeError ):
86- unpack_bitmask (1 )
87-
88-
8966def test_cpu_affinity ():
9067 for i in range (get_n_gpus ()):
9168 affinity = get_cpu_affinity (i )
@@ -220,15 +197,10 @@ def test_get_ucx_config(enable_tcp_over_ucx, enable_infiniband, enable_nvlink):
220197
221198
222199def test_parse_visible_devices ():
223- pynvml .nvmlInit ()
224200 indices = []
225201 uuids = []
226- for index in range (get_gpu_count ()):
227- handle = pynvml .nvmlDeviceGetHandleByIndex (index )
228- try :
229- uuid = pynvml .nvmlDeviceGetUUID (handle ).decode ("utf-8" )
230- except AttributeError :
231- uuid = pynvml .nvmlDeviceGetUUID (handle )
202+ for index , device in enumerate (system .Device .get_all_devices ()):
203+ uuid = device .uuid
232204
233205 assert parse_cuda_visible_device (index ) == index
234206 assert parse_cuda_visible_device (uuid ) == uuid
@@ -350,12 +322,10 @@ def test_has_device_memory_resoure():
350322
351323
352324def test_parse_visible_mig_devices ():
353- pynvml .nvmlInit ()
354- for index in range (get_gpu_count ()):
355- handle = pynvml .nvmlDeviceGetHandleByIndex (index )
325+ for device in system .Device .get_all_devices ():
356326 try :
357- mode = pynvml . nvmlDeviceGetMigMode ( handle )[ 0 ]
358- except pynvml . NVMLError :
327+ mode = device . mig . mode
328+ except system . NvmlError :
359329 # if not a MIG device, i.e. a normal GPU, skip
360330 continue
361331 if mode :
@@ -364,14 +334,6 @@ def test_parse_visible_mig_devices():
364334 # in that GPU is <= to count, where count gives us the
365335 # maximum number of MIG devices/instances that can exist
366336 # under a given parent NVML device.
367- count = pynvml .nvmlDeviceGetMaxMigDeviceCount (handle )
368- miguuids = []
369- for i in range (count ):
370- try :
371- mighandle = pynvml .nvmlDeviceGetMigDeviceHandleByIndex (
372- device = handle , index = i
373- )
374- miguuids .append (mighandle )
375- except pynvml .NVMLError :
376- pass
377- assert len (miguuids ) <= count
337+ mig_devices = list (device .mig .get_all_devices ())
338+ count = device .mig .get_device_count ()
339+ assert len (mig_devices ) <= count
0 commit comments