@@ -4287,58 +4287,7 @@ static void ggml_cuda_graph_evaluate_and_capture(ggml_backend_cuda_context * cud
42874287 }
42884288 }
42894289
4290- if (should_launch_concurrent_events) {
4291- // Restore original node order within each concurrent region to enable fusion within streams
4292-
4293- std::unordered_map<const ggml_tensor *, int > node_to_idx;
4294- node_to_idx.reserve (cgraph->n_nodes );
4295- for (int i = 0 ; i < cgraph->n_nodes ; ++i) {
4296- node_to_idx[cgraph->nodes [i]] = i;
4297- }
4298-
4299- for (auto & [fork_node, event] : stream_ctx.concurrent_events ) {
4300- // Find positions of all nodes from this event in the current graph
4301- std::vector<int > positions;
4302- positions.reserve (event.original_order .size ());
4303-
4304- bool all_found = true ;
4305- for (const ggml_tensor * orig_node : event.original_order ) {
4306- auto it = node_to_idx.find (orig_node);
4307- if (it != node_to_idx.end ()) {
4308- positions.push_back (it->second );
4309- } else {
4310- all_found = false ;
4311- break ;
4312- }
4313- }
4314-
4315- if (!all_found || positions.size () != event.original_order .size ()) {
4316- continue ;
4317- }
4318-
4319- // Sort positions to get contiguous range
4320- std::vector<int > sorted_positions = positions;
4321- std::sort (sorted_positions.begin (), sorted_positions.end ());
4322-
4323- bool is_contiguous = true ;
4324- for (size_t i = 1 ; i < sorted_positions.size (); ++i) {
4325- if (sorted_positions[i] != sorted_positions[i-1 ] + 1 ) {
4326- is_contiguous = false ;
4327- break ;
4328- }
4329- }
4330-
4331- if (!is_contiguous) {
4332- continue ;
4333- }
4334-
4335- // Restore original order at the sorted positions
4336- int start_pos = sorted_positions[0 ];
4337- for (size_t i = 0 ; i < event.original_order .size (); ++i) {
4338- cgraph->nodes [start_pos + i] = const_cast <ggml_tensor *>(event.original_order [i]);
4339- }
4340- }
4341- } else {
4290+ if (!should_launch_concurrent_events) {
43424291 stream_ctx.concurrent_events .clear ();
43434292 }
43444293
@@ -4758,13 +4707,6 @@ static void ggml_backend_cuda_graph_optimize(ggml_backend_t backend, ggml_cgraph
47584707 continue ;
47594708 }
47604709
4761- // Save the original order of nodes in this region before interleaving
4762- // This is used later to restore grouping for fusion within streams
4763- concurrent_event.original_order .reserve (total_branch_nodes);
4764- for (int i = fork_node_idx + 1 ; i < join_node_idx; ++i) {
4765- concurrent_event.original_order .push_back (cgraph->nodes [i]);
4766- }
4767-
47684710 std::unordered_map<const ggml_tensor *, ggml_cuda_concurrent_event> & concurrent_events = cuda_ctx->stream_context ().concurrent_events ;
47694711 GGML_ASSERT (concurrent_events.find (root_node) == concurrent_events.end ());
47704712 concurrent_events.emplace (root_node, std::move (concurrent_event));
@@ -4885,10 +4827,6 @@ static void ggml_backend_cuda_graph_optimize(ggml_backend_t backend, ggml_cgraph
48854827 }
48864828
48874829 const ggml_tensor * fork_node = cgraph->nodes [fork_idx];
4888- concurrent_event.original_order .reserve (join_idx - fork_idx - 1 );
4889- for (int i = fork_idx + 1 ; i < join_idx; ++i) {
4890- concurrent_event.original_order .push_back (cgraph->nodes [i]);
4891- }
48924830
48934831 std::unordered_map<const ggml_tensor *, ggml_cuda_concurrent_event> & concurrent_events = cuda_ctx->stream_context ().concurrent_events ;
48944832 if (concurrent_events.find (fork_node) != concurrent_events.end ()) {
0 commit comments