Skip to content

fix(ir): Preserve TaskId temp deps in auto derivation#1753

Open
sunkaixuan2018 wants to merge 3 commits into
hw-native-sys:mainfrom
sunkaixuan2018:fix-issue-1744
Open

fix(ir): Preserve TaskId temp deps in auto derivation#1753
sunkaixuan2018 wants to merge 3 commits into
hw-native-sys:mainfrom
sunkaixuan2018:fix-issue-1744

Conversation

@sunkaixuan2018

Copy link
Copy Markdown
Contributor

Summary

  • Track Array[TASK_ID] and scalar TaskId lineage through auto dependency derivation.
  • Preserve manual scopes for TaskId-array temp deps used by Qwen decode, while rejecting unrelated direct submit deps as dynamic-producer coverage.
  • Add regression coverage for full TaskId-array deps, scalar temp deps, partial fallback, and unrelated deps fallback.

Testing

  • Remote myserver: rebuilt build-native and copied fresh pypto_core into the branch .venv.
  • Remote pytest: tests/ut/ir/transforms/test_auto_derive_task_dependencies.py -> 36 passed.
  • Remote Qwen3 14B decode: models/qwen3/14b/decode_layer.py -d {} --enable-l2-swimlane -> PASS.
  • Fresh L2 artifact: /data/sunkaixuan/skx_log_output/issue1744/qwen_decode_nonsubmit_20260611_203215/merged_swimlane_20260611_203238.json.
  • L2 concurrency spot check: out_proj 24/50, gate_proj 14/85, up_proj 15/85, down_proj 24/85, down_cast_residual 5/5.

Related Issues

Fixes #1744

@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 934e6eab-a0de-4e33-9d7d-c162c59534a0

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The PR extends the AutoDeriveTaskDependencies compiler pass to resolve task-id dependencies expressed through pl.array[TASK_ID] elements, preventing incorrect demotion of user-written pl.manual_scope() to AUTO scope. The implementation adds lineage tracking for array task-ids, updates loop propagation and canonicalization logic, and includes comprehensive test coverage.

Changes

Task-ID Array Lineage Support

Layer / File(s) Summary
Helper utilities and collector task-id recording
src/ir/transforms/auto_derive_task_dependencies_pass.cpp
Adds utility functions to identify task-id scalars/arrays, extract constant values and extents, merge unique task-id sets, and detect multi-slot dynamic coverage. Extends SubmitTaskIdCollector to record task-id producers for both array and scalar forms alongside existing tuple task-id recording.
Lineage-driven data structures and accessors
src/ir/transforms/auto_derive_task_dependencies_pass.cpp
Replaces scalar-only task-id mappings with lineage-based structures: task-id vectors per var-id, dynamic producer slot sets, task-id array extents, and expanded array candidates. Introduces new lineage structs for expression and array propagation that enable task-id resolution through array access patterns.
Lineage-based task-id resolution and array expansion
src/ir/transforms/auto_derive_task_dependencies_pass.cpp
Implements TaskIdsForExpr to derive task-id vectors and dynamic slot sets from canonical task-id vars, mapped var-derived task-ids, or array.get_element expansion. Adds ExpandTaskIdArray to conditionally expand array task-ids when lineage is known (direct writes, dynamic loop writes, per-element composition) and multi-slot coverage is satisfied.
Loop-carried task-id array propagation and collector state
src/ir/transforms/auto_derive_task_dependencies_pass.cpp
Updates loop-carried task-id handling to propagate task-id arrays by lineage and derive expansions for iter args and return vars. Rewrites producer/extent recording logic to distinguish task-id arrays and task-id scalars, replacing prior scalar-only internal state mappings with new vector/dynamic-slot/extent/lineage representations.
Canonicalization and hazard edge coverage logic
src/ir/transforms/auto_derive_task_dependencies_pass.cpp
Reworks dependency canonicalization to operate on vectors of task-ids rather than single scalars. Adds dynamic-array slot-based merging and array task-id expansion when multi-slot dynamic coverage is satisfied. Augments hazard edge coverage check with additional conditions for dynamic producers with non-submit user edges. Includes helper to detect user edges containing non-submit task-ids.
Mutator state updates and pass construction wiring
src/ir/transforms/auto_derive_task_dependencies_pass.cpp
Updates AutoDepMutator member fields to store vector-based task-id mappings, dynamic slot sets, and array extents instead of previous scalar-only var-id mapping. Adjusts pass construction wiring so the mutator receives new collector outputs including task-id vectors for vars and arrays, dynamic slot sets, and extents.
Algorithm documentation updates
docs/en/dev/passes/35-auto_derive_task_dependencies.md, docs/zh-cn/dev/passes/35-auto_derive_task_dependencies.md
Updates documentation in both English and Simplified Chinese to clarify step 6 of the AutoDeriveTaskDependencies algorithm: specifies when Array[TASK_ID] dependency values are conservatively expanded (only when lineage is known for direct scalar writes, dynamic loop writes, and per-element array composition), and when arrays with unclear origin remain unexpanded to preserve fallback behavior for missing dependencies.
Test coverage for task-id array dependencies
tests/ut/ir/transforms/test_auto_derive_task_dependencies.py
Adds three new unit tests validating that pl.manual_scope() is preserved when loop-propagated task-id information is stored in and accessed from a pl.array of TASK_IDs (covering full indexing, slot-based access, and partial access patterns). Updates one existing test to depend on two separate unrelated task-ids to validate fallback behavior with multiple producers.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

A rabbit hops through task arrays with glee, 🐰
Tracking TASK_ID lineage, wild and free,
No more false scope demotion's sad refrain,
pl.manual_scope() keeps its parallelism reign,
Array deps resolved—the pass stands in delight! ✨

🚥 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 accurately describes the main change: preserving TaskId temporary dependencies in auto-derivation, which directly addresses issue #1744's core problem of manual scopes being incorrectly demoted.
Description check ✅ Passed The description clearly explains the changes: tracking Array[TASK_ID] lineage, preserving manual scopes for TaskId-array deps, and includes testing performed with concrete examples.
Linked Issues check ✅ Passed The PR fully addresses issue #1744's objectives: it implements lineage tracking for TaskId arrays, enables correct dependency resolution for arr[i] elements, and preserves user manual scopes by avoiding fallback demotion to AUTO.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing issue #1744: documentation updates clarify the behavior, core implementation adds TaskId array support, and tests validate the fix with comprehensive coverage of array deps, scalar deps, partial fallback, and unrelated deps scenarios.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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 and usage tips.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request enhances the task dependency auto-derivation pass to conservatively expand Array[TASK_ID] dependency values when their lineage is known, updating both documentation and unit tests. The review feedback highlights a critical bug in HasMultiSlotDynamicCoverage where partial slot coverage could incorrectly bypass fallback mechanisms, a potential issue in HasNonSubmitTaskIdUserEdge where unrelated task IDs might satisfy coverage checks, and a recommendation to add a test case verifying fallback behavior for partial slot coverage.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread src/ir/transforms/auto_derive_task_dependencies_pass.cpp Outdated
Comment thread src/ir/transforms/auto_derive_task_dependencies_pass.cpp Outdated
Comment thread tests/ut/ir/transforms/test_auto_derive_task_dependencies.py
@sunkaixuan2018 sunkaixuan2018 force-pushed the fix-issue-1744 branch 5 times, most recently from 8668e0d to b38eaed Compare June 11, 2026 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[Pass Bug] AutoDeriveTaskDependencies demotes user-written pl.manual_scope() to AUTO when deps go through a pl.array of TaskIds → full serialization

1 participant