[Bug] loop_conv_ws narrows 2-bit activation enum to bool, silently turning RELU6 (2) into RELU (1) on hardware-pooled path

オープン 初心者向け
#10 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
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/libgemmini master (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-sim master (051d820f08be84d069993de4375d29c91eb2f577) at gemmini/gemmini.cc:1002 and 1401-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_ws does not re-issue CONFIG_ST, so the caller's prior RELU6 configuration remains intact.
  • When output != 0 && !no_pool, loop_conv_ws re-issues CONFIG_ST to set pooling parameters and inadvertently overwrites gemmini_state.act with 1 (RELU).
  • Note: This bug is independent of 32-bit 6 << relu6_shift overflow at relu6_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 を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

ucb-bar/libgemmini のほかの issue

ucb-bar/libgemmini の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。