1010from helpers .graph_kernels import compile_common_kernels
1111from helpers .misc import try_create_condition
1212
13+ from conftest import xfail_on_graph_mempool_oom
1314from cuda .core import Device , LaunchConfig
1415from cuda .core .graph import (
1516 AllocNode ,
@@ -201,13 +202,15 @@ def _build_disconnected():
201202def graph_spec (request , init_cuda ):
202203 if request .param is not _build_empty :
203204 _skip_if_no_mempool ()
204- return request .param ()
205+ with xfail_on_graph_mempool_oom ():
206+ return request .param ()
205207
206208
207209@pytest .fixture (params = _NONEMPTY_BUILDERS )
208210def nonempty_graph_spec (request , init_cuda ):
209211 _skip_if_no_mempool ()
210- return request .param ()
212+ with xfail_on_graph_mempool_oom ():
213+ return request .param ()
211214
212215
213216# =============================================================================
@@ -562,7 +565,8 @@ def node_spec(request, init_cuda):
562565 if spec .needs_mempool :
563566 _skip_if_no_mempool ()
564567 g = GraphDefinition ()
565- node , expected_attrs = spec .builder (g )
568+ with xfail_on_graph_mempool_oom ():
569+ node , expected_attrs = spec .builder (g )
566570 return spec , g , node , expected_attrs
567571
568572
@@ -803,18 +807,20 @@ def test_alloc_zero_size_fails(sample_graphdef):
803807def test_free_creates_dependency (sample_graphdef ):
804808 """Free node depends on its predecessor."""
805809 _skip_if_no_mempool ()
806- alloc = sample_graphdef .allocate (ALLOC_SIZE )
807- free = alloc .deallocate (alloc .dptr )
810+ with xfail_on_graph_mempool_oom ():
811+ alloc = sample_graphdef .allocate (ALLOC_SIZE )
812+ free = alloc .deallocate (alloc .dptr )
808813 assert alloc in free .pred
809814
810815
811816def test_alloc_free_chain (sample_graphdef ):
812817 """Alloc and free can be chained."""
813818 _skip_if_no_mempool ()
814- a1 = sample_graphdef .allocate (ALLOC_SIZE )
815- a2 = a1 .allocate (ALLOC_SIZE )
816- f2 = a2 .deallocate (a2 .dptr )
817- f1 = f2 .deallocate (a1 .dptr )
819+ with xfail_on_graph_mempool_oom ():
820+ a1 = sample_graphdef .allocate (ALLOC_SIZE )
821+ a2 = a1 .allocate (ALLOC_SIZE )
822+ f2 = a2 .deallocate (a2 .dptr )
823+ f1 = f2 .deallocate (a1 .dptr )
818824 assert a1 in a2 .pred
819825 assert a2 in f2 .pred
820826 assert f2 in f1 .pred
@@ -842,15 +848,17 @@ def test_alloc_device_option(sample_graphdef, device_spec):
842848 """Device can be specified as int or Device object."""
843849 _skip_if_no_mempool ()
844850 device = Device ()
845- node = sample_graphdef .allocate (ALLOC_SIZE , device = device_spec (device ))
851+ with xfail_on_graph_mempool_oom (device ):
852+ node = sample_graphdef .allocate (ALLOC_SIZE , device = device_spec (device ))
846853 assert node .dptr != 0
847854
848855
849856def test_alloc_peer_access (mempool_device_x2 ):
850857 """AllocNode.peer_access reflects requested peers."""
851858 d0 , d1 = mempool_device_x2
852859 g = GraphDefinition ()
853- node = g .allocate (ALLOC_SIZE , device = d0 .device_id , peer_access = [d1 .device_id ])
860+ with xfail_on_graph_mempool_oom (d0 ):
861+ node = g .allocate (ALLOC_SIZE , device = d0 .device_id , peer_access = [d1 .device_id ])
854862 assert d1 .device_id in node .peer_access
855863
856864
@@ -863,8 +871,9 @@ def test_alloc_peer_access(mempool_device_x2):
863871def test_join_merges_branches (sample_graphdef , num_branches ):
864872 """join() with multiple branches creates correct dependencies."""
865873 _skip_if_no_mempool ()
866- branches = [sample_graphdef .allocate (ALLOC_SIZE ) for _ in range (num_branches )]
867- joined = sample_graphdef .join (* branches )
874+ with xfail_on_graph_mempool_oom ():
875+ branches = [sample_graphdef .allocate (ALLOC_SIZE ) for _ in range (num_branches )]
876+ joined = sample_graphdef .join (* branches )
868877 assert isinstance (joined , EmptyNode )
869878 assert set (joined .pred ) == set (branches )
870879
@@ -956,8 +965,9 @@ def test_instantiate_empty_graph(sample_graphdef, inst_kwargs):
956965def test_instantiate_with_nodes (sample_graphdef , inst_kwargs ):
957966 """Graph with nodes can be instantiated."""
958967 _skip_if_no_mempool ()
959- sample_graphdef .allocate (ALLOC_SIZE )
960- sample_graphdef .allocate (ALLOC_SIZE )
968+ with xfail_on_graph_mempool_oom ():
969+ sample_graphdef .allocate (ALLOC_SIZE )
970+ sample_graphdef .allocate (ALLOC_SIZE )
961971 graph = _instantiate (sample_graphdef , inst_kwargs )
962972 assert graph is not None
963973
@@ -997,8 +1007,9 @@ def test_instantiate_and_execute_kernel(sample_graphdef, inst_kwargs):
9971007def test_instantiate_and_execute_alloc_free (sample_graphdef , inst_kwargs ):
9981008 """Graph with alloc/free can be executed."""
9991009 _skip_if_no_mempool ()
1000- alloc = sample_graphdef .allocate (ALLOC_SIZE )
1001- alloc .deallocate (alloc .dptr )
1010+ with xfail_on_graph_mempool_oom ():
1011+ alloc = sample_graphdef .allocate (ALLOC_SIZE )
1012+ alloc .deallocate (alloc .dptr )
10021013
10031014 stream = Device ().create_stream ()
10041015 graph = _instantiate_and_upload (sample_graphdef , inst_kwargs , stream )
@@ -1010,9 +1021,10 @@ def test_instantiate_and_execute_alloc_free(sample_graphdef, inst_kwargs):
10101021def test_instantiate_and_execute_memset (sample_graphdef , inst_kwargs ):
10111022 """Graph with alloc/memset/free can be executed."""
10121023 _skip_if_no_mempool ()
1013- alloc = sample_graphdef .allocate (ALLOC_SIZE )
1014- ms = alloc .memset (alloc .dptr , 0xAB , ALLOC_SIZE )
1015- ms .deallocate (alloc .dptr )
1024+ with xfail_on_graph_mempool_oom ():
1025+ alloc = sample_graphdef .allocate (ALLOC_SIZE )
1026+ ms = alloc .memset (alloc .dptr , 0xAB , ALLOC_SIZE )
1027+ ms .deallocate (alloc .dptr )
10161028
10171029 stream = Device ().create_stream ()
10181030 graph = _instantiate_and_upload (sample_graphdef , inst_kwargs , stream )
@@ -1026,12 +1038,13 @@ def test_instantiate_and_execute_memcpy(sample_graphdef, inst_kwargs):
10261038 _skip_if_no_mempool ()
10271039 import ctypes
10281040
1029- src_alloc = sample_graphdef .allocate (ALLOC_SIZE )
1030- dst_alloc = sample_graphdef .allocate (ALLOC_SIZE )
1031- dep = sample_graphdef .join (src_alloc , dst_alloc )
1032- ms = dep .memset (src_alloc .dptr , 0xAB , ALLOC_SIZE )
1033- cp = ms .memcpy (dst_alloc .dptr , src_alloc .dptr , ALLOC_SIZE )
1034- cp .deallocate (src_alloc .dptr )
1041+ with xfail_on_graph_mempool_oom ():
1042+ src_alloc = sample_graphdef .allocate (ALLOC_SIZE )
1043+ dst_alloc = sample_graphdef .allocate (ALLOC_SIZE )
1044+ dep = sample_graphdef .join (src_alloc , dst_alloc )
1045+ ms = dep .memset (src_alloc .dptr , 0xAB , ALLOC_SIZE )
1046+ cp = ms .memcpy (dst_alloc .dptr , src_alloc .dptr , ALLOC_SIZE )
1047+ cp .deallocate (src_alloc .dptr )
10351048
10361049 stream = Device ().create_stream ()
10371050 graph = _instantiate_and_upload (sample_graphdef , inst_kwargs , stream )
@@ -1166,11 +1179,12 @@ def test_instantiate_and_execute_if_then(sample_graphdef):
11661179 set_handle = mod .get_kernel ("set_handle" )
11671180 add_one = mod .get_kernel ("add_one" )
11681181
1169- alloc = sample_graphdef .allocate (ctypes .sizeof (ctypes .c_int ))
1170- ms = alloc .memset (alloc .dptr , 0 , ctypes .sizeof (ctypes .c_int ))
1171- setter = ms .launch (LaunchConfig (grid = 1 , block = 1 ), set_handle , condition , 1 )
1172- if_node = setter .if_then (condition )
1173- if_node .then .launch (LaunchConfig (grid = 1 , block = 1 ), add_one , alloc .dptr )
1182+ with xfail_on_graph_mempool_oom ():
1183+ alloc = sample_graphdef .allocate (ctypes .sizeof (ctypes .c_int ))
1184+ ms = alloc .memset (alloc .dptr , 0 , ctypes .sizeof (ctypes .c_int ))
1185+ setter = ms .launch (LaunchConfig (grid = 1 , block = 1 ), set_handle , condition , 1 )
1186+ if_node = setter .if_then (condition )
1187+ if_node .then .launch (LaunchConfig (grid = 1 , block = 1 ), add_one , alloc .dptr )
11741188
11751189 graph = sample_graphdef .instantiate ()
11761190 stream = Device ().create_stream ()
@@ -1198,13 +1212,14 @@ def test_instantiate_and_execute_if_else(sample_graphdef):
11981212 set_handle = mod .get_kernel ("set_handle" )
11991213 add_one = mod .get_kernel ("add_one" )
12001214
1201- alloc = sample_graphdef .allocate (ctypes .sizeof (ctypes .c_int ))
1202- ms = alloc .memset (alloc .dptr , 0 , ctypes .sizeof (ctypes .c_int ))
1203- setter = ms .launch (LaunchConfig (grid = 1 , block = 1 ), set_handle , condition , 0 )
1204- ie_node = setter .if_else (condition )
1205- ie_node .then .launch (LaunchConfig (grid = 1 , block = 1 ), add_one , alloc .dptr )
1206- n1 = ie_node .else_ .launch (LaunchConfig (grid = 1 , block = 1 ), add_one , alloc .dptr )
1207- n1 .launch (LaunchConfig (grid = 1 , block = 1 ), add_one , alloc .dptr )
1215+ with xfail_on_graph_mempool_oom ():
1216+ alloc = sample_graphdef .allocate (ctypes .sizeof (ctypes .c_int ))
1217+ ms = alloc .memset (alloc .dptr , 0 , ctypes .sizeof (ctypes .c_int ))
1218+ setter = ms .launch (LaunchConfig (grid = 1 , block = 1 ), set_handle , condition , 0 )
1219+ ie_node = setter .if_else (condition )
1220+ ie_node .then .launch (LaunchConfig (grid = 1 , block = 1 ), add_one , alloc .dptr )
1221+ n1 = ie_node .else_ .launch (LaunchConfig (grid = 1 , block = 1 ), add_one , alloc .dptr )
1222+ n1 .launch (LaunchConfig (grid = 1 , block = 1 ), add_one , alloc .dptr )
12081223
12091224 graph = sample_graphdef .instantiate ()
12101225 stream = Device ().create_stream ()
@@ -1232,12 +1247,13 @@ def test_instantiate_and_execute_switch(sample_graphdef):
12321247 set_handle = mod .get_kernel ("set_handle" )
12331248 add_one = mod .get_kernel ("add_one" )
12341249
1235- alloc = sample_graphdef .allocate (ctypes .sizeof (ctypes .c_int ))
1236- ms = alloc .memset (alloc .dptr , 0 , ctypes .sizeof (ctypes .c_int ))
1237- setter = ms .launch (LaunchConfig (grid = 1 , block = 1 ), set_handle , condition , 2 )
1238- sw_node = setter .switch (condition , 4 )
1239- for branch in sw_node .branches :
1240- branch .launch (LaunchConfig (grid = 1 , block = 1 ), add_one , alloc .dptr )
1250+ with xfail_on_graph_mempool_oom ():
1251+ alloc = sample_graphdef .allocate (ctypes .sizeof (ctypes .c_int ))
1252+ ms = alloc .memset (alloc .dptr , 0 , ctypes .sizeof (ctypes .c_int ))
1253+ setter = ms .launch (LaunchConfig (grid = 1 , block = 1 ), set_handle , condition , 2 )
1254+ sw_node = setter .switch (condition , 4 )
1255+ for branch in sw_node .branches :
1256+ branch .launch (LaunchConfig (grid = 1 , block = 1 ), add_one , alloc .dptr )
12411257
12421258 graph = sample_graphdef .instantiate ()
12431259 stream = Device ().create_stream ()
@@ -1272,7 +1288,8 @@ def test_conditional_node_type_preserved_by_nodes(sample_graphdef):
12721288def test_debug_dot_print_creates_file (sample_graphdef , dot_file ):
12731289 """debug_dot_print writes a DOT file."""
12741290 _skip_if_no_mempool ()
1275- sample_graphdef .allocate (ALLOC_SIZE )
1291+ with xfail_on_graph_mempool_oom ():
1292+ sample_graphdef .allocate (ALLOC_SIZE )
12761293 sample_graphdef .debug_dot_print (str (dot_file ))
12771294 assert dot_file .exists ()
12781295 content = dot_file .read_text ()
@@ -1282,7 +1299,8 @@ def test_debug_dot_print_creates_file(sample_graphdef, dot_file):
12821299def test_debug_dot_print_with_options (sample_graphdef , dot_file ):
12831300 """debug_dot_print accepts GraphDebugPrintOptions."""
12841301 _skip_if_no_mempool ()
1285- sample_graphdef .allocate (ALLOC_SIZE )
1302+ with xfail_on_graph_mempool_oom ():
1303+ sample_graphdef .allocate (ALLOC_SIZE )
12861304 options = GraphDebugPrintOptions (verbose = True , handles = True )
12871305 sample_graphdef .debug_dot_print (str (dot_file ), options )
12881306 assert dot_file .exists ()
@@ -1291,6 +1309,7 @@ def test_debug_dot_print_with_options(sample_graphdef, dot_file):
12911309def test_debug_dot_print_invalid_options (sample_graphdef , dot_file ):
12921310 """debug_dot_print rejects invalid options type."""
12931311 _skip_if_no_mempool ()
1294- sample_graphdef .allocate (ALLOC_SIZE )
1312+ with xfail_on_graph_mempool_oom ():
1313+ sample_graphdef .allocate (ALLOC_SIZE )
12951314 with pytest .raises (TypeError , match = "options must be a GraphDebugPrintOptions" ):
12961315 sample_graphdef .debug_dot_print (str (dot_file ), "invalid" )
0 commit comments