Skip to content

Add: unit tests for PTO2 scheduler core data structures and hot-paths#643

Open
chenshengxin2026 wants to merge 1 commit intohw-native-sys:mainfrom
chenshengxin2026:ut-pto2-ring-scheduler
Open

Add: unit tests for PTO2 scheduler core data structures and hot-paths#643
chenshengxin2026 wants to merge 1 commit intohw-native-sys:mainfrom
chenshengxin2026:ut-pto2-ring-scheduler

Conversation

@chenshengxin2026
Copy link
Copy Markdown
Contributor

@chenshengxin2026 chenshengxin2026 commented Apr 22, 2026

Summary

The core data structures (task allocator, dep-list pool, fanin pool, SPSC queue, tensor map) and scheduling hot-paths (wire_task, on_mixed_task_complete, on_task_release, advance_ring_pointers) in the PTO2 A2A3 scheduler previously had no unit test coverage. Bugs in these paths — off-by-one in wrap-around, stale fanin references, lost dependency edges — only surface under specific task-graph topologies and are extremely hard to diagnose at the system-test level.

This PR adds per-component unit tests:

  • test_task_allocator — heap bump, wrap-around guard, flow-control window
  • test_task_state — slot lifecycle driven through src API, profiling CAS semantics
  • test_dep_list_pool / test_fanin_pool — ring allocation, overflow detection, tail advance
  • test_spsc_queue — cached-index SPSC correctness, wrap, capacity semantics
  • test_tensormap — hash distribution, overlap detection, lookup saturation
  • test_wiring — end-to-end wire → complete → release → advance cycle

These tests also serve as executable documentation of design contracts (e.g. heap_available reports max-not-sum, LIFO dispatch for cache locality, relaxed size() as a hint only).

Test plan

  • cmake -B tests/ut/cpp/build -S tests/ut/cpp && cmake --build tests/ut/cpp/build -j$(nproc)
  • ctest --test-dir tests/ut/cpp/build -L no_hardware --output-on-failure
  • All new and modified test binaries pass

@gemini-code-assist
Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@chenshengxin2026 chenshengxin2026 changed the title Add: PTO2 ring buffer, scheduler & ready queue unit tests Refactor: rewrite PTO2 A2A3 unit tests around actual component APIs Apr 24, 2026
@chenshengxin2026 chenshengxin2026 force-pushed the ut-pto2-ring-scheduler branch 2 times, most recently from 5c8138d to bda9279 Compare April 24, 2026 04:22
@chenshengxin2026 chenshengxin2026 changed the title Refactor: rewrite PTO2 A2A3 unit tests around actual component APIs Add: unit tests for PTO2 scheduler core data structures and hot-paths Apr 24, 2026
The PTO2 A2A3 scheduler relies on several tightly coupled data structures
(task allocator, dep-list pool, fanin pool, SPSC queue, tensor map) and
hot-path functions (wire_task, on_mixed_task_complete, on_task_release,
advance_ring_pointers) that previously had no unit test coverage. Bugs in
these paths — off-by-one in wrap-around, stale fanin references, lost
dependency edges — surface only under specific task-graph topologies and
are extremely hard to diagnose at the system-test level.

This change adds per-component tests that exercise:
- task_allocator: heap bump, wrap-around guard, flow-control window
- task_state: slot lifecycle through src API, profiling CAS semantics
- dep_list_pool / fanin_pool: ring allocation, overflow, tail advance
- spsc_queue: cached-index SPSC correctness, wrap, capacity semantics
- tensormap: hash distribution, overlap detection, lookup saturation
- wiring: end-to-end wire → complete → release → advance cycle

These tests also serve as executable documentation of design contracts
(e.g. heap_available reports max-not-sum, LIFO dispatch for cache
locality, relaxed size() as a hint) that would otherwise exist only as
implicit assumptions in the source.
set(A2A3_COMMON_INCLUDE_DIRS
${CMAKE_SOURCE_DIR}/../../../src/a2a3/runtime/tensormap_and_ringbuffer/orchestration
${CMAKE_SOURCE_DIR}/../../../src/a2a3/runtime/tensormap_and_ringbuffer/runtime
${CMAKE_SOURCE_DIR}/../../../src/a2a3/runtime/tensormap_and_ringbuffer/runtime/scheduler
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

建议删除这一行新增的 include 目录,改为让 UT 的 #include 与生产代码保持一致。

生产代码里所有引用 pto_scheduler.h 的地方都用带子目录前缀的形式:

  • src/a2a3/runtime/tensormap_and_ringbuffer/runtime/pto_orchestrator.h:34: #include "scheduler/pto_scheduler.h"
  • src/a2a3/runtime/tensormap_and_ringbuffer/runtime/pto_ring_buffer.cpp:25: #include "scheduler/pto_scheduler.h"
  • src/a2a3/runtime/tensormap_and_ringbuffer/runtime/pto_runtime2.h:43: #include "scheduler/pto_scheduler.h"

约定是: include path 只暴露 runtime/,然后用 scheduler/pto_scheduler.h 作相对路径。这样 scheduler/ / shared/ 这些子目录的归属在 #include 行里就可见,不会被 flatten。

本 PR 里 5 个 UT 文件用的是短路径写法(#include "pto_scheduler.h"),为了让它们能 resolve,CMake 被迫追加了 runtime/scheduler 这个额外的 include 目录。建议反过来做:

改 5 个 test 文件的 include:

  • tests/ut/cpp/a2a3/test_wiring.cpp:32
  • tests/ut/cpp/a2a3/test_ready_queue.cpp:47
  • tests/ut/cpp/a2a3/test_spsc_queue.cpp:30
  • tests/ut/cpp/a2a3/test_task_state.cpp:31
  • tests/ut/cpp/a2a3/test_scheduler_state.cpp:22

#include "pto_scheduler.h" 改成 #include "scheduler/pto_scheduler.h",然后回滚本行。

为什么不是风格偏好而已: 将来如果 scheduler/ 再被拆分(例如 scheduler/hot/ + scheduler/cold/),生产代码的 #include "scheduler/..." 必须跟着改;但 UT 的短路径 include 只要 CMake 同步 include path 就还能编译,于是 UT 的 include 解析可能偏离生产代码 —— UT 以为自己在测同一个头文件,实际链路已经不同。保持对称就不会出这种静默漂移。

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.

2 participants