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

Set server keys for each thread in Rayon pool #171

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/fhevm-coprocessor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ on:
push:
branches:
- main
- temp-fix-coprocessor-crash
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess these changes were just for testing on the CI? Could be removed before merging, right?

Copy link
Collaborator

@0xawaz 0xawaz Dec 6, 2024

Choose a reason for hiding this comment

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

yes exactly, let's revered them before merge

paths:
- .github/workflows/fhevm-coprocessor.yml
- .github/workflows/common-docker.yml
- fhevm-engine/coprocessor/**
- fhevm-engine/scheduler/**
- fhevm-engine/.sqlx
- proto/**
release:
Expand All @@ -27,7 +29,7 @@ jobs:
packages: "write"
with:
working-directory: "."
push_image: ${{ github.event_name == 'release' || github.ref_name == 'main' }}
push_image: true
image-name: "fhevm-coprocessor"
generate-dev-image: false
docker-file: "fhevm-engine/coprocessor/Dockerfile"
Expand Down
40 changes: 26 additions & 14 deletions fhevm-engine/scheduler/src/dfg/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ impl<'a> Scheduler<'a> {

pub async fn schedule(&mut self, server_key: tfhe::ServerKey) -> Result<()> {
let schedule_type = std::env::var("FHEVM_DF_SCHEDULE");

println!("Scheduling with strategy {:?}", schedule_type);

match schedule_type {
Ok(val) => match val.as_str() {
"MAX_PARALLELISM" => {
Expand All @@ -89,11 +92,11 @@ impl<'a> Scheduler<'a> {
self.schedule_coarse_grain(PartitionStrategy::MaxLocality, server_key)
.await
}
"LOOP" => self.schedule_component_loop(server_key).await,
"LOOP" => self.schedule_component_loop(server_key),
"FINE_GRAIN" => self.schedule_fine_grain(server_key).await,
unhandled => panic!("Scheduling strategy {:?} does not exist", unhandled),
},
_ => self.schedule_component_loop(server_key).await,
_ => self.schedule_component_loop(server_key),
}
}

Expand Down Expand Up @@ -248,7 +251,7 @@ impl<'a> Scheduler<'a> {
Ok(())
}

async fn schedule_component_loop(&mut self, server_key: tfhe::ServerKey) -> Result<()> {
fn schedule_component_loop(&mut self, server_key: tfhe::ServerKey) -> Result<()> {
let mut execution_graph: Dag<ExecNode, ()> = Dag::default();
let _ = partition_components(self.graph, &mut execution_graph);
let mut comps = vec![];
Expand All @@ -268,21 +271,28 @@ impl<'a> Scheduler<'a> {
}
}

let (src, dest) = channel();
let rayon_threads = self.rayon_threads;

rayon::broadcast(|_| {
tfhe::set_server_key(server_key.clone());
});
let (src, dest) = channel();
let rayon_threads = self.rayon_threads;
comps.par_iter().for_each_with(src, |src, (args, index)| {
src.send(execute_partition(
args.to_vec(),
*index,
true,
rayon_threads,
server_key.clone(),
))
.unwrap();

// Execute computations in parallel using Rayon threadpool
tokio::task::block_in_place( move || {
comps.par_iter().for_each_with(src, |src, (args, index)| {
tfhe::set_server_key(server_key.clone());
src.send(execute_partition(
args.to_vec(),
*index,
true,
rayon_threads,
server_key.clone(),
))
.unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: Maybe we can change that to expect()? I know it is not part of the PR, but just to use that as an excuse.

});
});

let results: Vec<_> = dest.iter().collect();
for result in results {
let mut output = result?;
Expand All @@ -292,6 +302,7 @@ impl<'a> Scheduler<'a> {
self.graph[node_index].result = Some(o.1);
}
}

Ok(())
}
}
Expand Down Expand Up @@ -444,6 +455,7 @@ fn execute_partition(
}
}
}

if use_global_threadpool {
let (node_index, result) = run_computation(opcode, Ok(cts), nidx.index())?;
res.insert(node_index, result);
Expand Down
Loading