Misc. bug: Hexagon: test-backend-ops POOL_2D fails for 128-wide kernels with padding on HTP0 (v73)

Open Beginner friendly
#32,598 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
cpp
Domain
backend

Research direction

Start in ggml/src/ggml-hexagon/ and inspect pool_pixel_boundary_vec, especially the predicate mask built with Q6_Q_vsetq_R; compare it with Q6_Q_vsetq2_R and trace how pool_row_general_vec uses this path. Run test-backend-ops -b HTP0 -o POOL_2D; done means all 144 cases pass, including the four padded 128-wide kernel cases.

Written by the indexing model from the issue text.

Description

bug-unconfirmed
Name and Version

version: 1.0.0-dev (build 12536, commit 7a4117eef)
built with Clang 22.1.7 for Windows arm64

This is the unmodified master build where the bug reproduces. The bug is still present on current master (8af68d48); ggml/src/ggml-hexagon/ is identical between the two commits.

Operating systems

Windows

Which llama.cpp modules do you know to be affected?

Other (Please specify in the next section)

Command line
test-backend-ops -b HTP0 -o POOL_2D
Problem description & steps to reproduce

On my machine (Snapdragon X Elite X1E78100, Hexagon v73, SDK 6.7.0.0, driver 30.0.219.1000), test-backend-ops -b HTP0 -o POOL_2D fails 4 of the 144 cases. All four use a 128-wide kernel with padding; the other 140 pass, including the unpadded 128-wide kernels. The two shapes are ne_input=[259,5,3,2], k0=128, k1=3, s0=64, s1=2, p0=64, p1=1 and ne_input=[193,2,1,1], k0=128, k1=1, s0=128, s1=1, p0=128, p1=2, and each one fails for both avg and max pooling.

Avg pooling gives NMSE 294.16 and 206.38. Max pooling returns -FLT_MAX where the CPU reference is about 0.98. The mask in pool_pixel_boundary_vec is built per 32-float chunk. A full chunk has n = 32, so the code calls Q6_Q_vsetq_R(n * sizeof(float)) with 128 bytes. vsetq only takes a 7-bit byte count, so 128 wraps to 0 and the predicate is empty; Q6_V_vmux_QVV then substitutes the identity value (-FLT_MAX for max, 0 for avg) in every lane. Every output pixel that goes through this function with 32 or more valid columns therefore loses data, not only pixels with exactly 128. With stride 64 or 128, pool_row_general_vec sends every pixel, including interior ones, through this path; pixels with exactly 128 valid columns are just the most visible case (max gives -FLT_MAX), while the rest come out partly wrong. Q6_Q_vsetq2_R handles the full range and gives the correct mask, so switching to it is the whole fix.

Before the fix, 140 of 144 cases pass. After it, 144 of 144 pass on HTP0. POOL_1D is 240/240 both before and after. I only tested this on v73.

First Bad Commit

Likely 50569eb87 (ggml-org/llama.cpp#29995, which added the pool op). I did not bisect.

Relevant log output
Logs
before (7a4117eef):
[POOL_2D] ERR = 294.158129097 > 0.000000100   POOL_2D(pool_type=avg,type_input=f32,ne_input=[259,5,3,2],k0=128,k1=3,s0=64,s1=2,p0=64,p1=1): FAIL
[POOL_2D] ERR = 206.382433124 > 0.000000100   POOL_2D(pool_type=avg,type_input=f32,ne_input=[193,2,1,1],k0=128,k1=1,s0=128,s1=1,p0=128,p1=2): FAIL
[POOL_2D] inf mismatch: HTP0=-340282346638528859811704183484516925440.000000 CPU=0.985368   POOL_2D(pool_type=max,type_input=f32,ne_input=[259,5,3,2],k0=128,k1=3,s0=64,s1=2,p0=64,p1=1): FAIL
[POOL_2D] inf mismatch: HTP0=-340282346638528859811704183484516925440.000000 CPU=0.987192   POOL_2D(pool_type=max,type_input=f32,ne_input=[193,2,1,1],k0=128,k1=1,s0=128,s1=1,p0=128,p1=2): FAIL

after (51a77c4f2 + vsetq2):
POOL_2D(pool_type=avg,type_input=f32,ne_input=[259,5,3,2],k0=128,k1=3,s0=64,s1=2,p0=64,p1=1): OK
POOL_2D(pool_type=avg,type_input=f32,ne_input=[193,2,1,1],k0=128,k1=1,s0=128,s1=1,p0=128,p1=2): OK
POOL_2D(pool_type=max,type_input=f32,ne_input=[259,5,3,2],k0=128,k1=3,s0=64,s1=2,p0=64,p1=1): OK
POOL_2D(pool_type=max,type_input=f32,ne_input=[193,2,1,1],k0=128,k1=1,s0=128,s1=1,p0=128,p1=2): OK
Dominant language
C++
Stars
136k
Forks
26.1k
Avg merge
1d 19h
Merged PRs (30d)
521

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ggml-org/llama.cpp

All issues in ggml-org/llama.cpp

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.