Skip to content

feat(rocjitsu): Add a pipeline latch and IssueQueue for clocked components - #14308

Merged
amd-arosa merged 1 commit into
developfrom
users/arosa/rji/timing/simdojo-pipe-latch
Oct 27, 2026
Merged

amd-arosa merged 1 commit into
developfrom
users/arosa/rji/timing/simdojo-pipe-latch

Conversation

@amd-arosa

@amd-arosa amd-arosa commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Adds simdojo::PipeLatch, a pipeline register for models built from Clocked components. It is the first of four PRs that give a clocked CU driver the pieces it needs to decide which waves issue each cycle; this one is standalone and touches only simdojo.

Motivation

to add PipeLatch and IssueQueue

Technical Details

PipeLatch<T> is a single register. The producer stage write()s during a cycle, the owning component calls clock() on the clock edge after every stage has run, and the consumer stage take()s the value in the next cycle. Nothing written in a cycle is visible before the edge, so the stages of one cycle may run in any order. The latch applies no back-pressure and adds no latency beyond the edge; clock() replaces whatever the consumer did not take.

IssueQueue<T> holds entries that wait, in order, until each one's ready cycle. A producer push()es an entry with the first cycle it may leave, and the consumer pop()s the oldest entry once ready(cycle) says that cycle has arrived. An entry never overtakes an older one, even if its own ready cycle is earlier. A fixed-latency pipeline pushes with the current cycle plus its latency.

Both are header-only, plain state driven by their owning component, and schedule no events:

  • lib/simdojo/include/simdojo/components/pipe_latch.h
  • lib/simdojo/include/simdojo/components/issue_queue.h

Issue Tracking

#14308

Test Plan

New PipeLatchTest (9 cases) covers latency, one-per-cycle throughput, back-pressure from a stalled consumer, bubbles closing behind a stalled head, move-only entries, and a three-stage clocked pipeline run with its stages ticked in both orders.

Test Result

Built in Release with ROCm 7.3 clang, with the whole stack applied on develop.

  • PipeLatchTest: 9/9 pass.
  • Full rocjitsu ctest passes 8907 of 8922. All 15 failures are unrelated to this stack:
    • The 11 Gfx1250ExecutionTest.TensorDma* cases segfault identically on develop without these changes.
    • The 3 HsaTest cases fail because the test binary cannot link against this host's HSA runtime (hsa_amd_queue_create is missing).
    • SystemGraphTest.DaemonStartsSelectedNode cannot create its runtime directory under /tmp on this host.
  • No new compiler warnings.
  • pre-commit run --from-ref origin/develop --to-ref HEAD is clean.

Submission Checklist

@therock-pr-bot

therock-pr-bot Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

✅ All Checks Passed — Ready for Review

Check Status Details
📝 PR Description ✅ Pass —
⛔ Forbidden Files ✅ Pass —
🧪 Unit Test ✅ Pass —
🔎 pre-commit ✅ Pass —
🚫 Draft PR 🔜 To Be Enabled —
🚩 Feature Flag 🔜 To Be Enabled —
📊 Code Coverage 🔜 To Be Enabled —
🤖 therock-pr-bot ✅ Pass —

🎉 All checks passed! This PR is ready for review.

📖 Need help? See the Policy FAQ for details on every check and how to fix failures.

🙋 Wish to Override Policy?

@therock-pr-bot

therock-pr-bot Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

🎉 All checks passed! This PR is ready for review.

@atgutier atgutier 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.

Looks good to me, just a nit about pragma once and an ask to remove some complexity for now.

@amd-arosa
amd-arosa force-pushed the users/arosa/rji/timing/simdojo-pipe-latch branch 2 times, most recently from 8d9cfb4 to 20a1215 Compare October 26, 2026 22:55

@kuhar kuhar 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.

It would be useful to make a few small type and timing details explicit:

  • In emulation/rocjitsu/lib/simdojo/include/simdojo/components/pipe_latch.h:94, rename visible to visible_cycle so comparisons and updates read as timestamps rather than a boolean property.
  • At pipe_latch.h:99, use std::numeric_limits<uint64_t>::max() (as simdojo's TICK_MAX does) and document that the initial value means no write yet.
  • In emulation/rocjitsu/tests/simdojo_pipe_latch_test.cpp:101, spell out std::unique_ptr<int> value to make the move-only result type explicit and follow the style guide's rule for function-return auto.
  • At simdojo_pipe_latch_test.cpp:73, spell out latency + 1 instead of introducing the undefined shorthand L.

Cycle-level models built from Clocked components need registers between
their pipeline stages. Add simdojo::PipeLatch: a producer stage writes a
value during a cycle, the owning component clocks the latch on the clock
edge, and the consumer stage takes the value in the next cycle. Nothing
written in a cycle is visible before the edge, so the stages of one cycle
may run in any order.

A latch is a single register: it applies no back-pressure and adds no
latency beyond the edge. It is plain state driven by its owning component
and schedules no events.

Multi-cycle units, such as execution pipelines and memory round trips,
need entries to wait longer than one edge. Add simdojo::IssueQueue: a
producer pushes an entry with the first cycle it may leave, and the
consumer pops the oldest entry once that cycle arrives. Entries leave in
order. A fixed-latency pipeline pushes with the current cycle plus its
latency.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@amd-arosa
amd-arosa force-pushed the users/arosa/rji/timing/simdojo-pipe-latch branch from 20a1215 to 19c929e Compare October 27, 2026 15:33
@amd-arosa
amd-arosa requested a review from atgutier October 27, 2026 15:39
@amd-arosa amd-arosa changed the title [rocjitsu] Add a pipeline latch for clocked components feat(rocjitsu): Add a pipeline latch and IssueQueue for clocked components Oct 27, 2026

@atgutier atgutier 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.

LGTM

@amd-arosa
amd-arosa merged commit 24a8e9d into develop Oct 27, 2026
92 of 99 checks passed
@amd-arosa
amd-arosa deleted the users/arosa/rji/timing/simdojo-pipe-latch branch October 27, 2026 16:52

@kuhar kuhar 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.

We should update the documentation to match the simplified primitives:

  • The PR Test Plan and Test Result still describe nine PipeLatchTest cases, including latency and back-pressure. The current suites have five latch tests and four queue tests. Please describe those cases and identify which revision the reported full-suite results cover.
  • Add the two headers to emulation/rocjitsu/docs/simdojo.md's file overview and component library, with a short example of running stages before clock(). Its Simulation Time section currently says all timestamps and latencies use Tick; clarify that this queue instead uses owner-maintained cycle indices. This gives callers one consistent reference for composing the new primitives.

/// any order.
///
/// @tparam T Entry type. It must be movable.
template <typename T> class IssueQueue {

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 think we should name this for its timed FIFO behavior, for example DelayQueue. It releases entries in insertion order using a fixed ready-cycle stamp; it does not select among ready instructions or track later changes to a wave's readiness. A behavior-based name would make its role clearer for execution delays and memory returns, and distinguish it from the CU's scheduling policy before the follow-up PRs adopt it.

PipeLatch<int> latch;
latch.write(1);
latch.clock();
latch.clock();

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.

It would be good to add an unread-value replacement test: write(1); clock(); write(2); clock(); should make take() return 2. The current tests cover a bubble replacing an unread value, but consume the old value before testing replacement with another value. A scratch mutation that retained the old value when both slots were populated still passed all five latch tests. The implementation is correct; this test would protect its documented overwrite behavior.

return !entries_.empty() && entries_.front().ready_cycle <= cycle;
}

/// @brief Remove and return the oldest entry.

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.

It would help to state here that pop() does not check readiness and callers must check ready(cycle) before a timed departure. The class describes that protocol, but this method's only listed precondition is non-emptiness, and pop() will also return an entry before its ready cycle. Making the caller's responsibility explicit beside the operation would clarify the timing contract without changing the API.

IssueQueue<std::unique_ptr<int>> queue;
queue.push(std::make_unique<int>(3), 1);
ASSERT_TRUE(queue.ready(1));
auto value = queue.pop();

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.

Please spell out std::unique_ptr<int> value = queue.pop(); here. This makes the move-only result type visible at the assertion and follows docs/style.md's rule against function-return auto when the type is not apparent on the same line.

@systems-assistant

Copy link
Copy Markdown
Contributor

TheRock Submodule Bump Activity

Newest first

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants