Skip to content

Commit 42131b6

Browse files
committed
Fix unregister_handle and rename invalidate_graph_node_handle
unregister_handle: remove the expired() guard that prevented erasure when the shared_ptr was still alive. This caused stale registry entries after destroy(), leading to CUDA_ERROR_INVALID_VALUE when the driver reused CUgraphNode pointer values. Rename invalidate_graph_node_handle -> invalidate_graph_node for consistency with the rest of the graph node API. Made-with: Cursor
1 parent 729af49 commit 42131b6

File tree

5 files changed

+8
-13
lines changed

5 files changed

+8
-13
lines changed

cuda_core/cuda/core/_cpp/resource_handles.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,8 @@ class HandleRegistry {
174174
}
175175

176176
void unregister_handle(const Key& key) noexcept {
177-
try {
178-
std::lock_guard<std::mutex> lock(mutex_);
179-
auto it = map_.find(key);
180-
if (it != map_.end() && it->second.expired()) {
181-
map_.erase(it);
182-
}
183-
} catch (...) {}
177+
std::lock_guard<std::mutex> lock(mutex_);
178+
map_.erase(key);
184179
}
185180

186181
Handle lookup(const Key& key) {
@@ -989,7 +984,7 @@ GraphHandle graph_node_get_graph(const GraphNodeHandle& h) noexcept {
989984
return h ? get_box(h)->h_graph : GraphHandle{};
990985
}
991986

992-
void invalidate_graph_node_handle(const GraphNodeHandle& h) noexcept {
987+
void invalidate_graph_node(const GraphNodeHandle& h) noexcept {
993988
if (h) {
994989
CUgraphNode node = get_box(h)->resource;
995990
if (node) {

cuda_core/cuda/core/_cpp/resource_handles.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ GraphNodeHandle create_graph_node_handle(CUgraphNode node, const GraphHandle& h_
416416
GraphHandle graph_node_get_graph(const GraphNodeHandle& h) noexcept;
417417

418418
// Zero the CUgraphNode resource inside the handle, marking it invalid.
419-
void invalidate_graph_node_handle(const GraphNodeHandle& h) noexcept;
419+
void invalidate_graph_node(const GraphNodeHandle& h) noexcept;
420420

421421
// ============================================================================
422422
// Graphics resource handle functions

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ from cuda.core._resource_handles cimport (
4848
create_graph_handle_ref,
4949
create_graph_node_handle,
5050
graph_node_get_graph,
51-
invalidate_graph_node_handle,
51+
invalidate_graph_node,
5252
)
5353
from cuda.core._utils.cuda_utils cimport HANDLE_RETURN, _parse_fill_value
5454

@@ -154,7 +154,7 @@ cdef class GraphNode:
154154
with nogil:
155155
HANDLE_RETURN(cydriver.cuGraphDestroyNode(node))
156156
_node_registry.pop(<uintptr_t>self._h_node.get(), None)
157-
invalidate_graph_node_handle(self._h_node)
157+
invalidate_graph_node(self._h_node)
158158

159159
@property
160160
def pred(self):

cuda_core/cuda/core/_resource_handles.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ cdef GraphHandle create_graph_handle_ref(cydriver.CUgraph graph, const GraphHand
186186
# Graph node handles
187187
cdef GraphNodeHandle create_graph_node_handle(cydriver.CUgraphNode node, const GraphHandle& h_graph) except+ nogil
188188
cdef GraphHandle graph_node_get_graph(const GraphNodeHandle& h) noexcept nogil
189-
cdef void invalidate_graph_node_handle(const GraphNodeHandle& h) noexcept nogil
189+
cdef void invalidate_graph_node(const GraphNodeHandle& h) noexcept nogil
190190

191191
# Graphics resource handles
192192
cdef GraphicsResourceHandle create_graphics_resource_handle(

cuda_core/cuda/core/_resource_handles.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ cdef extern from "_cpp/resource_handles.hpp" namespace "cuda_core":
159159
cydriver.CUgraphNode node, const GraphHandle& h_graph) except+ nogil
160160
GraphHandle graph_node_get_graph "cuda_core::graph_node_get_graph" (
161161
const GraphNodeHandle& h) noexcept nogil
162-
void invalidate_graph_node_handle "cuda_core::invalidate_graph_node_handle" (
162+
void invalidate_graph_node "cuda_core::invalidate_graph_node" (
163163
const GraphNodeHandle& h) noexcept nogil
164164

165165
# Graphics resource handles

0 commit comments

Comments
 (0)