Skip to content

Fix flush/barrier - #30

Open
karabambus wants to merge 1 commit into
aifoundry-org:etfrom
karabambus:et-fix-engine-flush-barrier
Open

Fix flush/barrier#30
karabambus wants to merge 1 commit into
aifoundry-org:etfrom
karabambus:et-fix-engine-flush-barrier

Conversation

@karabambus

@karabambus karabambus commented Aug 29, 2026

Copy link
Copy Markdown

Overview

This commit fixes 2 bugs.

  1. Kernels that using consumer/producer double buffering (matrix engines) would read stale counters
    • on lunch we call barrier to stop consumer reading counter to early before producer has reset them.
  2. During dequantization weights get flushed from one layer of cache to other, and flush_to_l2 cant flush over 16 lines of weights, this rule was broken multiple times.
    • flush_to_l2_multi flushes n lines instead of 16.

Additional information

Both fixes are verbatim copy (including comments from q8 kernels #25). Tracking history there was mul_mat kernel for q8, lost after rewrite (?) This changes were encountered on mul_mat_Q4_0_matrix_engine. Fix was tested and verified. Other kernels weren't tested.

Both bugs were showing up under specific conditions

  • dequant was working fine if last digits of value were zero, since I ly tail if value was affected
  • consumer reading stale counter was also based on were previouse side effects of right shape so they affect the counter.
  • bugs only showed up during extensive testing

Requirements

1. Kernels that using consumer/producer double buffering (matrix engines)
- on lunch we call barrier to stop consumer reading counter to early before producer has reset them.
2. During dequantization weights get flushed from one layer of cache to other, and flush_to_l2 cant flush over 16 lines of weights, this rule was broken multiple times.
- flush_to_l2_multi flushes n lines instead of 16.

Both fixes are verbatim copy (including comments from q8 kernels)
@karabambus
karabambus requested a review from marty1885 as a code owner August 29, 2026 21:37
@github-actions github-actions Bot added the ggml label Aug 29, 2026
@marty1885

Copy link
Copy Markdown

Hi, thanks for the patch. But no. I do not believe you have validated your code - please request remote access at AIF discord

L2-SCP persists across kernel dispatches (only zeroed at boot.....)

FCC counters are reset across on kernel dispatches.

@karabambus

karabambus commented Aug 30, 2026

Copy link
Copy Markdown
Author

FCC counters are reset across on kernel dispatches.

correct, but two counters this barrier protects are ready_ctr/consumed_ctr. These are just values in scratchpad. I measured them surviving across dispatch. Since it is a race condition you have to perform multiple tests.

these are result of 5 runs of 46 tests without barrier - 46/46, 45/46, 45/46, 45/46, 45/46. Numerical error is different with every ("failing") run.

EDIT: only Q4 was tested. Downloading all the weights requires some time, I might come back on this later if its needed to go trough every kernel. Please confirm, what you want for this PR to be validated? Since all this was present in q8 engine that was allready reviewed #25 (why is it gone?) I tought this would be straight forward so I didn't put much effort in detailed results. I will try to revisit this when I have more time

@marty1885

Copy link
Copy Markdown

tested on my machine. Works well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants