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

[WIP] Documentation to diplomacy(Nodes part) #2316

Closed
wants to merge 8 commits into from

Conversation

sequencer
Copy link
Member

Related issue:
#2311

Type of change: other enhancement

Impact: no functional change

Development Phase: proposal

Release Notes

This PR is split from #2311, for the documentation to Nodes.scala

It's still a draft version, since I'm not fully understand resolveStar function.
I'm trying to reavl out this function, may luck be with me.

@mwachs5
Copy link
Contributor

mwachs5 commented Mar 12, 2020

@sequencer , how would you feel if I copied @richardxia 's documentation to this same PR and use this as the PR going forward? I think you both have complementary information and it may be easier to review at once vs trying to do them separately? If you are OK with this plan can you add the "allow edits from admins" box again?

@sequencer
Copy link
Member Author

I have added "allow edits from admins", please feel free to edit my PR:)
Sorry, I got some work on physical design these days, and I will work on this this weekend.

@mwachs5
Copy link
Contributor

mwachs5 commented Mar 12, 2020

I havae merged the changes and some minor edits from #2311 here. I suggest we close #2311 and work together on this PR.

@mwachs5
Copy link
Contributor

mwachs5 commented Mar 16, 2020

@ryoungsun here is another diplomacy doc PR

Copy link
Contributor

@mwachs5 mwachs5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, this took a while but I did a pass for english language and to better merge @sequencer and @richardxia's work.

I think we should get rid of the "master slave" information, because everything in this file can be described in terms of "upwards/downwards" and "input/output". Frankly i dont think I did a good job of doing that yet. Need to save the work though.

* Since all blocks(CPUs, caches, peripheries) are connected to bus,
* It has a very complex data flow illustrated graph below:
* ┌────────────────────────────────────────────────────────────────────────────┐
* ↓ │
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll be honest, this diagram doesn't help me much and it's kinda scary as the first thing to run into in this file...
how would you feel about removing it / moving it down / adding it back in a follow-up PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I should move it down to MixedNode, I think it’s really useful to understand behaviour of diplomacy negotiation in a detail sequence. Maybe I need to make it more detail.

*
* Is an "edge" and a binding the same thing?
*
*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Todo: ASCII art for "anatomy of a Node"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It think my scary ascii art be a "anatomy of a Node"

* - Inward refers to edges that point into a node.
* - Outward refers to edges that point out of a node.
*
* A useful mnemonic for distinguishing between inward and outward is to always
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mnemonic doesn't help me. It is like this:

                                     |------------------|
"upstream" node A ---inward edge---> |                  |
"upstream" node B ---inward edge---> | Intermediate Node| <-----  inward edge --> "downstream" node X
"upstream" node C <---outward edge-- |                  | ------- outward edge -> "downstream" node Y
                                     |------------------|

Or is the point that the above is illegal, given that you can't go "upstream" with an inward edge?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, sorry, I was having difficulty eloquently describing what finally "clicked" for me.

Your diagram is mostly what I was trying to convey, where I specifically was trying to draw attention to the fact that the "inward" and "outward" labels on those edges are only true from the perfective of that Intermediate Node. However, the edge coming out of Node A is an "outward" edge from the perspective of A.

Maybe embedding this actual ASCII diagram into the comments and specifically remarking on the inward/outward directions and different perspectives would be helpful?


To elaborate on why I found this notable enough to write documentation for, it was originally I was thinking of "inward" and "outward" of describing some more global inward and outward directions. To make a crappy, false mnemonic, if you think of the surface of the planet Earth as being "outward" and the core of the planet as being "inward", then "inward" and "outward" are global directions regardless of where you are. They are "global" in the sense that all of your neighbors will agree on those general directions.

This is exactly not the case with Diplomacy, and inward and outward are always from the perspective of you.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, i think this is really important and I feel like I still haven't fully grasped why it's important to distinguish inward/outward from Up and Down.

Are these words correct: Edges always "go" from up to down, But edge parameters flow along those directed edges BOTH up and down. As a node, an inward edge is always coming from the "up" direction, and an outward edge is always going in the "down" direction. But again you can both send and receive edge parameters in either direction on both inward and outward edges.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think a good analogy for inward/outward could be "producer/consumer", "sender-receiver".
If you draw an edge from producer->consumer, then the producer sees that as an "outward" edge and the consumer sees it as an "inward" edge. It's the same edge. The parameters will flow downwards along that edge from the producer->consumer, but consumer gets to send upwards parameters along the edge as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these words correct: Edges always "go" from up to down, But edge parameters flow along those directed edges BOTH up and down. As a node, an inward edge is always coming from the "up" direction, and an outward edge is always going in the "down" direction. But again you can both send and receive edge parameters in either direction on both inward and outward edges.

I think this is correct. I guess another way of looking at this is that the Up and Down always flow in the direction of the underlying Bundle type, whereas In and Out always flow in the direction of the parameter negotiation.

i think a good analogy for inward/outward could be "producer/consumer", "sender-receiver".

The only problem with these specific analogies is that they are tied to the underlying DAG being modeled. In TileLink, is the "producer" the node "producing requests", or is the "producer" the node producing "responses"? At some level, inward and outward are arbitrary, as you could just flip all the edges of a TileLink network and just define the edges as pointing from receiver to sender.

Copy link
Contributor

@mwachs5 mwachs5 Jul 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. the protocol gets to further decide its own naming "Master/Slave", "Producer/Consumer", "Source/Sink", "First/Second" based on the types of messages it is sending and the way it has decided to map that to the "Upwards/Downwards" direction.

Copy link
Contributor

@mwachs5 mwachs5 Jul 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating my ASCII art:

                                  |------------------|
"upstream" node A --- edge a ---> |                  |
"upstream" node B --- edge b ---> |   Current Node   | -----  edge x --> "downstream" node X
"upstream" node C ----edge c ---> |                  | ------ edge y --> "downstream" node Y
                                  |------------------|

From "Current Node"'s perspective, edge `a` is an inward edge. Edge `x` is an outward edge.
But node A sees edge a as an outward edge and node X sees edge `x` as an inward edge.

HOWEVER, parameters can flow both "up" and "down" along any edge.

From Current Node's perspective, 

The type of the parameters that flow "up" on edge a are "UI". The ones that flow down are of type "DI".
The type of the paramters that flow "down" on edge x are "DO". The ones that flow up are "UO".

Terms like "master/slave", "consumer/producer", "source/sink" are generally NOT part of diplomacy itself, but of the concrete protocols that are built on top of Diplomacy (by extending `NodeImp`). 

After negotiation, the UI+DI+DO+UO parameters on a given edge have all been resolved such that from a node's perspective, its input edges just have one parameter of type EI, and its output edge just have one parameter of type EO. 

Then during hardware construction, those EI parameters get turned into a hardware (parameterized) bundle of type BI, and the EO parameters get turned into a hardware (parameterized) bundle of type BO.

I'll suggest a change to the words here that capture this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, is your updated diagram correct? I might just not actually understand whether your previous diagram was correct or whether your new diagram is correct.

Could you change some of the "upstream" and "downstream" nodes to be flipped in order to demonstrate that nodes can be downstream yet still inward?

Actually, now I'm kind of confused about whether edges can be said to be "inward" or "outward", and whether a single edge can be both "inward" and "outward" at the same time from the perspective of a single node. From Current Node's perspective, couldn't "edge a" be inward for parameters that flow from A to Current but simultaneously outward for parameters that flow from Current to A?

Copy link
Contributor

@mwachs5 mwachs5 Jul 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Could you change some of the "upstream" and "downstream" nodes to be flipped in order to demonstrate that nodes can be downstream yet still inward?"

I don't believe that is true. I dont think my previous diagram was right.

Inward/Outward refers to the ultimately physical direction. I don't believe that a single edge can be both inward and outward at the same time from the perspective of a single node.

From Current Node's perspective, couldn't "edge a" be inward for parameters that flow from A to Current but simultaneously outward for parameters that flow from Current to A?

No. Edge a comes in to Current Node. The parameters along that edge a flow both "Upwards" and "Downwards" on that edge. Since it's an inward edge, then from Current Node's perspective, the parameters that flow DOWN on edge a are "DI" parameters. The parameters that flow UP on edge a are "UI" parameters. Nothing about edge a is "out" from Current Node's perspective.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mwachs5 @aswaterman
I have already read the diplomacy code, and lots of other stuff, But I still feel very confused about what problem the diplomacy framework can solve specificly.
Suppose we have two nodes, a source node and a sink node, they comply with TL-UL, the source node initiates an GET operation on channel A, and the sink node responded with AccessAckData on channel D. According to the diplomacy, we have to define two lazymodule. Inside each lazymodule, we define source node for the Master lazymodule, and sinknode for the slave lazymodule. also we have to implement nodeImp to conduct the specific negotiating logic. And inside the nodeImp, we have to decide the EO and EI according to the DO and UO for the source node (DI and UI for the sinknode). I know the general idea of diplomacy, but my confusion is what can we negotiate in real life? Take the source node as an example, is the DO params something related to the channel A? and the UO is some thing related to the channel D of the tile link protocol? I think the word negotiation is bilateral bargaining on something they both claim, the channel A and channel D are actually something seperated.

* - Inward refers to edges that point into a node.
* - Outward refers to edges that point out of a node.
*
* A useful mnemonic for distinguishing between inward and outward is to always
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, sorry, I was having difficulty eloquently describing what finally "clicked" for me.

Your diagram is mostly what I was trying to convey, where I specifically was trying to draw attention to the fact that the "inward" and "outward" labels on those edges are only true from the perfective of that Intermediate Node. However, the edge coming out of Node A is an "outward" edge from the perspective of A.

Maybe embedding this actual ASCII diagram into the comments and specifically remarking on the inward/outward directions and different perspectives would be helpful?


To elaborate on why I found this notable enough to write documentation for, it was originally I was thinking of "inward" and "outward" of describing some more global inward and outward directions. To make a crappy, false mnemonic, if you think of the surface of the planet Earth as being "outward" and the core of the planet as being "inward", then "inward" and "outward" are global directions regardless of where you are. They are "global" in the sense that all of your neighbors will agree on those general directions.

This is exactly not the case with Diplomacy, and inward and outward are always from the perspective of you.

Comment on lines 192 to 273
* @param pd the downward-flowing parameters into the node
* @param pu the upward-flowing parameters going out of the node
* @param p the [[Parameters]] which can be accessed by this node as needed
* @param sourceInfo [[SourceInfo]] of this edge
* @return an inward edge of this node
Copy link
Contributor

@mwachs5 mwachs5 Jul 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param pd the downward-flowing parameters into the node
* @param pu the upward-flowing parameters going out of the node
* @param p the [[Parameters]] which can be accessed by this node as needed
* @param sourceInfo [[SourceInfo]] of this edge
* @return an inward edge of this node
* @param pd the downward-flowing parameters into the node along the edge
* @param pu the upward-flowing parameters going out of the node along the edge
* @param p the [[Parameters]] which can be accessed by this node as needed
* @param sourceInfo [[SourceInfo]] of this edge
* @return an inward edge of this node

*
* The default behavior is to just return [[pu]].
*
* @param pu parameters flowing upwards
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param pu parameters flowing upwards
* @param pu parameters flowing upwards to "mix in"

* The default behavior is to just return [[pu]].
*
* @param pu parameters flowing upwards
* @param node node to "mix" the parameters with
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param node node to "mix" the parameters with
* @param node [[InwardNode]] to "mix" the parameters with

@sequencer sequencer force-pushed the diplomacy_node_doc branch 2 times, most recently from 3cde7d8 to 1b67268 Compare July 8, 2020 07:01
@mwachs5
Copy link
Contributor

mwachs5 commented Jul 9, 2020

I think @sequencer plans to:

  1. Make a PR that separates this file (in its current form on master) into (a) the NodeImp/binding stuff and (b) the different abstract node types (SourceNode, etc).
  2. Make this PR focus on the documentation for (a)
  3. Make another PR to focus on the documentation for (b)

This would help both 2 and 3 get through faster, I think.

@sequencer sequencer force-pushed the diplomacy_node_doc branch from 7678c35 to fe6caa3 Compare July 9, 2020 17:37
@sequencer
Copy link
Member Author

sequencer commented Jul 9, 2020

Thanks @mwachs5 for the explanation,
Rewrite the parameter propagation flow takes me too much time, sorry for that.
I almost finish general Nodes.scala documentations.
Remain questions are:

  1. flexibleArityDirection/edgeArityDirection/edgeAritySelect
  2. iForward/oForward/iTrace/oTrace

def outputs: Seq[(BaseNode, RenderedEdge)]

/** @todo
* [[MixedAdapterNode]] will be true, otherwise will be false
*/
protected[diplomacy] def flexibleArityDirection: Boolean = false
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't understand what arity direction means?
I can only see it is overwritten in MixedAdapterNode

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Arity" is a word that essentially means "number of" in a few different areas of mathematics and computer science.

When talking about functions, it means the number of arguments to the function. When talking about graphs, it's usually about the number if edges coming out (or going in) to a node. I'm not specifically familiar with this code, so I don't know the specific meaning, but you should be able to figure it out from reading where it is used.

protected[diplomacy] val oPortMapping: Seq[(Int, Int)]

/** @todo */
protected[diplomacy] def oForward(x: Int): Option[(Int, OutwardNode[DO, UO, BO])] = None
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, oForward and iForward are only used in EphemeralNode

val iSum = iBindings.map { case (_, n, b, _, _) => b match {
case BIND_ONCE => 1
case BIND_FLEX => edgeAritySelect(n, n.oStar, iStar)
case BIND_QUERY => n.oStar
case BIND_STAR => iStar }}.scanLeft(0)(_+_)
/** @todo [[oTotal]] and [[iTotal]] is not used. */
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these two codes are not used.

sequencer and others added 5 commits July 16, 2020 08:27
Co-Authored-By: Jack Koenig <koenig@sifive.com>
Co-authored-by: Megan Wachs <megan@sifive.com>
Co-authored-by: Richard Xia <richardxia@richardxia.com>
@sequencer sequencer force-pushed the diplomacy_node_doc branch from 47178e8 to cb06c23 Compare July 16, 2020 08:29
@sequencer sequencer marked this pull request as draft July 17, 2020 23:11
Comment on lines +147 to +148
* - Upward refers to a flow of parameters in the outward direction.
* - Downward refers to a flow of parameters in the inward direction.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of inward/outward here is kind of confusing, since we want to distinguish between up/down versus in/out.

@sequencer
Copy link
Member Author

#2604

@sequencer sequencer closed this Aug 23, 2020
@sequencer sequencer deleted the diplomacy_node_doc branch November 18, 2020 03:53
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.

5 participants