Skip to content

GAP9: -O3 hot kernels; make tile-control-table memory level configurable - #199

Merged
Victor-Jung merged 5 commits into
pulp-platform:develfrom
runwangdl:fix-gap9-l3-board
Aug 20, 2026
Merged

GAP9: -O3 hot kernels; make tile-control-table memory level configurable#199
Victor-Jung merged 5 commits into
pulp-platform:develfrom
runwangdl:fix-gap9-l3-board

Conversation

@runwangdl

@runwangdl runwangdl commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

1. -O3 on the hot forward kernels

TargetLibraries/GAP9/CMakeLists.txt — compile Conv / DWConv / Gemm at -O3, appended last so it
wins over the SDK's default -Os. This turns on the RISC-V (XpulpV2) hardware loops on the tight
inner loops.

2. Make the tile-control-table memory level configurable

Deeploy/TilingExtension/CodeTransformationPasses/TilingHoistingMixIn.py — adds
tileControlTableMemoryLevel, defaulting to None:

cb._memoryLevel = self.tileControlTableMemoryLevel or self.memory

None is the current behaviour, so this is a no-op unless a platform opts in.

The hoisted tables (numTiles, DMA cmd / size / stride, tile dims, base offsets) are the
read-only lookup tables the controller uses to drive the tiling loop and program the DMAs. Setting
the knob to "L2" on GAP9 moves them out of L1 TCDM, where they otherwise sit next to the cluster
master stack — a deep stack write can corrupt a DMA cmd and hang mchan_transfer_wait() (seen on
MobileNetV1 training).

runwangdl added 2 commits July 2, 2026 12:08
Compile the conv / depthwise-conv / Gemm translation units at -O3, appended
last so it wins over the SDK's default -Os on the same files. Everything else
stays at -Os. -O3 turns on the RISC-V (XpulpV2) hardware loops on the kernels'
tight inner loops; on a forward conv the -O3 object has 18 lp.setup HW-loop
instructions vs 0 at -Os, at the cost of ~+50% .text on those files.
The hoisted tile-control tables (numTiles / DMA cmd / size / dims / padding /
offsets) are read-only lookup tables the cluster controller uses to drive the
tiling loop and program DMAs -- not bulk tile data. Previously the L2->L1
tiling pass emitted them with _memoryLevel=self.memory="L1", so they landed
in the GAP9 L1 TCDM next to the cluster master stack. On memory-tight nets
this both wastes scarce L1 (~11.6 KB on CCT, ~7.0 KB on MobileNetV1, ~2.5 KB
on ResNet8) and creates a correctness hazard: a deep master-stack write can
clobber a single table entry, turning a DMA cmd into a garbage code pointer
so mchan_transfer_wait() hangs forever (observed on MobileNetV1 training).

Redirect only the L2->L1 pass to emit these tables in L2. The L3->L2 pass
keeps its tables in L2 (== self.memory, unchanged). Platforms that don't
tile into a level named "L1" are unaffected. Tile *data* buffers still go
to L1 as before -- only the constant control tables move.
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 17b87e7e-42a8-4df2-83fc-6f529d652dd0

📥 Commits

Reviewing files that changed from the base of the PR and between a2adfc6 and 72fd24f.

📒 Files selected for processing (1)
  • Deeploy/TilingExtension/CodeTransformationPasses/TilingHoistingMixIn.py

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Summary by CodeRabbit

  • New Features
    • Added configurable memory placement for hoisted tile control tables.
    • When no override is provided, control tables continue using the configured default memory level.

Walkthrough

TilingHoistingMixIn adds an optional tileControlTableMemoryLevel setting. Hoisted constant buffers use this setting when provided and otherwise use self.memory.

Changes

Tiling control-table memory placement

Layer / File(s) Summary
Resolve and apply control-table memory level
Deeploy/TilingExtension/CodeTransformationPasses/TilingHoistingMixIn.py
The mixin defines the optional tileControlTableMemoryLevel setting. _hoistValues uses it for hoisted constant buffers when it is truthy and falls back to self.memory otherwise.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Merge Risk: ⚪ Minimal · up to 72fd2

The change adds an opt-in memory-level setting and localized optimization flags without any identified merge-blocking issue; it is merge-ready after normal checks and review.

Suggested reviewers: xeratec, victor-jung

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies both main changes: GAP9 -O3 hot kernels and configurable tile-control-table memory placement.
Description check ✅ Passed The description directly explains the GAP9 optimization and the configurable tile-control-table memory level.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Victor-Jung Victor-Jung left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I have some small comments but overall it looks good. I'd like to see the runtime overhead of moving these tiling information in L2 for a small layer. If the overhead is not so negligible we will add the option to chose where these tiling info are stored.

Comment thread Deeploy/TilingExtension/CodeTransformationPasses/TilingHoistingMixIn.py Outdated
Comment thread TargetLibraries/GAP9/CMakeLists.txt
Adds TilingHoistingMixIn.tileControlTableMemoryLevel. It defaults to None,
which keeps the current behaviour of placing the hoisted tile-control
tables in the tiled level, so nothing changes unless a platform opts in.

Setting it to "L2" on GAP9 moves those tables away from the cluster master
stack, where a deep stack write can corrupt a DMA cmd and hang
mchan_transfer_wait() (seen on MobileNetV1 training).

The tables are file-scope static arrays and never come out of the tile
arena, so at a fixed --l1 the tiling solution, the DMA descriptors and the
kernel code are unchanged either way: generating VisualWakeWords with and
without the override gives identical Network.c apart from the PI_L1 /
PI_L2 section attribute on 60 arrays.
@runwangdl runwangdl changed the title GAP9: -O3 hot kernels + hoist L2->L1 tile-control tables to L2 GAP9: -O3 hot kernels; make tile-control-table memory level configurable Aug 19, 2026
@Victor-Jung Victor-Jung added the Feature Addition of new features label Aug 20, 2026
@Victor-Jung Victor-Jung added this to the Release 0.2.2 milestone Aug 20, 2026
@Victor-Jung
Victor-Jung merged commit 8c41b9b into pulp-platform:devel Aug 20, 2026
50 checks passed
@github-project-automation github-project-automation Bot moved this to Done in Deeploy Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature Addition of new features

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants