Formalizing Semantics of par
#932
Replies: 3 comments
-
|
Curious about thoughts from CIRCT folks: @mikeurbach @stephenneuendorffer @cgyurgyik |
Beta Was this translation helpful? Give feedback.
-
|
Just to summarize, some broad points here are:
So, You could bikeshed about the use of numbers as names for barriers (maybe they should be stringy symbols or declared in |
Beta Was this translation helpful? Give feedback.
-
|
@EclecticGriffin just curious–how hard would it be to implement the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
TLDR:
parblocks in Calyx currently do have well-defined guarantees on what kind of cross-thread communication is allowed. This proposal formalizes Calyx's memory models as: Data race free or nothing (DRF0) by default, and@syncannotation for communication.See Semantics of
par(#921) for background discussionDRF0 by Default
By default,
parblocks in Calyx are not allowed to "communicate" with each. Communication is defined as any possible data race between the ports of a cell or its internal state. For example, the following innocuous program is incorrect:In normal hardware design languages (HDLs), we would expect the program to swap values between
xandyafter one cycle. However, Calyx programs make no guarantees about the scheduling ofparblocks. This means that the compiler is free to assume thatg1andg2may start executing in the same cycle, or thatg1executes 100 cycles afterg2. The latter is just an egregious example but demonstrates that complete lack of guarantees thatparblocks provide.The lack of guarantees in the language model is a good thing---too many guarantees means that the compiler is limited in the kinds of optimizations it can perform.
@syncAnnotation for SynchronizationObviously, some programs do require some notion of synchronization when executing parallel threads. We propose a new annotation, called
@syncthat enables threads to declare that events other threads are visible to them.For example:
In the program above, the compiler needs to guarantee that the execution of
bcan observe the events froma(in its own thread) anddandein the second thread.However, it does not guarantee that both
bandfstart executing in the same cycle.The number
nin the@sync(n)annotation acts as the name of the barrier and can be referred to the by many different threads. Programs are free to use as many@sync(n)as needed.Well-Formedness Constraint
A required well-formedness constraint for
@syncannotations is that the same thread may not mention the same barrier in sequentially ordered events. For example, the following is allowed:Since
bandcoccur in two branches ofif, they are not sequentially ordered with respect to each other. However, the following@syncannotations are ill-formed:This is because in the first thread, execution of
aandcare sequentially ordered---amust execute beforecand therefore it is impossible forato view events beforec(which includesaitself).Optimizing with Barriers
Passes should be able to analyze the various barriers in the program and use that information to reason about ordering of execution of various groups. A simple litmus test of whether we have correctly implemented these semantics is if resource sharing can share components across various threads when it can establish specific ordering relationships.
Compiling Barriers
The compiler is responsible for reifying the barriers in the final program and maintaining their invariants. A natural choice for this is using synchronizing registers which implement M-structures useful for blocking reads and writes.
An implementation challenge is generating "multi-armed" synchronizing registers that can be referred to by many different threads.
Synchronizing with Static Time
The default
@syncprimitive only establishes an ordering between parallel threads and does not guarantee that, for example, two groups will start executing at the same time. This kind of clock-based synchronization can be useful for certain programs that do need to make use of clock-based tricks for optimizations.While we currently don't have a concrete proposal for this, here are our aspirations:
@syncannotation in conjunction to@staticto enable this kind of reasoning.Beta Was this translation helpful? Give feedback.
All reactions