@@ -1174,24 +1174,7 @@ struct ggml_cann_nz_workspace {
1174
1174
/* *
1175
1175
* @brief Global array of NZ workspaces, one per device.
1176
1176
*/
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];
1195
1178
1196
1179
1197
1180
/* *
@@ -1218,9 +1201,9 @@ static void weight_format_to_nz(ggml_tensor *tensor, size_t offset, int device)
1218
1201
ACL_CHECK (aclnnTransMatmulWeightGetWorkspaceSize (weightTransposed,
1219
1202
&workspaceSize, &executor));
1220
1203
// Avoid frequent malloc/free of the workspace.
1221
- get_nz_workspace ( device) .realloc (workspaceSize);
1204
+ g_nz_workspaces[ device] .realloc (workspaceSize);
1222
1205
1223
- void * g_nz_workspace = get_nz_workspace ( device) .get ();
1206
+ void * g_nz_workspace = g_nz_workspaces[ device] .get ();
1224
1207
1225
1208
ACL_CHECK (aclnnTransMatmulWeight (g_nz_workspace, workspaceSize, executor, nullptr ));
1226
1209
ACL_CHECK (aclDestroyTensor (weightTransposed));
@@ -2301,7 +2284,7 @@ static enum ggml_status ggml_backend_cann_graph_compute(
2301
2284
ggml_backend_cann_context* cann_ctx =
2302
2285
(ggml_backend_cann_context*)backend->context ;
2303
2286
ggml_cann_set_device (cann_ctx->device );
2304
- get_nz_workspace ( cann_ctx->device ) .clear ();
2287
+ g_nz_workspaces[ cann_ctx->device ] .clear ();
2305
2288
2306
2289
#ifdef USE_ACL_GRAPH
2307
2290
bool use_cann_graph = true ;
0 commit comments