@@ -1140,7 +1140,7 @@ struct ggml_cann_nz_workspace {
1140
1140
*/
1141
1141
void clear () {
1142
1142
if (ptr) {
1143
- aclrtFree (ptr);
1143
+ ACL_CHECK ( aclrtFree (ptr) );
1144
1144
ptr = nullptr ;
1145
1145
allocated = 0 ;
1146
1146
}
@@ -1174,25 +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
- }
1195
-
1177
+ static ggml_cann_nz_workspace g_nz_workspaces[GGML_CANN_MAX_DEVICES];
1196
1178
1197
1179
/* *
1198
1180
* @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)
1218
1200
ACL_CHECK (aclnnTransMatmulWeightGetWorkspaceSize (weightTransposed,
1219
1201
&workspaceSize, &executor));
1220
1202
// Avoid frequent malloc/free of the workspace.
1221
- get_nz_workspace ( device) .realloc (workspaceSize);
1203
+ g_nz_workspaces[ device] .realloc (workspaceSize);
1222
1204
1223
- void * g_nz_workspace = get_nz_workspace ( device) .get ();
1205
+ void * g_nz_workspace = g_nz_workspaces[ device] .get ();
1224
1206
1225
1207
ACL_CHECK (aclnnTransMatmulWeight (g_nz_workspace, workspaceSize, executor, nullptr ));
1226
1208
ACL_CHECK (aclDestroyTensor (weightTransposed));
@@ -2301,7 +2283,7 @@ static enum ggml_status ggml_backend_cann_graph_compute(
2301
2283
ggml_backend_cann_context* cann_ctx =
2302
2284
(ggml_backend_cann_context*)backend->context ;
2303
2285
ggml_cann_set_device (cann_ctx->device );
2304
- get_nz_workspace ( cann_ctx->device ) .clear ();
2286
+ g_nz_workspaces[ cann_ctx->device ] .clear ();
2305
2287
2306
2288
#ifdef USE_ACL_GRAPH
2307
2289
bool use_cann_graph = true ;
0 commit comments