Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[enhancement] Support peek() op in XLS #1383

Open
hongted opened this issue Apr 18, 2024 · 1 comment
Open

[enhancement] Support peek() op in XLS #1383

hongted opened this issue Apr 18, 2024 · 1 comment
Labels
csp Relating to Communicating Sequential Processes or Kahn Process Network style concurrency models enhancement New feature or request

Comments

@hongted
Copy link
Collaborator

hongted commented Apr 18, 2024

What's hard to do? (limit 100 words)

Often requested is a peek() op that given a streaming channel, will return the data at the head of the channel (if any) and a valid bit (true if there were data).

While both peek() and recv_non_blocking() bring us out of KPN land, peek() poses a challenge to simulation vs hardware as in simulation we do not backtrack executed instruction when blocking.

For example:

(token, data, valid) = peek(token, ch0);
(token, data0) = recv(token, ch0);

In hardware, the behavior depends on how peek and recv are scheduled. Let's say that they are scheduled in the same cycle. In this case, once the recv occurs, valid will be true and data will be equal to data0.

In an interpreter, one possible sequence of events is that the channel is empty, and peek executes --> data = 0 and valid = 0. The interpreter then blocks on recv. Once there is data on the channel, recv executes and returns data0.

In order to continue with supporting peek() operation, we should clarify and agree on the behavior of the interpreters, and how the operator is impacted by scheduling.

Current best alternative workaround (limit 100 words)

This is as opposed to the recv_non_blocking() op which will pop the data at the head of the channel if it exists.

Your view of the "best case XLS enhancement" (limit 100 words)

One idea that came out of the discussion was to implement peek and receive as a single op/expression -- so we don't need any roll-back functionality in case a receive blocks.

Proposal was something like like the following

  1. New expression: peek_and_recv_conditional(<token>, <list of channels>, <list of (bool, value) for peeked values>) : <user defined return type> { body-expression }
  2. body-expression will have available the peek'ed values of each channel and if the channel has data
  3. return of the expression will be a tuple: (<list of conditionals for each receive>, <user defined return value>).
  4. All of this expression should be scheduled together.
  5. No side-effecting ops in the body.
  6. This expression will peek the value of the channels, and determine which receive should happen. If the simulator blocks on a receive, then the simulator will roll-back to the beginning of the expression.
@hongted hongted added the enhancement New feature or request label Apr 18, 2024
@hongted
Copy link
Collaborator Author

hongted commented Apr 18, 2024

Note that peek() is generally requested to implement arbiters without the need for additional state within the block (or when the outside world uses a pop() as a signal that the arbiter chose a particular candidate).

@hongted hongted changed the title [enhancement] [enhancement] Support peek() op in XLS Apr 18, 2024
@cdleary cdleary added the csp Relating to Communicating Sequential Processes or Kahn Process Network style concurrency models label Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
csp Relating to Communicating Sequential Processes or Kahn Process Network style concurrency models enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants