Skip to content

Commit c3ecf1f

Browse files
authored
hexagon: slight optimization for argosrt output init (#21463)
1 parent 487cdb1 commit c3ecf1f

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

ggml/src/ggml-hexagon/htp/argsort-ops.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ static void quicksort_values_indices_desc(float * values, int32_t * indices, int
164164
if (i < right) quicksort_values_indices_desc(values, indices, i, right);
165165
}
166166

167+
// LUT for ramp initialization of argsort output (first 32 members)
168+
int32_t argosrt_ramp_lut[32] __attribute__((aligned(VLEN))) = {
169+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
170+
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31
171+
};
172+
167173
static void htp_argsort_f32(unsigned int n, unsigned int i, void * data) {
168174
struct htp_argsort_context * actx = (struct htp_argsort_context *)data;
169175
struct htp_ops_context * octx = actx->octx;
@@ -205,8 +211,12 @@ static void htp_argsort_f32(unsigned int n, unsigned int i, void * data) {
205211
// Padded to 128 bytes.
206212

207213
size_t values_size = hex_round_up(ne00 * sizeof(float), 128);
214+
size_t num_vec_ind_values = hmx_ceil_div(ne00, VLEN/(sizeof(int32_t)));
208215
float * values_buf = (float *) spad;
209216
int32_t * indices_buf = (int32_t *) (spad + values_size);
217+
HVX_Vector * indices_buf_vec = (HVX_Vector *) (spad + values_size);
218+
const HVX_Vector ind_init_vec = *(HVX_Vector *)argosrt_ramp_lut;
219+
const HVX_Vector ind_diff_vec = Q6_V_vsplat_R(32);
210220

211221
for (uint32_t r = start_row; r < end_row; r++) {
212222
uint32_t src_offset = r * nb01;
@@ -218,9 +228,11 @@ static void htp_argsort_f32(unsigned int n, unsigned int i, void * data) {
218228
hex_l2fetch(src_ptr, ne00 * sizeof(float), ne00 * sizeof(float), 1);
219229
hvx_copy_f32_au((uint8_t*)values_buf, src_ptr, ne00);
220230

221-
// Initialize indices
222-
for (uint32_t j = 0; j < ne00; j++) {
223-
indices_buf[j] = j;
231+
// Initialize indices - Start with values 0..31, add 32 for additional vec iterations
232+
HVX_Vector curr_ind_vec = ind_init_vec;
233+
for (uint32_t j_vec = 0; j_vec < num_vec_ind_values; j_vec++) {
234+
indices_buf_vec[j_vec] = curr_ind_vec;
235+
curr_ind_vec = Q6_Vw_vadd_VwVw(curr_ind_vec, ind_diff_vec);
224236
}
225237

226238
// Sort values and mirror swaps to indices

0 commit comments

Comments
 (0)