Skip to content

Commit 6277fbe

Browse files
roberteg16claude
andcommitted
ggml-cuda: drop dead concurrent-region reorder path
The branch scratch buffer made the node interleaving obsolete, so the concurrent branches already run in their original graph order. The "restore original order" pass in ggml_cuda_graph_evaluate_and_capture is therefore a no-op, and the ggml_cuda_concurrent_event::original_order it consumed is now unused. Remove the reorder pass and original_order, keeping only the is_valid() check that clears the events when a region cannot be safely overlapped. Co-Authored-By: Claude Opus 4 (1M context) <noreply@anthropic.com>
1 parent df79627 commit 6277fbe

2 files changed

Lines changed: 1 addition & 68 deletions

File tree

ggml/src/ggml-cuda/common.cuh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,10 +1244,6 @@ struct ggml_cuda_concurrent_event {
12441244
int n_streams = 0;
12451245
std::unordered_map<const ggml_tensor *, int> stream_mapping;
12461246

1247-
// Original order of nodes in this concurrent region (before interleaving)
1248-
// Used to restore grouping for fusion within streams
1249-
std::vector<const ggml_tensor *> original_order;
1250-
12511247
const ggml_tensor * join_node;
12521248

12531249
ggml_cuda_concurrent_event() = default;
@@ -1270,7 +1266,6 @@ struct ggml_cuda_concurrent_event {
12701266
, fork_event(other.fork_event)
12711267
, n_streams(other.n_streams)
12721268
, stream_mapping(std::move(other.stream_mapping))
1273-
, original_order(std::move(other.original_order))
12741269
, join_node(other.join_node) {
12751270
other.fork_event = nullptr;
12761271
}

ggml/src/ggml-cuda/ggml-cuda.cu

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)