Skip to content

Commit ff764bf

Browse files
noemotiovonyuchuan-cao
authored andcommitted
CANN: fix acl_rstd allocation size in ggml_cann_rms_norm (ggml-org#15760)
Fixes ggml-org#15330 Adjust the allocation size of acl_rstd. The parameter `dims` is set to 3 according to the CANN documentation. Co-authored-by: Yuchuan <[email protected]>
1 parent e614a10 commit ff764bf

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

ggml/src/ggml-cann/aclnn_ops.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -975,18 +975,19 @@ void ggml_cann_rms_norm(ggml_backend_cann_context& ctx, ggml_tensor* dst) {
975975
);
976976

977977
// build rstd, zero...
978-
size_t acl_rstd_nb[GGML_MAX_DIMS];
978+
int64_t acl_rstd_ne[] = {src->ne[1], src->ne[2], src->ne[3]};
979+
size_t acl_rstd_nb[GGML_MAX_DIMS - 1];
979980
acl_rstd_nb[0] = sizeof(float);
980-
for (int i = 1; i < GGML_MAX_DIMS; i++) {
981-
acl_rstd_nb[i] = acl_rstd_nb[i - 1] * src->ne[i - 1];
981+
for (int i = 1; i < GGML_MAX_DIMS - 1; i++) {
982+
acl_rstd_nb[i] = acl_rstd_nb[i - 1] * acl_rstd_ne[i - 1];
982983
}
983984
aclTensor* acl_rstd = get_f32_cache_acl_tensor(
984985
ctx,
985986
&ctx.rms_norm_zero_tensor_cache.cache,
986987
ctx.rms_norm_zero_tensor_cache.size,
987-
src->ne,
988+
acl_rstd_ne,
988989
acl_rstd_nb,
989-
GGML_MAX_DIMS,
990+
GGML_MAX_DIMS - 1,
990991
0.0f // value
991992
);
992993

0 commit comments

Comments
 (0)