Skip to content

refactor riscv gemm microkernel - #6752

Merged
nihui merged 12 commits into
Tencent:masterfrom
nihui:opt-riscv-gemm
Oct 4, 2026
Merged

nihui merged 12 commits into
Tencent:masterfrom
nihui:opt-riscv-gemm

Conversation

@nihui

@nihui nihui commented May 28, 2026

Copy link
Copy Markdown
Member

No description provided.

@github-actions github-actions Bot added the riscv label May 28, 2026
@tencent-adm

Copy link
Copy Markdown
Member

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@codecov-commenter

codecov-commenter commented May 28, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.05265% with 183 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.15%. Comparing base (9f9d4ec) to head (5e32cac).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/layer/riscv/multiheadattention_riscv.cpp 81.04% 58 Missing ⚠️
src/layer/riscv/gemm_fp16sa.h 95.25% 57 Missing ⚠️
src/layer/riscv/sdpa_riscv.cpp 88.53% 29 Missing ⚠️
src/layer/riscv/gemm_fp16s.h 93.68% 25 Missing ⚠️
src/layer/riscv/gemm_bf16s_fp16s.h 87.93% 7 Missing ⚠️
src/layer/riscv/gemm_riscv_zfh.cpp 98.79% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6752      +/-   ##
==========================================
- Coverage   95.19%   95.15%   -0.05%     
==========================================
  Files        1457     1456       -1     
  Lines      493714   495505    +1791     
==========================================
+ Hits       469996   471482    +1486     
- Misses      23718    24023     +305     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nihui
nihui marked this pull request as ready for review May 30, 2026 08:21
@nihui nihui changed the title [WIP] refactor riscv gemm microkernel refactor riscv gemm microkernel May 30, 2026
@nihui
nihui requested a review from Copilot May 30, 2026 08:23
@nihui

nihui commented May 30, 2026

Copy link
Copy Markdown
Member Author

@codex review

@nihui nihui closed this May 30, 2026
@nihui nihui reopened this May 30, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@nihui

nihui commented May 30, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e0a6655f26

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/layer/riscv/gemm_riscv.cpp Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment thread src/layer/riscv/gemm_riscv_zfh.cpp Outdated
@nihui nihui closed this Jun 6, 2026
@nihui nihui reopened this Jun 6, 2026
@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown

Please enable github action in YOUR FORKED REPO to make code-format workflow work

@nihui
nihui merged commit 5e33816 into Tencent:master Oct 4, 2026
50 of 52 checks passed
HougeLangley added a commit to HougeLangley/ncnn that referenced this pull request Oct 5, 2026
…ME2 branch

合并上游对 riscv GEMM 微内核与 SDPA 的重构(Tencent#6752,含新的 sdpa_riscv 子层实现)。
冲突文件以上游新版为基,本分支的增量(IME2 Gemm 接管块、M=1 解码快路径)在随后的提交中移植。

Merge the upstream riscv GEMM microkernel / SDPA refactor (Tencent#6752, which adds its
own sdpa_riscv sub-layer implementation). The conflicting files take the upstream
version as the base; this branch's additions (the IME2 Gemm takeover block and the
M=1 decode fast path) are ported in the following commits.
HougeLangley added a commit to HougeLangley/ncnn that referenced this pull request Oct 5, 2026
…he upstream refactor

在上游 Tencent#6752 重构后的基线上保留本分支的 SDPA 增量:
  * forward_rvv_decode —— M=1 解码快速路径(QK^T 逐位置点积 + 流式 P·V + RVV 向量化 exp),
    解决解码随上下文长度塌陷的问题(507 token 上下文:5.22 -> 8.07 tok/s 于该改动当时);
  * forward_ime2_prefill / ime2_available —— SpacemiT K3 IME2 的 flash 式预填充路径;
  * 与之配套的解码分段计时(NCNN_SDPA_DECODE_PROF)与 KV cache 管理。

注:上游 Tencent#6752 同时新增了一版 sdpa_riscv(子层 qk_gemm/qkv_gemm/qk_softmax 实现)。
本分支保留了自研实现,因为它额外提供 M=1 解码快路径与 IME2 预填充,并已通过三腿逐字节闸门;
若上游更希望采用子层方案,可将本文件的解码路径作为增量移植到该方案之上(接口已兼容)。

Keep this branch's SDPA additions on top of the upstream refactor (Tencent#6752):
the M=1 decode fast path (per-position dot product + streaming P·V + vectorised exp,
which stops decode collapsing with context length), the IME2 flash prefill path, and
the accompanying decode segment timers and KV-cache handling.

Upstream Tencent#6752 also added its own sdpa_riscv (sub-layer based). This branch keeps the
standalone implementation because it additionally provides the M=1 decode path and IME2
prefill, and it passes the three-leg byte-identical gate. If upstream prefers the
sub-layer design, the decode path here can be ported onto it (the interfaces are
compatible, as verified by building against the refactored base).
HougeLangley added a commit to HougeLangley/ncnn that referenced this pull request Oct 5, 2026
合并远端自动格式化提交;冲突文件取本分支版本,因为它已包含上游 Tencent#6752 的重构,
若取远端版本会把该重构回退掉。格式由上游 CI 统一处理。

Merge the remote code-format commit. The conflicted file keeps this branch's
version because it already contains the upstream Tencent#6752 refactor; taking the
remote side would revert it. Formatting is left to the upstream CI.
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.

5 participants