@@ -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) {
@@ -393,6 +388,7 @@ ContextHandle get_event_context(const EventHandle& h) noexcept {
393388 return h ? get_box (h)->h_context : ContextHandle{};
394389}
395390
391+ // See REGISTRY_DESIGN.md (Level 1: Driver Handle -> Resource Handle)
396392static HandleRegistry<CUevent, EventHandle> event_registry;
397393
398394EventHandle create_event_handle (const ContextHandle& h_ctx, unsigned int flags,
@@ -899,6 +895,7 @@ static const KernelBox* get_box(const KernelHandle& h) {
899895 );
900896}
901897
898+ // See REGISTRY_DESIGN.md (Level 1: Driver Handle -> Resource Handle)
902899static HandleRegistry<CUkernel, KernelHandle> kernel_registry;
903900
904901KernelHandle create_kernel_handle (const LibraryHandle& h_library, const char * name) {
@@ -957,7 +954,7 @@ GraphHandle create_graph_handle_ref(CUgraph graph, const GraphHandle& h_parent)
957954
958955namespace {
959956struct GraphNodeBox {
960- CUgraphNode resource;
957+ mutable CUgraphNode resource;
961958 GraphHandle h_graph;
962959};
963960} // namespace
@@ -969,15 +966,37 @@ static const GraphNodeBox* get_box(const GraphNodeHandle& h) {
969966 );
970967}
971968
969+ // See REGISTRY_DESIGN.md (Level 1: Driver Handle -> Resource Handle)
970+ static HandleRegistry<CUgraphNode, GraphNodeHandle> graph_node_registry;
971+
972972GraphNodeHandle create_graph_node_handle (CUgraphNode node, const GraphHandle& h_graph) {
973+ if (node) {
974+ if (auto h = graph_node_registry.lookup (node)) {
975+ return h;
976+ }
977+ }
973978 auto box = std::make_shared<const GraphNodeBox>(GraphNodeBox{node, h_graph});
974- return GraphNodeHandle (box, &box->resource );
979+ GraphNodeHandle h (box, &box->resource );
980+ if (node) {
981+ graph_node_registry.register_handle (node, h);
982+ }
983+ return h;
975984}
976985
977986GraphHandle graph_node_get_graph (const GraphNodeHandle& h) noexcept {
978987 return h ? get_box (h)->h_graph : GraphHandle{};
979988}
980989
990+ void invalidate_graph_node (const GraphNodeHandle& h) noexcept {
991+ if (h) {
992+ CUgraphNode node = get_box (h)->resource ;
993+ if (node) {
994+ graph_node_registry.unregister_handle (node);
995+ }
996+ get_box (h)->resource = nullptr ;
997+ }
998+ }
999+
9811000// ============================================================================
9821001// Graphics Resource Handles
9831002// ============================================================================
0 commit comments