Skip to content

Fix: decouple tensor-dump args mask pool from runtime ring depth#1320

Merged
ChaoZheng109 merged 1 commit into
hw-native-sys:mainfrom
yanghaoran29:dumptensor
Jul 10, 2026
Merged

Fix: decouple tensor-dump args mask pool from runtime ring depth#1320
ChaoZheng109 merged 1 commit into
hw-native-sys:mainfrom
yanghaoran29:dumptensor

Conversation

@yanghaoran29

@yanghaoran29 yanghaoran29 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Problem

The args-dump mask pool keyed entries on the runtime's (ring_id, slot) partition of task_id: resolve_dump_args_task_slot extracted ring_id from the high 32 bits and returned false when ring_id >= TENSOR_DUMP_MASK_POOL_MAX_RINGS (= PTO2_MAX_RING_DEPTH). Any task_id whose ring field exceeded the runtime's max was silently dropped — its dump mask never entered the table and reads back TENSOR_DUMP_ARG_MASK_NONE.

The pool inherited a runtime coupling (PTO2_MAX_RING_DEPTH / PTO2_TASK_WINDOW_SIZE via pto_runtime2_types.h) it shouldn't have: the dump mask pool is a host-side diagnostic table and must accept any task_id the runtime issues, regardless of how the runtime partitions the id into ring/slot.

Fix

  • Drop the PTO2_MAX_RING_DEPTH / PTO2_TASK_WINDOW_SIZE dependency from the a2a3 and a5 tensor_dump.h headers (removes the TENSOR_DUMP_MASK_POOL_MAX_RINGS / MAX_SLOTS / DEFAULT_SLOT_MASK constants and the pto_runtime2_types.h include).
  • Refactor resolve_dump_args_task_slot to fold the full 64-bit task_id via high ^ low XOR into the table index. Every task_id now maps to a slot regardless of its ring field; the function returns uint32_t directly instead of writing through an out-parameter (per review feedback).
  • Update all 4 callers (set_dump_args_task_scalar_dtypes, get_dump_args_task_scalar_dtypes, set_dump_args_task_mask, get_dump_args_task_masks) to uint32_t idx = resolve_dump_args_task_slot(task_id);.

Tests

Adds tests/ut/cpp/a2a3/test_tensor_dump_mask_pool.cpp and tests/ut/cpp/a5/test_tensor_dump_mask_pool.cpp (mirrored — the dump source is shared but each platform carries its own header/test target) covering:

  • HighRingTaskIdRoundTrips — a task_id whose high 32 bits exceed any runtime's ring depth still round-trips through both the mask table and the scalar-dtype table (the regression this PR fixes).
  • DistinctTaskIdsDoNotAlias — open-addressed probing keeps two distinct ids independent.
  • UnknownTaskIdReadsNone — unset task_id reads back TENSOR_DUMP_ARG_MASK_NONE (empty-slot path).

Changes

  • src/a2a3/platform/include/common/tensor_dump.h — remove pto_runtime2_types.h include and the 3 derived constants.
  • src/a5/platform/include/common/tensor_dump.h — same.
  • src/common/platform/shared/aicpu/tensor_dump_aicpu.cpp — refactor resolve_dump_args_task_slot + 4 callers.
  • tests/ut/cpp/CMakeLists.txt — register the new a2a3 + a5 tests.
  • tests/ut/cpp/a2a3/test_tensor_dump_mask_pool.cpp — new test file.
  • tests/ut/cpp/a5/test_tensor_dump_mask_pool.cpp — new test file.

close #1317

@yanghaoran29 yanghaoran29 changed the title 1 [WIP] DumpTensor Jul 10, 2026
@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Tensor-dump selective metadata now maps task IDs using folded 64-bit hashing instead of ring validation. Header constants were updated, and new A2A3 runtime tests cover masks, flags, scalar dtypes, collisions, high task IDs, and unset entries.

Changes

Tensor-dump task slot selection

Layer / File(s) Summary
Update tensor-dump constants
src/a2a3/platform/include/common/tensor_dump.h, src/a5/platform/include/common/tensor_dump.h
Removes ring-depth-dependent includes and mask-pool constants, replacing the A2A3 definitions with TENSOR_DUMP_ARG_MASK_NONE and TENSOR_DUMP_ARG_MASK_BITS.
Replace task-ID slot resolution
src/common/platform/shared/aicpu/tensor_dump_aicpu.cpp
Uses XOR-folded task-ID halves masked to table capacity, and applies the resolver unconditionally for scalar dtype and mask accessors.
Add mask-pool runtime coverage
tests/ut/cpp/CMakeLists.txt, tests/ut/cpp/a2a3/test_tensor_dump_mask_pool.cpp
Registers tests for task-ID round trips, high and legacy-range IDs, independent entries, scalar dtypes, and unset values.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related issues

  • Issue 1317 — Directly covers opaque task-ID hashing, removal of ring-depth-dependent constants, and associated test coverage.

Possibly related PRs

Poem

A rabbit hops through masks of light,
Hashing task IDs left and right.
Old rings fade; new bits align,
Tests guard every lookup line.
High IDs burrow safely home.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 38.46% 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
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.
Title check ✅ Passed The title clearly matches the main change: decoupling tensor-dump args mask pool from runtime ring-depth assumptions.
Description check ✅ Passed The description accurately covers the header cleanup, slot-resolution refactor, and added tests reflected in the changeset.

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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

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 decouples the tensor dump mask pool from the runtime ring depth by refactoring resolve_dump_args_task_slot to use a hash-folding mechanism on the 64-bit task_id instead of splitting it into ring and slot fields. It also removes the unused constants and the dependency on pto_runtime2_types.h, and adds a comprehensive unit test suite. The review feedback suggests a great improvement to make resolve_dump_args_task_slot return the calculated index directly as a uint32_t instead of using an out-parameter pointer, which simplifies the calling code and avoids potential null pointer dereferences.

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/common/platform/shared/aicpu/tensor_dump_aicpu.cpp Outdated
Comment thread src/common/platform/shared/aicpu/tensor_dump_aicpu.cpp Outdated
Comment thread src/common/platform/shared/aicpu/tensor_dump_aicpu.cpp Outdated
Comment thread src/common/platform/shared/aicpu/tensor_dump_aicpu.cpp Outdated
Comment thread src/common/platform/shared/aicpu/tensor_dump_aicpu.cpp Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
tests/ut/cpp/a2a3/test_tensor_dump_mask_pool.cpp (1)

72-88: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add a test for actual hash collisions.

The DistinctTaskIdsDoNotAlias comment claims "open-addressed probing resolves any hash collision to separate slots," but id_a (hash 102) and id_b (hash 203) do not collide. A dedicated test with two task IDs that fold to the same index would verify the probing logic that the comment describes.

For example, (1<<32)|10 and (3<<32)|8 both produce ring_id ^ local_id == 11, guaranteeing a collision for any power-of-2 table capacity.

♻️ Suggested collision test
 // Two distinct task_ids must keep independent entries (open-addressed probing
 // resolves any hash collision to separate slots).
 TEST_F(TensorDumpMaskPoolTest, DistinctTaskIdsDoNotAlias) {
     const uint64_t id_a = (uint64_t{2} << 32) | 100u;
     const uint64_t id_b = (uint64_t{3} << 32) | 200u;

     set_dump_args_task_mask(id_a, 0b0001, TENSOR_DUMP_ARG_MASK_NONE);
     set_dump_args_task_mask(id_b, 0b1000, TENSOR_DUMP_ARG_MASK_NONE);

     TensorDumpArgMask mask_a = TENSOR_DUMP_ARG_MASK_NONE;
     TensorDumpArgMask mask_b = TENSOR_DUMP_ARG_MASK_NONE;
     get_dump_args_task_masks(id_a, &mask_a, nullptr);
     get_dump_args_task_masks(id_b, &mask_b, nullptr);

     EXPECT_EQ(mask_a, static_cast<TensorDumpArgMask>(0b0001));
     EXPECT_EQ(mask_b, static_cast<TensorDumpArgMask>(0b1000));
 }

+// Two task_ids that fold to the same hash index must still occupy separate
+// slots via open-addressed probing.
+TEST_F(TensorDumpMaskPoolTest, CollidingTaskIdsDoNotAlias) {
+    // (1 << 32) | 10  -> hash = 1 ^ 10 = 11
+    // (3 << 32) | 8   -> hash = 3 ^ 8  = 11
+    const uint64_t id_a = (uint64_t{1} << 32) | 10u;
+    const uint64_t id_b = (uint64_t{3} << 32) | 8u;
+
+    set_dump_args_task_mask(id_a, 0b0001, TENSOR_DUMP_ARG_MASK_NONE);
+    set_dump_args_task_mask(id_b, 0b1000, TENSOR_DUMP_ARG_MASK_NONE);
+
+    TensorDumpArgMask mask_a = TENSOR_DUMP_ARG_MASK_NONE;
+    TensorDumpArgMask mask_b = TENSOR_DUMP_ARG_MASK_NONE;
+    get_dump_args_task_masks(id_a, &mask_a, nullptr);
+    get_dump_args_task_masks(id_b, &mask_b, nullptr);
+
+    EXPECT_EQ(mask_a, static_cast<TensorDumpArgMask>(0b0001));
+    EXPECT_EQ(mask_b, static_cast<TensorDumpArgMask>(0b1000));
+}
+
 // An unset task_id reads back as "no mask" — the empty-slot path.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/ut/cpp/a2a3/test_tensor_dump_mask_pool.cpp` around lines 72 - 88, Add a
dedicated collision test near DistinctTaskIdsDoNotAlias using task IDs
(uint64_t{1} << 32) | 10u and (uint64_t{3} << 32) | 8u, which fold to the same
hash index for power-of-two capacities. Set distinct masks with
set_dump_args_task_mask, retrieve both via get_dump_args_task_masks, and assert
each remains independent; update the existing test comment to avoid claiming it
validates collision handling.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tests/ut/cpp/a2a3/test_tensor_dump_mask_pool.cpp`:
- Around line 72-88: Add a dedicated collision test near
DistinctTaskIdsDoNotAlias using task IDs (uint64_t{1} << 32) | 10u and
(uint64_t{3} << 32) | 8u, which fold to the same hash index for power-of-two
capacities. Set distinct masks with set_dump_args_task_mask, retrieve both via
get_dump_args_task_masks, and assert each remains independent; update the
existing test comment to avoid claiming it validates collision handling.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 362cfd2a-8c9c-406a-91a0-6664e443c3b4

📥 Commits

Reviewing files that changed from the base of the PR and between cbbdfd4 and dfb352a.

📒 Files selected for processing (5)
  • src/a2a3/platform/include/common/tensor_dump.h
  • src/a5/platform/include/common/tensor_dump.h
  • src/common/platform/shared/aicpu/tensor_dump_aicpu.cpp
  • tests/ut/cpp/CMakeLists.txt
  • tests/ut/cpp/a2a3/test_tensor_dump_mask_pool.cpp
💤 Files with no reviewable changes (2)
  • src/a2a3/platform/include/common/tensor_dump.h
  • src/a5/platform/include/common/tensor_dump.h

@yanghaoran29 yanghaoran29 changed the title [WIP] DumpTensor Fix: decouple tensor-dump args mask pool from runtime ring depth Jul 10, 2026
The args-dump mask pool keyed entries on the runtime's (ring_id, slot) partition of task_id: resolve_dump_args_task_slot extracted ring_id from the high 32 bits and returned false when ring_id >= TENSOR_DUMP_MASK_POOL_MAX_RINGS (= PTO2_MAX_RING_DEPTH), so any task_id whose ring field exceeded the runtime's max was silently dropped — its dump mask never entered the table and reads back TENSOR_DUMP_ARG_MASK_NONE. The pool inherited a runtime coupling it shouldn't have.

Drop the PTO2_MAX_RING_DEPTH / PTO2_TASK_WINDOW_SIZE dependency from the a2a3 and a5 tensor_dump.h headers (removes the TENSOR_DUMP_MASK_POOL_MAX_RINGS / MAX_SLOTS / DEFAULT_SLOT_MASK constants and the pto_runtime2_types.h include) and refactor resolve_dump_args_task_slot to fold the full 64-bit task_id via high^low XOR into the table index. Every task_id now maps to a slot regardless of its ring field, and the function returns uint32_t directly instead of writing through an out-param (per review).

Adds tests/ut/cpp/a2a3/test_tensor_dump.cpp and tests/ut/cpp/a5/test_tensor_dump.cpp (mirrored across both arches since the dump source is shared but each platform carries its own header/test target) covering: basic enable/disable and dump-base round-trip; high-ring task_id mask + scalar-dtype round-trip (the regression this PR fixes); distinct task_id independence under open-addressed probing; unknown-task-id reads-none; decision helpers in FULL mode (ArgDirection→role mapping, stage gating, should_dump_task/should_dump_arg, has_dump_arg_flag); end-to-end dump-record correctness (1-D tensor arena payload + scalar inline value); selective (PARTIAL) mode decision filtering; and non-contiguous 2-D tensor gather path verification.
@ChaoZheng109 ChaoZheng109 merged commit 86a4483 into hw-native-sys:main Jul 10, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Code Health] tensor_dump mask pool should hash opaque task_id, not unpack runtime ring_id

2 participants