Skip to content

Commit a70e4c8

Browse files
committed
CANN: merge SSM_CONV tensor shape/strides into one line
1 parent eb07456 commit a70e4c8

File tree

1 file changed

+4
-24
lines changed

1 file changed

+4
-24
lines changed

ggml/src/ggml-cann/aclnn_ops.cpp

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3523,22 +3523,12 @@ void ggml_cann_ssm_conv(ggml_backend_cann_context & ctx, ggml_tensor * dst) {
35233523
// we want a view: ne_w = { nc, 1, nr } // [K, 1, C]
35243524
// so that reversed dims -> [C, 1, K] which matches
35253525
// [out_channels, in_channels/groups, kernel_size]
3526-
int64_t w_ne[GGML_MAX_DIMS] = { 0 };
3527-
size_t w_nb[GGML_MAX_DIMS] = { 0 };
3528-
3529-
w_ne[0] = nc; // K
3530-
w_ne[1] = 1; // 1 input channel per group
3531-
w_ne[2] = nr; // C groups
3532-
w_ne[3] = 1;
3533-
3526+
int64_t w_ne[GGML_MAX_DIMS] = { nc, 1, nr, 1 }; // [K, 1 input ch. per group, C groups]
35343527
// Layout: src1 data is [K, C] with
35353528
// offset(k, c) = k*nb0 + c*nb1
35363529
// We want offset_w(k, 0, c) = k*nb0 + c*nb1,
35373530
// so we can reuse nb0 and nb1, and set nb2 = nb1.
3538-
w_nb[0] = src1->nb[0]; // sizeof(float)
3539-
w_nb[1] = src1->nb[1]; // nc * sizeof(float)
3540-
w_nb[2] = src1->nb[1]; // same stride for each (fake) "channel"
3541-
w_nb[3] = src1->nb[3];
3531+
size_t w_nb[GGML_MAX_DIMS] = { src1->nb[0], src1->nb[1], src1->nb[1], src1->nb[3] }; // same as src1
35423532

35433533
acl_tensor_ptr acl_w = ggml_cann_create_tensor(
35443534
src1->data, ggml_cann_type_mapping(src1->type), ggml_type_size(src1->type), w_ne, w_nb, 3, ACL_FORMAT_NCL);
@@ -3559,18 +3549,8 @@ void ggml_cann_ssm_conv(ggml_backend_cann_context & ctx, ggml_tensor * dst) {
35593549
// nb_y[0] = nr * sizeof(float); // step in L
35603550
// nb_y[1] = sizeof(float); // step in C
35613551
// nb_y[2] = nr * n_t * sizeof(float); // step in N
3562-
int64_t y_ne[GGML_MAX_DIMS] = { 0 };
3563-
size_t y_nb[GGML_MAX_DIMS] = { 0 };
3564-
3565-
y_ne[0] = n_t; // L_out
3566-
y_ne[1] = nr; // C
3567-
y_ne[2] = n_s; // N
3568-
y_ne[3] = 1;
3569-
3570-
y_nb[0] = dst->ne[0] * sizeof(float); // nr * sizeof(float)
3571-
y_nb[1] = sizeof(float);
3572-
y_nb[2] = dst->ne[0] * dst->ne[1] * sizeof(float); // nr * n_t * sizeof(float)
3573-
y_nb[3] = dst->nb[3];
3552+
int64_t y_ne[GGML_MAX_DIMS] = { n_t, nr, n_s, 1 }; // [L_out, C, N]
3553+
size_t y_nb[GGML_MAX_DIMS] = { dst->ne[0] * sizeof(float), sizeof(float), dst->ne[0] * dst->ne[1] * sizeof(float), dst->nb[3] }; // [nr, 1, nr * n_t]
35743554

35753555
acl_tensor_ptr acl_y = ggml_cann_create_tensor(
35763556
dst->data, ggml_cann_type_mapping(dst->type), ggml_type_size(dst->type), y_ne, y_nb, 3, ACL_FORMAT_NCL);

0 commit comments

Comments
 (0)