-
Notifications
You must be signed in to change notification settings - Fork 33
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
Refactor the hydroflow graph API to simplify the surface API #58
Conversation
edf5c3d
to
f6b5174
Compare
ChangesSurface API
|
TODOs in the future
|
f6b5174
to
e2731db
Compare
hydroflow/src/scheduled/query.rs
Outdated
let mut sends = Vec::with_capacity(n); | ||
let mut recvs = Vec::with_capacity(n); | ||
for _ in 0..n { | ||
let (send_port, recv_port) = df.make_handoff::<VecHandoff<T>>(); | ||
sends.push(send_port); | ||
recvs.push(Operator { | ||
df: self.df.clone(), | ||
output_port, | ||
}) | ||
.collect() | ||
recv_port, | ||
}); | ||
} | ||
|
||
df.add_subgraph_n_m(vec![self.recv_port], sends, move |_ctx, recvs, sends| { | ||
let input = recvs.iter().next().unwrap().take_inner(); | ||
if let Some((&last_output, outputs)) = sends.split_last() { | ||
for output in outputs { | ||
output.give(Iter(input.iter().cloned())); | ||
} | ||
last_output.give(Iter(input.into_iter())); | ||
} | ||
}); | ||
|
||
recvs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improves the query API tee, only real change in the runtime code in this diff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a big improvement to me as far as simplicity of the code goes 👍
hydroflow/src/scheduled/graph.rs
Outdated
} | ||
|
||
pub fn add_edge<H>(&mut self, output_port: OutputPort<H>, input_port: InputPort<H>) | ||
pub fn make_handoff<H>(&mut self) -> (InputPort<H>, OutputPort<H>) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WDYT about renaming this to make_edge
? We had some conversations get mildly derailed regarding this, it's not incorrect, and might appeal to the user's intuition a little more?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it. I'm always down to rename things better, up until we stabilize (which is probably not soon)
benches/benches/reachability.rs
Outdated
@@ -130,67 +129,63 @@ fn benchmark_hydroflow_scheduled(c: &mut Criterion) { | |||
// A dataflow that represents graph reachability. | |||
let mut df = Hydroflow::new(); | |||
|
|||
let reachable_out = df.add_source(move |_ctx, send: &SendCtx<VecHandoff<usize>>| { | |||
type Hoff = VecHandoff<usize>; | |||
let (reachable_out, merge_lhs) = df.make_handoff::<Hoff>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we should have an alias for make_handoff<VecHandoff<...>>
given that (at least for now) it's almost always what we use?
impl<T: BasePortList<false>> RecvPortList for T {} | ||
|
||
#[sealed] | ||
pub trait BasePortList<const S: bool>: TypeList { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a way we can have something other than a bool
here? I don't really understand what it's doing, but could it be possible to use a trait instead? Is there a reason having a trait with a bool method marked #[inline]
is less expressive than a bool?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically we have InputPort
and OutputPort
which in terms of implementation are pretty much identically, but I want to treat them as different types since they're not interchangeably semantically. So here we just use one struct to represent both with a bool
to differentiate (true = send, false = recv).
But I want to change this to not be a bool, and be a different tag struct instead, because the bool isn't descriptive
hydroflow/src/scheduled/mod.rs
Outdated
pub mod graph; | ||
pub mod graph_demux; | ||
pub mod port; | ||
// pub mod graph_demux; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stray? either delete or add a comment explaining when this could be uncommented imo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ill add comment
fa55982
to
499626b
Compare
Now make handoffs before subgraphs (instead of the other way around).
…nference of hf.add_subgraph()
499626b
to
6c1df00
Compare
TODO(mingwei): fix trivial subgraph on L110, needs network/input methods to take in ports instead of return them.
6c1df00
to
4c69d29
Compare
Basically |
We inherited the idea that subgraphs are created first, then are linked up to each other. This works okay, but requires waiting for an input/output port pair to be connected before the handoff state can be created, resulting in awkward
Rc<RefCell<>>
passing around to link things together.This change swaps the order subgraphs/handoffs are created. Handoffs are created first and their state is immediately inserted into the hydroflow struct. Then it is up to the user to provide the already-created input/output ports when adding a new subgraph.
Rc<RefCell<>>
indirection.Example
Before:
After: