forked from hydro-project/hydro
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hydroflow_plus): perf(true) added to HydroflowCrateService (hydr…
- Loading branch information
1 parent
23d7a8f
commit e6b6d40
Showing
20 changed files
with
373 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,5 +13,6 @@ | |
], | ||
"files.watcherExclude": { | ||
"**/target": true | ||
} | ||
}, | ||
"rust-analyzer.showUnlinkedFileNotification": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
use std::cell::RefCell; | ||
|
||
use hydroflow::futures::channel::mpsc::UnboundedSender; | ||
use stageleft::*; | ||
|
||
use crate as hydroflow_plus; | ||
use crate::ir::*; | ||
use crate::RuntimeContext; | ||
|
||
pub fn increment_counter(count: &mut u64) { | ||
*count += 1; | ||
} | ||
|
||
fn quoted_any_fn<'a, F: Fn(usize) -> usize + 'a, Q: IntoQuotedMut<'a, F>>(q: Q) -> Q { | ||
q | ||
} | ||
|
||
/// Add a profiling node before each node to count the cardinality of its input | ||
fn add_profiling_node<'a>( | ||
node: HfPlusNode, | ||
_context: RuntimeContext<'a>, | ||
counters: RuntimeData<&'a RefCell<Vec<u64>>>, | ||
counter_queue: RuntimeData<&'a RefCell<UnboundedSender<(usize, u64)>>>, | ||
id: &mut u32, | ||
seen_tees: &mut SeenTees, | ||
) -> HfPlusNode { | ||
let my_id = *id; | ||
*id += 1; | ||
|
||
let child = node.transform_children( | ||
|node, seen_tees| { | ||
add_profiling_node(node, _context, counters, counter_queue, id, seen_tees) | ||
}, | ||
seen_tees, | ||
); | ||
HfPlusNode::Map { | ||
f: quoted_any_fn(q!({ | ||
// Put counters on queue | ||
counter_queue | ||
.borrow() | ||
.unbounded_send((my_id as usize, counters.borrow()[my_id as usize])) | ||
.unwrap(); | ||
counters.borrow_mut()[my_id as usize] = 0; | ||
move |v| { | ||
hydroflow_plus::profiler::increment_counter( | ||
&mut counters.borrow_mut()[my_id as usize], | ||
); | ||
v | ||
} | ||
})) | ||
.splice() | ||
.into(), | ||
input: Box::new(child), | ||
} | ||
} | ||
|
||
/// Count the cardinality of each input and periodically output to a file | ||
pub fn profiling<'a>( | ||
ir: Vec<HfPlusLeaf>, | ||
context: RuntimeContext<'a>, | ||
counters: RuntimeData<&'a RefCell<Vec<u64>>>, | ||
counter_queue: RuntimeData<&'a RefCell<UnboundedSender<(usize, u64)>>>, | ||
) -> Vec<HfPlusLeaf> { | ||
let mut id = 0; | ||
let mut seen_tees = Default::default(); | ||
ir.into_iter() | ||
.map(|l| { | ||
l.transform_children( | ||
|node, seen_tees| { | ||
add_profiling_node(node, context, counters, counter_queue, &mut id, seen_tees) | ||
}, | ||
&mut seen_tees, | ||
) | ||
}) | ||
.collect() | ||
} | ||
|
||
#[stageleft::runtime] | ||
#[cfg(test)] | ||
mod tests { | ||
use stageleft::*; | ||
|
||
use crate::MultiGraph; | ||
|
||
#[test] | ||
fn predicate_pushdown_through_map() { | ||
let flow = crate::builder::FlowBuilder::<MultiGraph>::new(); | ||
let process = flow.process(&()); | ||
|
||
flow.source_iter(&process, q!(0..10)) | ||
.all_ticks() | ||
.map(q!(|v| v + 1)) | ||
.for_each(q!(|n| println!("{}", n))); | ||
|
||
let runtime_context = flow.runtime_context(); | ||
let built = flow.extract(); | ||
|
||
insta::assert_debug_snapshot!(&built.ir); | ||
|
||
// Print mermaid | ||
// let mut mermaid_config = WriteConfig {op_text_no_imports: true, ..Default::default()}; | ||
// for (_, ir) in built.clone().optimize_default().hydroflow_ir() { | ||
// println!("{}", ir.to_mermaid(&mermaid_config)); | ||
// } | ||
|
||
let counters = RuntimeData::new("Fake"); | ||
let counter_queue = RuntimeData::new("Fake"); | ||
|
||
let pushed_down = built | ||
.optimize_with(|ir| super::profiling(ir, runtime_context, counters, counter_queue)); | ||
|
||
insta::assert_debug_snapshot!(&pushed_down.ir); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...plus/src/snapshots/hydroflow_plus__profiler__tests__predicate_pushdown_through_map-2.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
source: hydroflow_plus/src/profiler.rs | ||
expression: "&pushed_down.ir" | ||
--- | ||
[ | ||
ForEach { | ||
f: { use crate :: __staged :: profiler :: tests :: * ; | n | println ! ("{}" , n) }, | ||
input: Map { | ||
f: { use crate :: __staged :: profiler :: * ; let counter_queue = Fake ; let my_id_copy1 = 0u32 ; let counters_copy1 = Fake ; let my_id_copy2 = 0u32 ; let counters_copy2 = Fake ; let my_id_copy3 = 0u32 ; let context = & context ; let my_id_copy4 = 0u32 ; let counters = Fake ; let my_id = 0u32 ; { counter_queue . borrow () . unbounded_send ((my_id_copy1 as usize , counters_copy1 . borrow () [my_id_copy2 as usize])) . unwrap () ; counters_copy2 . borrow_mut () [my_id_copy3 as usize] = 0 ; move | v | { hydroflow_plus :: profiler :: increment_counter (context . current_tick () , my_id_copy4 , & mut counters . borrow_mut () [my_id as usize] ,) ; v } } }, | ||
input: Map { | ||
f: { use crate :: __staged :: profiler :: tests :: * ; | v | v + 1 }, | ||
input: Map { | ||
f: { use crate :: __staged :: profiler :: * ; let counter_queue = Fake ; let my_id_copy1 = 1u32 ; let counters_copy1 = Fake ; let my_id_copy2 = 1u32 ; let counters_copy2 = Fake ; let my_id_copy3 = 1u32 ; let context = & context ; let my_id_copy4 = 1u32 ; let counters = Fake ; let my_id = 1u32 ; { counter_queue . borrow () . unbounded_send ((my_id_copy1 as usize , counters_copy1 . borrow () [my_id_copy2 as usize])) . unwrap () ; counters_copy2 . borrow_mut () [my_id_copy3 as usize] = 0 ; move | v | { hydroflow_plus :: profiler :: increment_counter (context . current_tick () , my_id_copy4 , & mut counters . borrow_mut () [my_id as usize] ,) ; v } } }, | ||
input: Persist( | ||
Map { | ||
f: { use crate :: __staged :: profiler :: * ; let counter_queue = Fake ; let my_id_copy1 = 2u32 ; let counters_copy1 = Fake ; let my_id_copy2 = 2u32 ; let counters_copy2 = Fake ; let my_id_copy3 = 2u32 ; let context = & context ; let my_id_copy4 = 2u32 ; let counters = Fake ; let my_id = 2u32 ; { counter_queue . borrow () . unbounded_send ((my_id_copy1 as usize , counters_copy1 . borrow () [my_id_copy2 as usize])) . unwrap () ; counters_copy2 . borrow_mut () [my_id_copy3 as usize] = 0 ; move | v | { hydroflow_plus :: profiler :: increment_counter (context . current_tick () , my_id_copy4 , & mut counters . borrow_mut () [my_id as usize] ,) ; v } } }, | ||
input: Source { | ||
source: Iter( | ||
{ use crate :: __staged :: profiler :: tests :: * ; 0 .. 10 }, | ||
), | ||
location_id: 0, | ||
}, | ||
}, | ||
), | ||
}, | ||
}, | ||
}, | ||
}, | ||
] |
Oops, something went wrong.