@@ -1140,7 +1140,7 @@ struct ggml_cann_nz_workspace {
11401140 */
11411141 void clear () {
11421142 if (ptr) {
1143- aclrtFree (ptr);
1143+ ACL_CHECK ( aclrtFree (ptr) );
11441144 ptr = nullptr ;
11451145 allocated = 0 ;
11461146 }
@@ -1174,25 +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- }
1195-
1177+ static ggml_cann_nz_workspace g_nz_workspaces[GGML_CANN_MAX_DEVICES];
11961178
11971179/* *
11981180 * @brief Convert tensor weights to NZ format using Ascend CANN API.
@@ -1218,9 +1200,9 @@ static void weight_format_to_nz(ggml_tensor *tensor, size_t offset, int device)
12181200 ACL_CHECK (aclnnTransMatmulWeightGetWorkspaceSize (weightTransposed,
12191201 &workspaceSize, &executor));
12201202 // Avoid frequent malloc/free of the workspace.
1221- get_nz_workspace ( device) .realloc (workspaceSize);
1203+ g_nz_workspaces[ device] .realloc (workspaceSize);
12221204
1223- void * g_nz_workspace = get_nz_workspace ( device) .get ();
1205+ void * g_nz_workspace = g_nz_workspaces[ device] .get ();
12241206
12251207 ACL_CHECK (aclnnTransMatmulWeight (g_nz_workspace, workspaceSize, executor, nullptr ));
12261208 ACL_CHECK (aclDestroyTensor (weightTransposed));
@@ -2301,7 +2283,7 @@ static enum ggml_status ggml_backend_cann_graph_compute(
23012283 ggml_backend_cann_context* cann_ctx =
23022284 (ggml_backend_cann_context*)backend->context ;
23032285 ggml_cann_set_device (cann_ctx->device );
2304- get_nz_workspace ( cann_ctx->device ) .clear ();
2286+ g_nz_workspaces[ cann_ctx->device ] .clear ();
23052287
23062288#ifdef USE_ACL_GRAPH
23072289 bool use_cann_graph = true ;
0 commit comments