Skip to content

RVV1.0 Dequantize Layer#6658

Merged
nihui merged 6 commits into
Tencent:masterfrom
Deepdive543443:dequantize-riscv/PR
May 18, 2026
Merged

RVV1.0 Dequantize Layer#6658
nihui merged 6 commits into
Tencent:masterfrom
Deepdive543443:dequantize-riscv/PR

Conversation

@Deepdive543443
Copy link
Copy Markdown
Contributor

Road to int8 optimization Episode 2: Dequantize Layer

@github-actions github-actions Bot added the riscv label Apr 7, 2026
Comment thread src/layer/riscv/dequantize_riscv.cpp Outdated
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 19, 2026

Codecov Report

❌ Patch coverage is 97.29730% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.85%. Comparing base (9ee760d) to head (8cc4a44).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
src/layer/riscv/dequantize_riscv_zfh.cpp 96.00% 3 Missing ⚠️
src/layer/riscv/dequantize_riscv.cpp 98.63% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           master    #6658    +/-   ##
========================================
  Coverage   95.85%   95.85%            
========================================
  Files         934      936     +2     
  Lines      312692   312319   -373     
========================================
- Hits       299720   299371   -349     
+ Misses      12972    12948    -24     

☔ View full report in Codecov by Sentry.
📢 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.

@Deepdive543443 Deepdive543443 requested a review from nihui May 12, 2026 07:10
@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 all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ Deepdive543443
❌ nihui
You have signed the CLA already but the status is still pending? Let us recheck it.

@nihui nihui requested a review from Copilot May 15, 2026 06:54
@nihui
Copy link
Copy Markdown
Member

nihui commented May 15, 2026

@codex review

Copy link
Copy Markdown

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

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: 01fa3a135c

ℹ️ 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/dequantize_riscv.cpp Outdated
Comment thread src/layer/riscv/dequantize_riscv_zfh.cpp Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a RISC-V (RVV 1.0) optimized implementation of the Dequantize layer as part of the int8 optimization work, including optional fp16-storage support, and adjusts the unit test suite behavior on RISC-V.

Changes:

  • Added RVV-accelerated Dequantize_riscv forward path for fp32 output.
  • Added NCNN_ZFH fp16-storage forward path for Dequantize_riscv.
  • Disabled the pack8 dequantize test case on RISC-V builds.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
tests/test_dequantize.cpp Skips the pack8 dequantize test on __riscv.
src/layer/riscv/dequantize_riscv.h Declares the RISC-V optimized Dequantize layer class and fp16-storage hook.
src/layer/riscv/dequantize_riscv.cpp Implements RVV-based dequantization to fp32 and dispatch to fp16-storage when enabled.
src/layer/riscv/dequantize_riscv_zfh.cpp Implements fp16-storage output path (optionally using RVV).
Comments suppressed due to low confidence (2)

src/layer/riscv/dequantize_riscv.cpp:94

  • Similarly, _bias is only initialized for bias_data.w == 1 or elempack == vlm1. If bias_data.w > 1 and elempack is not vlm1, _bias is used uninitialized in vfmacc, leading to undefined behavior and wrong outputs for per-channel bias with other pack widths. Add initialization + pack-width handling consistent with the _scale logic.
#if __riscv_vector
        vfloat32m8_t _bias;
        if (bias_data.w == 1)
        {
            _bias = __riscv_vfmv_v_f_f32m8(bias, __riscv_vsetvlmax_e32m8());
        }
        else if (elempack == vlm1)
        {
            vfloat32m1_t _b = __riscv_vle32_v_f32m1(bias_data, vlm1);
            _bias = __riscv_vcreate_v_f32m1_f32m8(_b, _b, _b, _b, _b, _b, _b, _b);
        }

        int n = size;
        while (n > 0)
        {
            size_t vl = __riscv_vsetvl_e32m8(n);
            vfloat32m8_t _v = __riscv_vfcvt_f_x_v_f32m8(__riscv_vle32_v_i32m8(intptr, vl), vl);
            _v = __riscv_vfmacc_vv_f32m8(_bias, _v, _scale, vl);
            __riscv_vse32_v_f32m8(ptr, _v, vl);

src/layer/riscv/dequantize_riscv_zfh.cpp:80

  • In the RVV fp16-storage path, _bias is also potentially used uninitialized when bias_data.w > 1 and elempack is not vlm1. Add initialization and support for other pack widths so per-channel bias works for all packed layouts that can reach this code.
#if __riscv_vector
        vfloat32m8_t _bias;
        if (bias_data.w == 1)
        {
            _bias = __riscv_vfmv_v_f_f32m8(bias, __riscv_vsetvlmax_e32m8());
        }
        else if (elempack == vlm1)
        {
            vfloat32m1_t _b = __riscv_vle32_v_f32m1(bias_data, vlm1);
            _bias = __riscv_vcreate_v_f32m1_f32m8(_b, _b, _b, _b, _b, _b, _b, _b);
        }

        int n = size;
        while (n > 0)
        {
            size_t vl = __riscv_vsetvl_e16m4(n);
            vfloat32m8_t _v = __riscv_vfcvt_f_x_v_f32m8(__riscv_vle32_v_i32m8(intptr, vl), vl);
            _v = __riscv_vfmacc_vv_f32m8(_bias, _v, _scale, vl);
            __riscv_vse16_v_f16m4(ptr, __riscv_vfncvt_f_f_w_f16m4(_v, vl), vl);

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/layer/riscv/dequantize_riscv.cpp Outdated
Comment thread src/layer/riscv/dequantize_riscv_zfh.cpp
Comment thread tests/test_dequantize.cpp
Copy link
Copy Markdown

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

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: ee2084d509

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/layer/riscv/dequantize_riscv.cpp Outdated
Comment thread src/layer/riscv/dequantize_riscv_zfh.cpp Outdated
Copy link
Copy Markdown

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

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: 27a556049e

ℹ️ 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/dequantize_riscv.cpp Outdated
Comment thread src/layer/riscv/dequantize_riscv_zfh.cpp Outdated
@nihui nihui merged commit abfa9d2 into Tencent:master May 18, 2026
96 of 97 checks passed
@nihui
Copy link
Copy Markdown
Member

nihui commented May 18, 2026

Thanks for your contribution !

@Deepdive543443 Deepdive543443 deleted the dequantize-riscv/PR branch May 18, 2026 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants