Skip to content

Track PHI first state per control slot#298

Open
guosran wants to merge 1 commit into
tancheng:masterfrom
guosran:fix/phi-first-state
Open

Track PHI first state per control slot#298
guosran wants to merge 1 commit into
tancheng:masterfrom
guosran:fix/phi-first-state

Conversation

@guosran

@guosran guosran commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

Summary

Addresses #292 with a minimized PHI fix. This PR only updates PhiRTL.py and its focused test.

Changes

  • Track PHI first-state independently for each control-memory slot.
  • Clear the corresponding state only after a valid PHI transaction completes.
  • Add concrete examples in the focused PHI tests.

No MemUnit changes, markdown files, new ports, or new interfaces are included.

@tancheng tancheng requested review from tancheng and yyan7223 June 22, 2026 07:04
@tancheng

Copy link
Copy Markdown
Owner

Thanks @guosran, this is the only PR that I understand what it is trying to solve. Can we provide a concrete example in the description about why we need this fix? What issue it would encounter if we don't fix it?

@tancheng

Copy link
Copy Markdown
Owner

Well, the Drop unrelated PHI PR noise actually adds MemUnit fix in this PR. Can we avoid that?

@guosran guosran force-pushed the fix/phi-first-state branch from 3548569 to 2d9163b Compare June 23, 2026 20:30
@guosran

guosran commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks @guosran, this is the only PR that I understand what it is trying to solve. Can we provide a concrete example in the description about why we need this fix? What issue it would encounter if we don't fix it?

Concrete example: two different control-memory slots can both execute PHI operations. Before this fix, PhiRTL used one shared first-state flag, so executing PHI_START/PHI_CONST in one slot could incorrectly affect whether a PHI in another slot is treated as first iteration.

Without the fix, a later PHI slot may choose the loop-carried input when it should still choose the initial/const input, or vice versa. This can corrupt the value entering the loop body.

The fix tracks first-state per control slot, so each PHI instruction has independent first-iteration state.

@guosran

guosran commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator Author

Well, the Drop unrelated PHI PR noise actually adds MemUnit fix in this PR. Can we avoid that?

The unrelated MemUnit change has been removed from this PR.

@guosran guosran force-pushed the fix/phi-first-state branch from 2d9163b to 8c6da63 Compare June 25, 2026 14:43
@guosran guosran changed the base branch from kernel-submit to master June 25, 2026 14:52
@guosran guosran marked this pull request as draft June 25, 2026 14:53
@guosran

guosran commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator Author

Concrete example:
PHI needs to select the first-state value only for the first dynamic execution.

first iteration:
first_state = 1
PHI selects init input

later iterations:
first_state = 0
PHI selects loop-carried input

@guosran guosran marked this pull request as ready for review June 26, 2026 00:32

@yyan7223 yyan7223 left a comment

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.

The proposed Track PHI first state per cotrol slot has already been implemented in the initial code, I don't understand what is this PR trying to resolve. Most of code changes are just modifying the signal name, e.g., renaming s.first[s.ctrl_addr_inport] to s.cur_first.

Besides, I agree with that OPT_PHI_START selects the value from port 0 for the first iteration, but I remember it should select the ports value with predicate = 1 in the following iterations just like OPT_PHI, rather than just select the value from port 1 regardless of its predicate. @tancheng WDYT?

Comment thread fu/single/PhiRTL.py
s.send_out[0].msg.predicate @= 0
s.recv_all_val @= ((s.first[s.ctrl_addr_inport] & s.recv_in[s.in0_idx].val) | \
(~s.first[s.ctrl_addr_inport] & s.recv_in[s.in0_idx].val & s.recv_in[s.in1_idx].val))
s.send_out[0].msg.predicate @= s.recv_in[s.in1_idx].msg.predicate & \

@yyan7223 yyan7223 Jun 27, 2026

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.

What if the loop-carried input comes from s.recv_in[s.in0_idx]? Will that happen for OPT_PHI_START?
Sorry I forget the definition of PHI_START. What's the difference between PHI_START, PHI_CONST, and PHI?

Comment thread fu/single/PhiRTL.py
s.send_to_ctrl_mem.val @= 0
s.send_to_ctrl_mem.msg @= s.CgraPayloadType(0, 0, 0, 0, 0)
s.recv_from_ctrl_mem.rdy @= 0
s.cur_first @= s.first[s.ctrl_addr_inport]

@yyan7223 yyan7223 Jun 27, 2026

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.

I think directly using s.phi_executed_first_time[s.ctrl_addr_inport] is more straightforward.

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.

3 participants