99 skip_if_managed_memory_unsupported ,
1010)
1111from cuda .core import Device , Host , ManagedBuffer
12- from cuda .core ._utils . cuda_utils import handle_return
12+ from cuda .core ._memory . _managed_buffer import _get_int_attr
1313
1414try :
1515 from cuda .bindings import driver
1818
1919
2020_MANAGED_TEST_ALLOCATION_SIZE = 4096
21- _MEM_RANGE_ATTRIBUTE_VALUE_SIZE = 4
2221_READ_MOSTLY_ENABLED = 1
2322_HOST_LOCATION_ID = - 1
2423_INVALID_HOST_DEVICE_ORDINAL = 0
2524
2625
27- def _get_mem_range_attr (buffer , attribute , data_size ):
28- return handle_return (driver .cuMemRangeGetAttribute (data_size , attribute , buffer .handle , buffer .size ))
29-
30-
31- def _get_int_mem_range_attr (buffer , attribute ):
32- return _get_mem_range_attr (buffer , attribute , _MEM_RANGE_ATTRIBUTE_VALUE_SIZE )
33-
34-
3526def _skip_if_managed_allocation_unsupported (device ):
3627 try :
3728 if not device .properties .managed_memory :
@@ -70,15 +61,15 @@ def test_managed_memory_prefetch_supports_managed_pool_allocations(init_cuda):
7061
7162 buffer .prefetch (Host (), stream = stream )
7263 stream .sync ()
73- last_location = _get_int_mem_range_attr (
64+ last_location = _get_int_attr (
7465 buffer ,
7566 driver .CUmem_range_attribute .CU_MEM_RANGE_ATTRIBUTE_LAST_PREFETCH_LOCATION ,
7667 )
7768 assert last_location == _HOST_LOCATION_ID
7869
7970 buffer .prefetch (device , stream = stream )
8071 stream .sync ()
81- last_location = _get_int_mem_range_attr (
72+ last_location = _get_int_attr (
8273 buffer ,
8374 driver .CUmem_range_attribute .CU_MEM_RANGE_ATTRIBUTE_LAST_PREFETCH_LOCATION ,
8475 )
@@ -97,15 +88,15 @@ def test_managed_memory_advise_supports_external_managed_allocations(init_cuda):
9788
9889 buffer .read_mostly = True
9990 assert (
100- _get_int_mem_range_attr (
91+ _get_int_attr (
10192 buffer ,
10293 driver .CUmem_range_attribute .CU_MEM_RANGE_ATTRIBUTE_READ_MOSTLY ,
10394 )
10495 == _READ_MOSTLY_ENABLED
10596 )
10697
10798 buffer .preferred_location = Host ()
108- preferred_location = _get_int_mem_range_attr (
99+ preferred_location = _get_int_attr (
109100 buffer ,
110101 driver .CUmem_range_attribute .CU_MEM_RANGE_ATTRIBUTE_PREFERRED_LOCATION ,
111102 )
@@ -126,7 +117,7 @@ def test_managed_memory_prefetch_supports_external_managed_allocations(init_cuda
126117 buffer .prefetch (device , stream = stream )
127118 stream .sync ()
128119
129- last_location = _get_int_mem_range_attr (
120+ last_location = _get_int_attr (
130121 buffer ,
131122 driver .CUmem_range_attribute .CU_MEM_RANGE_ATTRIBUTE_LAST_PREFETCH_LOCATION ,
132123 )
@@ -151,7 +142,7 @@ def test_managed_memory_discard_prefetch_supports_managed_pool_allocations(init_
151142 buffer .discard_prefetch (device , stream = stream )
152143 stream .sync ()
153144
154- last_location = _get_int_mem_range_attr (
145+ last_location = _get_int_attr (
155146 buffer ,
156147 driver .CUmem_range_attribute .CU_MEM_RANGE_ATTRIBUTE_LAST_PREFETCH_LOCATION ,
157148 )
@@ -175,7 +166,7 @@ def test_managed_memory_discard_prefetch_supports_external_managed_allocations(i
175166 buffer .discard_prefetch (device , stream = stream )
176167 stream .sync ()
177168
178- last_location = _get_int_mem_range_attr (
169+ last_location = _get_int_attr (
179170 buffer ,
180171 driver .CUmem_range_attribute .CU_MEM_RANGE_ATTRIBUTE_LAST_PREFETCH_LOCATION ,
181172 )
@@ -369,7 +360,7 @@ def test_same_location(self, init_cuda):
369360 stream .sync ()
370361
371362 for buf in bufs :
372- last = _get_int_mem_range_attr (
363+ last = _get_int_attr (
373364 buf ,
374365 driver .CUmem_range_attribute .CU_MEM_RANGE_ATTRIBUTE_LAST_PREFETCH_LOCATION ,
375366 )
@@ -391,11 +382,11 @@ def test_per_buffer_location(self, init_cuda):
391382 prefetch_batch (bufs , [Host (), device ], stream = stream )
392383 stream .sync ()
393384
394- last0 = _get_int_mem_range_attr (
385+ last0 = _get_int_attr (
395386 bufs [0 ],
396387 driver .CUmem_range_attribute .CU_MEM_RANGE_ATTRIBUTE_LAST_PREFETCH_LOCATION ,
397388 )
398- last1 = _get_int_mem_range_attr (
389+ last1 = _get_int_attr (
399390 bufs [1 ],
400391 driver .CUmem_range_attribute .CU_MEM_RANGE_ATTRIBUTE_LAST_PREFETCH_LOCATION ,
401392 )
@@ -487,7 +478,7 @@ def test_same_location(self, init_cuda):
487478 discard_prefetch_batch (bufs , device , stream = stream )
488479 stream .sync ()
489480 for buf in bufs :
490- last = _get_int_mem_range_attr (
481+ last = _get_int_attr (
491482 buf ,
492483 driver .CUmem_range_attribute .CU_MEM_RANGE_ATTRIBUTE_LAST_PREFETCH_LOCATION ,
493484 )
@@ -633,7 +624,7 @@ def test_instance_prefetch(self, init_cuda):
633624 try :
634625 buf .prefetch (device , stream = stream )
635626 stream .sync ()
636- last = _get_int_mem_range_attr (
627+ last = _get_int_attr (
637628 buf ,
638629 driver .CUmem_range_attribute .CU_MEM_RANGE_ATTRIBUTE_LAST_PREFETCH_LOCATION ,
639630 )
@@ -670,7 +661,7 @@ def test_instance_discard_prefetch(self, init_cuda):
670661 stream .sync ()
671662 buf .discard_prefetch (device , stream = stream )
672663 stream .sync ()
673- last = _get_int_mem_range_attr (
664+ last = _get_int_attr (
674665 buf ,
675666 driver .CUmem_range_attribute .CU_MEM_RANGE_ATTRIBUTE_LAST_PREFETCH_LOCATION ,
676667 )
0 commit comments