Skip to content

Commit cbf22a0

Browse files
committed
fix review comment
Signed-off-by: noemotiovon <757486878@qq.com>
1 parent 600ef99 commit cbf22a0

File tree

1 file changed

+4
-21
lines changed

1 file changed

+4
-21
lines changed

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

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,24 +1174,7 @@ struct ggml_cann_nz_workspace {
11741174
/**
11751175
* @brief Global array of NZ workspaces, one per device.
11761176
*/
1177-
static std::array<ggml_cann_nz_workspace, GGML_CANN_MAX_DEVICES> g_nz_workspaces;
1178-
1179-
/**
1180-
* @brief Get the NZ workspace for a specific device.
1181-
*
1182-
* This function returns a reference to the workspace corresponding to the
1183-
* given device index.
1184-
*
1185-
* @param device Device index (0-based). Must be less than GGML_CANN_MAX_DEVICES.
1186-
* @return Reference to the device's NZ workspace.
1187-
* @throws std::out_of_range if device index is invalid.
1188-
*/
1189-
inline ggml_cann_nz_workspace& get_nz_workspace(int device) {
1190-
if (device < 0 || device >= static_cast<int>(g_nz_workspaces.size())) {
1191-
throw std::out_of_range("device id out of range");
1192-
}
1193-
return g_nz_workspaces[device];
1194-
}
1177+
static ggml_cann_nz_workspace g_nz_workspaces[GGML_CANN_MAX_DEVICES];
11951178

11961179

11971180
/**
@@ -1218,9 +1201,9 @@ static void weight_format_to_nz(ggml_tensor *tensor, size_t offset, int device)
12181201
ACL_CHECK(aclnnTransMatmulWeightGetWorkspaceSize(weightTransposed,
12191202
&workspaceSize, &executor));
12201203
// Avoid frequent malloc/free of the workspace.
1221-
get_nz_workspace(device).realloc(workspaceSize);
1204+
g_nz_workspaces[device].realloc(workspaceSize);
12221205

1223-
void* g_nz_workspace = get_nz_workspace(device).get();
1206+
void* g_nz_workspace = g_nz_workspaces[device].get();
12241207

12251208
ACL_CHECK(aclnnTransMatmulWeight(g_nz_workspace, workspaceSize, executor, nullptr));
12261209
ACL_CHECK(aclDestroyTensor(weightTransposed));
@@ -2301,7 +2284,7 @@ static enum ggml_status ggml_backend_cann_graph_compute(
23012284
ggml_backend_cann_context* cann_ctx =
23022285
(ggml_backend_cann_context*)backend->context;
23032286
ggml_cann_set_device(cann_ctx->device);
2304-
get_nz_workspace(cann_ctx->device).clear();
2287+
g_nz_workspaces[cann_ctx->device].clear();
23052288

23062289
#ifdef USE_ACL_GRAPH
23072290
bool use_cann_graph = true;

0 commit comments

Comments
 (0)