Skip to content
Draft
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
407b408
fix test failure
chraac Nov 27, 2025
4ddb8a4
fix: correct scaling calculations in rope_cache_init
chraac Nov 27, 2025
cfca78b
wip
chraac Nov 27, 2025
e9a02fd
wip
chraac Nov 28, 2025
e324bb0
fix: optimize element copying in rope_hex_f32 using memcpy
chraac Nov 28, 2025
0121291
fix: optimize loop boundaries in rope_hex_f32 for better performance
chraac Nov 28, 2025
010039a
rename
chraac Nov 28, 2025
a6ef41f
wip
chraac Nov 28, 2025
0376146
Merge branch 'master' into dev-fix-rope
chraac Nov 28, 2025
8abecfa
Merge tag 'b7207' into dev-fix-rope
chraac Nov 30, 2025
b567413
feat: add profiling macros for performance measurement in operations
chraac Nov 30, 2025
7c8f101
refactor: replace manual timing with profiling macros in matmul opera…
chraac Dec 3, 2025
3a70465
Merge branch 'master' into dev-fix-rope
chraac Dec 4, 2025
3b0cef4
Revert "refactor: replace manual timing with profiling macros in matm…
chraac Dec 5, 2025
121e656
Revert "feat: add profiling macros for performance measurement in ope…
chraac Dec 5, 2025
401fd3e
refactor: optimize vector operations in vec_dot_q4x4x2_q8x4x2_rx2 fun…
chraac Dec 5, 2025
cf491f2
wip
chraac Dec 5, 2025
3a01d82
feat: enhance vec_dot_q4x4x2_q8x4x2_rx2 function with optimized data …
chraac Dec 7, 2025
87ad8b2
Merge branch 'master' into dev-mulmat-opt
chraac Dec 8, 2025
421d031
feat: add hvx_vec_load_d_and_mpy function for optimized data loading …
chraac Dec 8, 2025
bd43860
wip
chraac Dec 8, 2025
b197464
feat: add hvx_vec_load_d_and_mpy_r2x2 function for optimized vector l…
chraac Dec 8, 2025
309d782
feat: optimize vec_dot functions with improved data handling and loading
chraac Dec 8, 2025
dbe9309
wip
chraac Dec 9, 2025
00d5fb3
feat: add build information and update vector loading functions for o…
chraac Dec 9, 2025
b54ff18
revert rope changes
chraac Dec 10, 2025
f757245
Merge tag 'b7345' into dev-mulmat-opt
chraac Dec 10, 2025
09c4899
fix: revert HVX_Vector back to HVX_UVector
chraac Dec 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
wip
  • Loading branch information
chraac committed Dec 9, 2025
commit dbe93098513c212c6d48a89f12b4105fcd84f84c
32 changes: 16 additions & 16 deletions ggml/src/ggml-hexagon/htp/matmul-ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ static void vec_dot_q4x4x2_q8x4x2_rx2(const int n,
const HVX_VectorPred rd_mask = Q6_Q_vsetq_R(VLEN / 2);
r1_x_d -= VLEN / 2; // make sure r1 at the high half of the vector

for (; i < nb; i++) {
if (i < nb) {
HVX_Vector_x8 vy_q = hvx_vec_load_q8x4x8(y_q + i * y_qblk_size);
HVX_Vector_x8 r0_q = hvx_vec_load_q4x4x8(r0_x_q + i * x_qblk_size);
HVX_Vector_x8 r1_q = hvx_vec_load_q4x4x8(r1_x_q + i * x_qblk_size);
Expand All @@ -524,6 +524,7 @@ static void vec_dot_q4x4x2_q8x4x2_rx2(const int n,

r0_sum = Q6_Vqf32_vadd_Vqf32Vqf32(r0_sum, r0_fa);
r1_sum = Q6_Vqf32_vadd_Vqf32Vqf32(r1_sum, r1_fa);
i++;
}

// Process leftovers, we still load full 4x4x2 block but zero out unused scales/blocks
Expand Down Expand Up @@ -757,8 +758,12 @@ static void vec_dot_mxfp4x4x2_q8x4x2(const int n,
// Compute combined scale (fp32).
// Apply scale to acc and accumulate into the row sum (qf32).

const uint32_t nb = n / qk; // num full blocks
int32_t nloe = n % qk; // num leftover elemements (must be signed)
const uint32_t nb = n / qk; // num full blocks
int32_t nloe = n % qk; // num leftover elemements (must be signed)

const HVX_Vector half = Q6_Vh_vsplat_R(0x3800); // 0.5 in fp16
const HVX_Vector expand = *(const HVX_Vector *) expand_x32_e8m0;
const HVX_Vector e8m0_mask = Q6_V_vsplat_R(0x000000ff);

uint32_t i = 0;
for (; i < nb; i++) {
Expand All @@ -771,19 +776,16 @@ static void vec_dot_mxfp4x4x2_q8x4x2(const int n,
HVX_Vector r0_d = *(const HVX_UVector *) (r0_x_d + i * x_dblk_size);

// Convert vy_d from fp16 to fp32 while applying 0.5 scaling which is used for e8m0 halving
HVX_Vector half = Q6_Vh_vsplat_R(0x3800); // 0.5 in fp16
vy_d = Q6_V_lo_W(Q6_Wqf32_vmpy_VhfVhf(Q6_Vh_vshuff_Vh(vy_d), half));
vy_d = Q6_Vsf_equals_Vqf32(vy_d);
vy_d = Q6_V_lo_W(Q6_Wqf32_vmpy_VhfVhf(Q6_Vh_vshuff_Vh(vy_d), half));
vy_d = Q6_Vsf_equals_Vqf32(vy_d);

// Convert rX_d scales from e8m0 to fp32
// Expand and zero-pad 32x uint8 e8m0 values to uint32s : 0 0 0 0, 0 0 0 1, 0 0 0 2, ...
// Left shift with zero fill to create FP32
// FIXME: might need to handle zero as a special case (see ggml-cpu code)
HVX_Vector expand = *(const HVX_Vector *) expand_x32_e8m0;
HVX_Vector e8m0_mask = Q6_V_vsplat_R(0x000000ff);
r0_d = Q6_V_vdelta_VV(r0_d, expand);
r0_d = Q6_V_vand_VV(r0_d, e8m0_mask);
r0_d = Q6_Vw_vasl_VwR(r0_d, 23);
r0_d = Q6_V_vdelta_VV(r0_d, expand);
r0_d = Q6_V_vand_VV(r0_d, e8m0_mask);
r0_d = Q6_Vw_vasl_VwR(r0_d, 23);

HVX_Vector r0_dd = Q6_Vsf_equals_Vqf32(Q6_Vqf32_vmpy_VsfVsf(r0_d, vy_d));

Expand Down Expand Up @@ -811,11 +813,9 @@ static void vec_dot_mxfp4x4x2_q8x4x2(const int n,
// Expand and zero-pad 32x uint8 e8m0 values to uint32s : 0 0 0 0, 0 0 0 1, 0 0 0 2, ...
// Left shift with zero fill to create FP32
// FIXME: might need to handle zero as a special case (see ggml-cpu code)
HVX_Vector expand = *(const HVX_Vector *) expand_x32_e8m0;
HVX_Vector e8m0_mask = Q6_V_vsplat_R(0x000000ff);
r0_d = Q6_V_vdelta_VV(r0_d, expand);
r0_d = Q6_V_vand_VV(r0_d, e8m0_mask);
r0_d = Q6_Vw_vasl_VwR(r0_d, 23);
r0_d = Q6_V_vdelta_VV(r0_d, expand);
r0_d = Q6_V_vand_VV(r0_d, e8m0_mask);
r0_d = Q6_Vw_vasl_VwR(r0_d, 23);

HVX_Vector r0_dd = Q6_Vsf_equals_Vqf32(Q6_Vqf32_vmpy_VsfVsf(r0_d, vy_d));

Expand Down