[Bug] loop_conv_ws narrows 2-bit activation enum to bool, silently turning RELU6 (2) into RELU (1) on hardware-pooled path
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 72/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- cpp
調査の方向性
gemmini.cc の gemmini_t::loop_conv_ws から始めてください。ここでは rs2 のビット 3-4 からアクティベーションのフィールドを読み取ります。また、1450-1467 行目付近で CONFIG_ST を再発行するプーリングの分岐も確認してください。アクティベーション変数の型が、その設定呼び出しに渡る値にどう影響するかを調べてください。プーリング経路を通っても RELU6 が保持され、6 << relu6_shift に制限されるプーリング付き 1x1 conv のテストで示せれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Summary
Inside gemmini_t::loop_conv_ws(reg_t rs1, reg_t rs2), the 2-bit activation enum extracted from rs2[4:3] is stored in a const bool, silently narrowing RELU6 (2) to true (1 = RELU). Whenever hardware max-pooling is enabled (output != 0 && !no_pool), loop_conv_ws re-issues CONFIG_ST with (activation << 2), overwriting gemmini_state.act from RELU6 to RELU and silently dropping the upper 6 << relu6_shift clamp for all pooled outputs.
Exact Source Location (Live on master HEAD)
ucb-bar/libgemminimaster(6652649b26aa0beede6bc8f049b52431f2768c28):gemmini.cc:1042:const bool activation = (rs2 >> 3) & 3;gemmini.cc:1450-1467(else if (output != 0 && !no_pool)):config( ... (activation << 2) | 2, ...);
- Also identically present in
ucb-bar/esp-isa-simmaster(051d820f08be84d069993de4375d29c91eb2f577) atgemmini/gemmini.cc:1002and1401-1418.
Root Cause (CWE-681: Boolean Narrowing)
In Gemmini's RoCC ISA, activation is a 2-bit enumeration (0 = NO_ACTIVATION, 1 = RELU, 2 = RELU6). Although loop_conv_ws masks two bits with (rs2 >> 3) & 3, declaring activation as const bool converts integer 2 (RELU6) to true (1 = RELU) — verified in compiled libgemmini.so disassembly (and $0x18, %ebx; setne %dl; lea 0x0(,%rdx,4), %r12d).
- When
no_pool == true,loop_conv_wsdoes not re-issueCONFIG_ST, so the caller's priorRELU6configuration remains intact. - When
output != 0 && !no_pool,loop_conv_wsre-issuesCONFIG_STto set pooling parameters and inadvertently overwritesgemmini_state.actwith1(RELU). - Note: This bug is independent of 32-bit
6 << relu6_shiftoverflow atrelu6_shift >= 29; it triggers at completely normal, legal shifts (relu6_shift = 0, 1, 2, ...).
Controlled A/B Reproduction (16×16 WS Gemmini RTL vs. Spike)
Setup: 1×1 weight-stationary convolution (in_dim=4, in_ch=16, out_ch=16, act=RELU6 (2), relu6_shift=1 -> clamp ceiling 6 << 1 = 12, positive inputs producing pre-activation accumulator values ~127):
| Case | pool_size / pool_stride |
CPU Gold & Chisel RTL (Verilator) | Spike (libgemmini) |
Verdict |
|---|---|---|---|---|
| Control (Unpooled) | 0 / 1 (no_pool=1) |
[12, 0, 0, 0, 12] |
[12, 0, 0, 0, 12] |
Bit-exact match |
| Treatment (Hardware Pooled) | 2 / 2 (no_pool=0) |
[12, 0, 0, 12, 12] |
[127, 0, 0, 127, 127] |
10.58× silent corruption (RELU6 clamp dropped) |
Suggested One-Line Fix
--- a/gemmini.cc
+++ b/gemmini.cc
@@ -1039,7 +1039,7 @@ void gemmini_t::loop_conv_ws(reg_t rs1, reg_t rs2) {
const bool no_pool = rs2 & 1;
const bool downsample = (rs2 >> 1) & 1;
const bool input_dilated = (rs2 >> 2) & 1;
- const bool activation = (rs2 >> 3) & 3;
+ const uint8_t activation = (rs2 >> 3) & 3;
- 主要言語
- C++
- スター
- 5
- フォーク
- 18
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
ucb-bar/libgemmini のほかの issue
-
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
ucb-bar/libgemmini#9 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 20/100
ucb-bar/libgemmini#3 ·
ucb-bar/libgemmini の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
deepseek-ai/DeepGEMM#529 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
compiler-explorer/compiler-explorer#9710 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
`test_controlled_TermSequenceBox_logging` and `test_symbolic_ops` fail when another test runs firstオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
Quantinuum/tket#2282 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 84/100
KhronosGroup/Vulkan-Tutorial#555 ·
メンテナーはふだん 10 日以内に返信