1414import pytest
1515from helpers .graph_kernels import compile_common_kernels
1616
17- from cuda .core import Device , LaunchConfig , LegacyPinnedMemoryResource
17+ from cuda .core import Device , DeviceMemoryResource , LaunchConfig , LegacyPinnedMemoryResource
18+ from cuda .core ._memory ._synchronous_memory_resource import _SynchronousMemoryResource
1819from cuda .core ._utils ._weak_handles import weak_handle
1920from cuda .core ._utils .cuda_utils import CUDAError , driver , handle_return
2021from cuda .core ._utils .version import driver_version
@@ -745,15 +746,18 @@ def test_memcpy_update_between_host_and_device(init_cuda, device_operand):
745746 assert list (host_dst_bytes ) == [0x5A ] * 4
746747
747748
748- def _capture_device_memcpy (device , stream , size = 64 ):
749+ def _capture_device_memcpy (device , stream , size = 64 , mr = None ):
749750 """Capture ``dst.copy_from(src)`` between two device buffers.
750751
752+ The buffers come from ``mr``, by default the device's memory resource.
751753 The driver records both operands of a captured ``cuMemcpyAsync`` as
752754 unified addresses rather than as device memory (#2649). The builder is
753755 returned so that the captured graph stays alive with the definition view.
754756 """
755- src = device .memory_resource .allocate (size , stream = stream )
756- dst = device .memory_resource .allocate (size , stream = stream )
757+ if mr is None :
758+ mr = device .memory_resource
759+ src = mr .allocate (size , stream = stream )
760+ dst = mr .allocate (size , stream = stream )
757761 src .fill (0x5A , stream = stream )
758762 dst .fill (0 , stream = stream )
759763 stream .sync ()
@@ -882,25 +886,33 @@ def test_executable_memcpy_update_on_captured_node(init_cuda):
882886
883887
884888@pytest .mark .agent_authored (model = "claude-fable-5-1" )
885- def test_memcpy_update_captured_node_host_operand (init_cuda ):
889+ @pytest .mark .parametrize ("kind" , ["pool" , "cumemalloc" ])
890+ def test_memcpy_update_captured_node_host_operand (init_cuda , kind ):
886891 """Replacing a captured node's device operand with host memory.
887892
888893 The definition node accepts the host buffer and a fresh instantiation
889894 copies from it. Whether an executable update accepts the replacement
890- depends on how the operands were allocated: the driver compares the
895+ depends on how the operands were allocated. The driver compares the
891896 memory class of pool-backed and virtual-memory operands and rejects the
892- change for them, while plain ``cuMemAlloc`` operands accept it. A device
893- without memory-pool support (Windows TCC in CI) gets a default memory
894- resource that is not pool-backed, so the same test is accepted there.
895- The test allows either outcome and checks the copy when the update is
896- accepted. cuda.core enforces nothing here.
897+ change for them, so the pool-backed case expects the rejection. Plain
898+ ``cuMemAlloc`` operands skip that comparison and the driver may accept
899+ the change, so that case allows either outcome and checks the copy when
900+ the update is accepted. A device without memory-pool support (Windows
901+ TCC in CI) runs only the ``cuMemAlloc`` case. cuda.core enforces nothing
902+ here.
897903 """
898904 if driver_version () < (12 , 2 , 0 ):
899905 pytest .skip ("individual graph node updates require CUDA 12.2+" )
906+ if kind == "pool" :
907+ if not init_cuda .properties .memory_pools_supported :
908+ pytest .skip ("Device does not support mempool operations" )
909+ mr = DeviceMemoryResource (init_cuda )
910+ else :
911+ mr = _SynchronousMemoryResource (init_cuda .device_id )
900912
901913 stream = init_cuda .create_stream ()
902914 # The builder is unused; it keeps the captured graph alive.
903- builder , graph_def , node , dst , src = _capture_device_memcpy (init_cuda , stream )
915+ builder , graph_def , node , dst , src = _capture_device_memcpy (init_cuda , stream , mr = mr )
904916 instantiated_before = graph_def .instantiate ()
905917 host_src = LegacyPinnedMemoryResource ().allocate (64 )
906918 ctypes .memset (int (host_src .handle ), 0xA5 , 64 )
@@ -925,12 +937,18 @@ def _cuda_error_from(call):
925937 return exc
926938 return None
927939
928- rejected = _cuda_error_from ( lambda : instantiated_before . update ( graph_def ))
929- if rejected is None :
930- _launch_copies_host_source ( instantiated_before )
940+ if kind == "pool" :
941+ with pytest . raises ( CUDAError , match = "PARAMETERS_CHANGED" ) :
942+ instantiated_before . update ( graph_def )
931943 else :
932- assert "PARAMETERS_CHANGED" in str (rejected )
944+ rejected = _cuda_error_from (lambda : instantiated_before .update (graph_def ))
945+ if rejected is None :
946+ _launch_copies_host_source (instantiated_before )
947+ else :
948+ assert "PARAMETERS_CHANGED" in str (rejected )
933949
950+ # The executable-view update varies by driver for both kinds: the CI
951+ # drivers accept it, others reject it. Either outcome is allowed.
934952 other = graph_def .instantiate ()
935953 rejected = _cuda_error_from (lambda : other [node ].update (dst = dst , src = host_src , size = 64 ))
936954 if rejected is None :
0 commit comments