Skip to content

Commit 2370665

Browse files
authored
CANN: Refactor evaluate_and_capture_cann_graph (ggml-org#17333)
* CANN: Refactor `evaluate_and_capture_cann_graph` **Description of the problem** * `matched_graph` is obtained even if graph mode is disabled. * End of graph capture and graph replay are unnecessarily placed in different `if` blocks. **Proposed solution** * Obtain `matched_graph` only if graph mode is enabled. * Place end of graph capture and graph reply inside the same `if` block. * Unify graph related comments. * Remove trailing whitespace
1 parent 21d31e0 commit 2370665

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

ggml/src/ggml-cann/ggml-cann.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2246,8 +2246,7 @@ static void evaluate_and_capture_cann_graph(ggml_backend_cann_context * cann_ctx
22462246
bool & use_cann_graph,
22472247
bool & cann_graph_update_required) {
22482248
#ifdef USE_ACL_GRAPH
2249-
ggml_cann_graph * matched_graph = cann_ctx->graph_lru_cache.cache_list.front();
2250-
if (use_cann_graph && cann_graph_update_required) {
2249+
if (use_cann_graph && cann_graph_update_required) { // Begin CANN graph capture
22512250
ACL_CHECK(aclmdlRICaptureBegin(cann_ctx->stream(), ACL_MODEL_RI_CAPTURE_MODE_GLOBAL));
22522251
}
22532252
#endif // USE_ACL_GRAPH
@@ -2271,12 +2270,14 @@ static void evaluate_and_capture_cann_graph(ggml_backend_cann_context * cann_ctx
22712270
}
22722271

22732272
#ifdef USE_ACL_GRAPH
2274-
if (use_cann_graph && cann_graph_update_required) { // End CANN graph capture
2275-
ACL_CHECK(aclmdlRICaptureEnd(cann_ctx->stream(), &matched_graph->graph));
2276-
}
2277-
22782273
if (use_cann_graph) {
2279-
// Execute graph
2274+
ggml_cann_graph * matched_graph = cann_ctx->graph_lru_cache.cache_list.front();
2275+
2276+
if (cann_graph_update_required) { // End CANN graph capture
2277+
ACL_CHECK(aclmdlRICaptureEnd(cann_ctx->stream(), &matched_graph->graph));
2278+
}
2279+
2280+
// Execute CANN graph
22802281
ACL_CHECK(aclmdlRIExecuteAsync(matched_graph->graph, cann_ctx->stream()));
22812282
}
22822283
#endif // USE_ACL_GRAPH

0 commit comments

Comments
 (0)