Add: unit tests for PTO2 scheduler core data structures and hot-paths#643
Add: unit tests for PTO2 scheduler core data structures and hot-paths#643chenshengxin2026 wants to merge 1 commit intohw-native-sys:mainfrom
Conversation
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
96750e9 to
c5a1c8f
Compare
5c8138d to
bda9279
Compare
bda9279 to
bde9a7b
Compare
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.
bde9a7b to
db248fd
Compare
| 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 |
There was a problem hiding this comment.
建议删除这一行新增的 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:32tests/ut/cpp/a2a3/test_ready_queue.cpp:47tests/ut/cpp/a2a3/test_spsc_queue.cpp:30tests/ut/cpp/a2a3/test_task_state.cpp:31tests/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 以为自己在测同一个头文件,实际链路已经不同。保持对称就不会出这种静默漂移。
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:
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