@@ -27,12 +27,12 @@ aclDataType type_mapping(ggml_type type) {
27
27
* Transform ggml_tensor to acl_tensor. Note that ggml_tensor dimension order
28
28
* is reversed compared to acl_tensor.
29
29
*
30
- * If bcast_ne and bcast_stride is nullptr, use ggml_tensor's ne and nb.
31
- * otherwise, use bcast_ne bcast_stride , which means tensor dims should be
30
+ * If bcast_ne and bcast_nb is nullptr, use ggml_tensor's ne and nb.
31
+ * otherwise, use bcast_ne bcast_nb , which means tensor dims should be
32
32
* changed to satisfy the broadcast. @sa: get_bcast_shape.
33
33
*/
34
34
aclTensor* create_acl_tensor (const ggml_tensor* tensor, int64_t * bcast_ne,
35
- int64_t * bcast_stride , int64_t bcast_dims) {
35
+ size_t * bcast_nb , int64_t bcast_dims, aclFormat format ) {
36
36
size_t size = ggml_nbytes (tensor);
37
37
void * deviceAddr = nullptr ;
38
38
@@ -53,13 +53,13 @@ aclTensor* create_acl_tensor(const ggml_tensor* tensor, int64_t* bcast_ne,
53
53
for (int i = 0 ; i < GGML_MAX_DIMS; i++) {
54
54
acl_ne[i] = tensor->ne [i];
55
55
// The step size of acl is in elements.
56
- acl_stride[i] = tensor->nb [i] / tensor->nb [ 0 ] ;
56
+ acl_stride[i] = tensor->nb [i] / ggml_type_size ( tensor->type ) ;
57
57
}
58
58
} else {
59
59
// With bcast
60
60
for (int i = 0 ; i < bcast_dims; i++) {
61
61
acl_ne[i] = bcast_ne[i];
62
- acl_stride[i] = bcast_stride [i] / tensor->nb [ 0 ] ;
62
+ acl_stride[i] = bcast_nb [i] / ggml_type_size ( tensor->type ) ;
63
63
}
64
64
}
65
65
@@ -69,13 +69,13 @@ aclTensor* create_acl_tensor(const ggml_tensor* tensor, int64_t* bcast_ne,
69
69
70
70
aclTensor* acl_tensor =
71
71
aclCreateTensor (acl_ne, dims, type_mapping (tensor->type ), acl_stride, 0 ,
72
- aclFormat::ACL_FORMAT_ND , acl_ne, dims, deviceAddr);
72
+ format , acl_ne, dims, deviceAddr);
73
73
74
74
return acl_tensor;
75
75
}
76
76
77
77
aclTensor* create_acl_tensor (void * data_ptr, aclDataType dtype, size_t type_size, int64_t * ne,
78
- size_t * nb, int64_t dims) {
78
+ size_t * nb, int64_t dims, aclFormat format ) {
79
79
80
80
int64_t tmp_ne[GGML_MAX_DIMS * 2 ];
81
81
int64_t tmp_stride[GGML_MAX_DIMS * 2 ];
@@ -90,7 +90,7 @@ aclTensor* create_acl_tensor(void* data_ptr, aclDataType dtype, size_t type_size
90
90
91
91
aclTensor* acl_tensor =
92
92
aclCreateTensor (tmp_ne, dims, dtype, tmp_stride, 0 ,
93
- aclFormat::ACL_FORMAT_ND , tmp_ne, dims, data_ptr);
93
+ format , tmp_ne, dims, data_ptr);
94
94
95
95
return acl_tensor;
96
96
}
@@ -132,26 +132,26 @@ aclTensor* create_acl_tensor(void* data_ptr, aclDataType dtype, size_t type_size
132
132
*/
133
133
int64_t get_bcast_shape (const ggml_tensor* src0, const ggml_tensor* src1,
134
134
int64_t * bcast_ne_src0, int64_t * bcast_ne_src1,
135
- int64_t * bcast_stride_src0 ,
136
- int64_t * bcast_stride_src1 ) {
135
+ size_t * bcast_nb_src0 ,
136
+ size_t * bcast_nb_src1 ) {
137
137
GGML_ASSERT (ggml_can_repeat (src1, src0));
138
138
int bcast_dim_cnt = 0 ;
139
139
for (int i = 0 ; i < GGML_MAX_DIMS; i++) {
140
140
int64_t nr = src0->ne [i] / src1->ne [i];
141
141
bcast_ne_src0[bcast_dim_cnt] = src0->ne [i] / nr;
142
142
bcast_ne_src1[bcast_dim_cnt] = src1->ne [i];
143
- bcast_stride_src0 [bcast_dim_cnt] = src0->nb [i];
144
- bcast_stride_src1 [bcast_dim_cnt] = src1->nb [i];
143
+ bcast_nb_src0 [bcast_dim_cnt] = src0->nb [i];
144
+ bcast_nb_src1 [bcast_dim_cnt] = src1->nb [i];
145
145
bcast_dim_cnt++;
146
146
if (nr != 1 ) {
147
147
// Need to add an extra dim.
148
148
bcast_ne_src0[bcast_dim_cnt] = nr;
149
149
bcast_ne_src1[bcast_dim_cnt] = 1 ;
150
- bcast_stride_src0 [bcast_dim_cnt] =
151
- bcast_stride_src0 [bcast_dim_cnt - 1 ] *
150
+ bcast_nb_src0 [bcast_dim_cnt] =
151
+ bcast_nb_src0 [bcast_dim_cnt - 1 ] *
152
152
bcast_ne_src0[bcast_dim_cnt - 1 ];
153
- bcast_stride_src1 [bcast_dim_cnt] =
154
- bcast_stride_src1 [bcast_dim_cnt - 1 ] *
153
+ bcast_nb_src1 [bcast_dim_cnt] =
154
+ bcast_nb_src1 [bcast_dim_cnt - 1 ] *
155
155
bcast_ne_src1[bcast_dim_cnt - 1 ];
156
156
bcast_dim_cnt++;
157
157
}
0 commit comments