Skip to content

Commit 729af49

Browse files
committed
Rename _node_cache/_cached to _node_registry/_registered
Aligns Python-side terminology with the C++ graph_node_registry. Made-with: Cursor
1 parent a40be9a commit 729af49

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

cuda_core/cuda/core/_graph/_graph_def/_graph_node.pyx

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ from cuda.core import Device
6363
from cuda.core._graph._graph_def._adjacency_set_proxy import AdjacencySetProxy
6464
from cuda.core._utils.cuda_utils import driver, handle_return
6565

66-
_node_cache = weakref.WeakValueDictionary()
66+
_node_registry = weakref.WeakValueDictionary()
6767

6868

69-
cdef inline GraphNode _cached(GraphNode n):
70-
_node_cache[<uintptr_t>n._h_node.get()] = n
69+
cdef inline GraphNode _registered(GraphNode n):
70+
_node_registry[<uintptr_t>n._h_node.get()] = n
7171
return n
7272

7373

@@ -153,7 +153,7 @@ cdef class GraphNode:
153153
return
154154
with nogil:
155155
HANDLE_RETURN(cydriver.cuGraphDestroyNode(node))
156-
_node_cache.pop(<uintptr_t>self._h_node.get(), None)
156+
_node_registry.pop(<uintptr_t>self._h_node.get(), None)
157157
invalidate_graph_node_handle(self._h_node)
158158

159159
@property
@@ -532,7 +532,7 @@ cdef inline ConditionalNode _make_conditional_node(
532532
n._cond_type = cond_type
533533
n._branches = branches
534534

535-
return _cached(n)
535+
return _registered(n)
536536

537537
cdef inline GraphNode GN_create(GraphHandle h_graph, cydriver.CUgraphNode node):
538538
cdef GraphNodeHandle h_node = create_graph_node_handle(node, h_graph)
@@ -543,12 +543,12 @@ cdef inline GraphNode GN_create(GraphHandle h_graph, cydriver.CUgraphNode node):
543543
(<GraphNode>n)._h_node = h_node
544544
return n
545545

546-
# Return a cached object or create and cache a new one.
547-
cached = _node_cache.get(<uintptr_t>h_node.get())
548-
if cached is not None:
549-
return <GraphNode>cached
546+
# Return a registered object or create and register a new one.
547+
registered = _node_registry.get(<uintptr_t>h_node.get())
548+
if registered is not None:
549+
return <GraphNode>registered
550550
else:
551-
return _cached(GN_create_impl(h_node))
551+
return _registered(GN_create_impl(h_node))
552552

553553

554554
cdef inline GraphNode GN_create_impl(GraphNodeHandle h_node):
@@ -616,7 +616,7 @@ cdef inline KernelNode GN_launch(GraphNode self, LaunchConfig conf, Kernel ker,
616616
_attach_user_object(as_cu(h_graph), <void*>new KernelHandle(ker._h_kernel),
617617
<cydriver.CUhostFn>_destroy_kernel_handle_copy)
618618

619-
return _cached(KernelNode._create_with_params(
619+
return _registered(KernelNode._create_with_params(
620620
create_graph_node_handle(new_node, h_graph),
621621
conf.grid, conf.block, conf.shmem_size,
622622
ker._h_kernel))
@@ -645,7 +645,7 @@ cdef inline EmptyNode GN_join(GraphNode self, tuple nodes):
645645
HANDLE_RETURN(cydriver.cuGraphAddEmptyNode(
646646
&new_node, as_cu(h_graph), deps_ptr, num_deps))
647647

648-
return _cached(EmptyNode._create_impl(create_graph_node_handle(new_node, h_graph)))
648+
return _registered(EmptyNode._create_impl(create_graph_node_handle(new_node, h_graph)))
649649

650650

651651
cdef inline AllocNode GN_alloc(GraphNode self, size_t size, object options):
@@ -721,7 +721,7 @@ cdef inline AllocNode GN_alloc(GraphNode self, size_t size, object options):
721721
HANDLE_RETURN(cydriver.cuGraphAddMemAllocNode(
722722
&new_node, as_cu(h_graph), deps, num_deps, &alloc_params))
723723

724-
return _cached(AllocNode._create_with_params(
724+
return _registered(AllocNode._create_with_params(
725725
create_graph_node_handle(new_node, h_graph), alloc_params.dptr, size,
726726
device_id, memory_type, tuple(peer_ids)))
727727

@@ -741,7 +741,7 @@ cdef inline FreeNode GN_free(GraphNode self, cydriver.CUdeviceptr c_dptr):
741741
HANDLE_RETURN(cydriver.cuGraphAddMemFreeNode(
742742
&new_node, as_cu(h_graph), deps, num_deps, c_dptr))
743743

744-
return _cached(FreeNode._create_with_params(create_graph_node_handle(new_node, h_graph), c_dptr))
744+
return _registered(FreeNode._create_with_params(create_graph_node_handle(new_node, h_graph), c_dptr))
745745

746746

747747
cdef inline MemsetNode GN_memset(
@@ -776,7 +776,7 @@ cdef inline MemsetNode GN_memset(
776776
&new_node, as_cu(h_graph), deps, num_deps,
777777
&memset_params, ctx))
778778

779-
return _cached(MemsetNode._create_with_params(
779+
return _registered(MemsetNode._create_with_params(
780780
create_graph_node_handle(new_node, h_graph), c_dst,
781781
val, elem_size, width, height, pitch))
782782

@@ -837,7 +837,7 @@ cdef inline MemcpyNode GN_memcpy(
837837
HANDLE_RETURN(cydriver.cuGraphAddMemcpyNode(
838838
&new_node, as_cu(h_graph), deps, num_deps, &params, ctx))
839839

840-
return _cached(MemcpyNode._create_with_params(
840+
return _registered(MemcpyNode._create_with_params(
841841
create_graph_node_handle(new_node, h_graph), c_dst, c_src, size,
842842
c_dst_type, c_src_type))
843843

@@ -864,7 +864,7 @@ cdef inline ChildGraphNode GN_embed(GraphNode self, GraphDef child_def):
864864

865865
cdef GraphHandle h_embedded = create_graph_handle_ref(embedded_graph, h_graph)
866866

867-
return _cached(ChildGraphNode._create_with_params(
867+
return _registered(ChildGraphNode._create_with_params(
868868
create_graph_node_handle(new_node, h_graph), h_embedded))
869869

870870

@@ -886,7 +886,7 @@ cdef inline EventRecordNode GN_record_event(GraphNode self, Event ev):
886886
_attach_user_object(as_cu(h_graph), <void*>new EventHandle(ev._h_event),
887887
<cydriver.CUhostFn>_destroy_event_handle_copy)
888888

889-
return _cached(EventRecordNode._create_with_params(
889+
return _registered(EventRecordNode._create_with_params(
890890
create_graph_node_handle(new_node, h_graph), ev._h_event))
891891

892892

@@ -908,7 +908,7 @@ cdef inline EventWaitNode GN_wait_event(GraphNode self, Event ev):
908908
_attach_user_object(as_cu(h_graph), <void*>new EventHandle(ev._h_event),
909909
<cydriver.CUhostFn>_destroy_event_handle_copy)
910910

911-
return _cached(EventWaitNode._create_with_params(
911+
return _registered(EventWaitNode._create_with_params(
912912
create_graph_node_handle(new_node, h_graph), ev._h_event))
913913

914914

@@ -935,6 +935,6 @@ cdef inline HostCallbackNode GN_callback(GraphNode self, object fn, object user_
935935
&new_node, as_cu(h_graph), deps, num_deps, &node_params))
936936

937937
cdef object callable_obj = fn if not isinstance(fn, ct._CFuncPtr) else None
938-
return _cached(HostCallbackNode._create_with_params(
938+
return _registered(HostCallbackNode._create_with_params(
939939
create_graph_node_handle(new_node, h_graph), callable_obj,
940940
node_params.fn, node_params.userData))

0 commit comments

Comments
 (0)