From 28553c26df3d039f19da26829be2ee55d18ec42f Mon Sep 17 00:00:00 2001 From: philsippl Date: Fri, 27 Dec 2024 14:43:38 +0100 Subject: [PATCH 1/7] reuse events --- iris-mpc-gpu/src/server/actor.rs | 59 ++++++++++++++++---------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/iris-mpc-gpu/src/server/actor.rs b/iris-mpc-gpu/src/server/actor.rs index 5dd0d0d61..8bb91ba22 100644 --- a/iris-mpc-gpu/src/server/actor.rs +++ b/iris-mpc-gpu/src/server/actor.rs @@ -1126,13 +1126,13 @@ impl ServerActor { tracing::info!(party_id = self.party_id, "Finished batch deduplication"); // ---- END BATCH DEDUP ---- - // Create new initial events - let mut current_dot_event = self.device_manager.create_events(); - let mut next_dot_event = self.device_manager.create_events(); - let mut current_exchange_event = self.device_manager.create_events(); - let mut next_exchange_event = self.device_manager.create_events(); - let mut current_phase2_event = self.device_manager.create_events(); - let mut next_phase2_event = self.device_manager.create_events(); + // Create all needed events + let current_dot_events = vec![self.device_manager.create_events(); 2]; + let next_dot_events = vec![self.device_manager.create_events(); 2]; + let current_exchange_events = vec![self.device_manager.create_events(); 2]; + let next_exchange_events = vec![self.device_manager.create_events(); 2]; + let current_phase2_events = vec![self.device_manager.create_events(); 2]; + let next_phase2_events = vec![self.device_manager.create_events(); 2]; let chunk_sizes = |chunk_idx: usize| { self.current_db_sizes @@ -1195,11 +1195,11 @@ impl ServerActor { // First stream doesn't need to wait if db_chunk_idx == 0 { self.device_manager - .record_event(request_streams, ¤t_dot_event); + .record_event(request_streams, ¤t_dot_events[db_chunk_idx % 2]); self.device_manager - .record_event(request_streams, ¤t_exchange_event); + .record_event(request_streams, ¤t_exchange_events[db_chunk_idx % 2]); self.device_manager - .record_event(request_streams, ¤t_phase2_event); + .record_event(request_streams, ¤t_phase2_events[db_chunk_idx % 2]); } // Prefetch next chunk @@ -1229,7 +1229,7 @@ impl ServerActor { ); self.device_manager - .await_event(request_streams, ¤t_dot_event); + .await_event(request_streams, ¤t_dot_events[db_chunk_idx % 2]); // ---- START PHASE 1 ---- record_stream_time!(&self.device_manager, batch_streams, events, "db_dot", { @@ -1247,7 +1247,7 @@ impl ServerActor { // wait for the exchange result buffers to be ready self.device_manager - .await_event(request_streams, ¤t_exchange_event); + .await_event(request_streams, ¤t_exchange_events[db_chunk_idx % 2]); record_stream_time!( &self.device_manager, @@ -1268,7 +1268,7 @@ impl ServerActor { ); self.device_manager - .record_event(request_streams, &next_dot_event); + .record_event(request_streams, &next_dot_events[db_chunk_idx % 2]); record_stream_time!( &self.device_manager, @@ -1286,7 +1286,7 @@ impl ServerActor { // ---- END PHASE 1 ---- self.device_manager - .await_event(request_streams, ¤t_phase2_event); + .await_event(request_streams, ¤t_phase2_events[db_chunk_idx % 2]); // ---- START PHASE 2 ---- let max_chunk_size = dot_chunk_size.iter().max().copied().unwrap(); @@ -1319,7 +1319,7 @@ impl ServerActor { // code_dots/mask_dots which are just reinterpretations of the exchange result // buffers self.device_manager - .record_event(request_streams, &next_exchange_event); + .record_event(request_streams, &next_exchange_events[db_chunk_idx % 2]); let res = self.phase2.take_result_buffer(); record_stream_time!(&self.device_manager, request_streams, events, "db_open", { @@ -1340,23 +1340,10 @@ impl ServerActor { }); } self.device_manager - .record_event(request_streams, &next_phase2_event); + .record_event(request_streams, &next_phase2_events[db_chunk_idx % 2]); // ---- END PHASE 2 ---- - // Destroy events - self.device_manager.destroy_events(current_dot_event); - self.device_manager.destroy_events(current_exchange_event); - self.device_manager.destroy_events(current_phase2_event); - - // Update events for synchronization - current_dot_event = next_dot_event; - current_exchange_event = next_exchange_event; - current_phase2_event = next_phase2_event; - next_dot_event = self.device_manager.create_events(); - next_exchange_event = self.device_manager.create_events(); - next_phase2_event = self.device_manager.create_events(); - // Increment chunk index db_chunk_idx += 1; @@ -1373,6 +1360,20 @@ impl ServerActor { self.device_manager.await_streams(&self.streams[1]); tracing::info!(party_id = self.party_id, "db search finished"); + // Destroy all events + for events in [ + current_dot_events, + next_dot_events, + current_exchange_events, + next_exchange_events, + current_phase2_events, + next_phase2_events, + ] { + for event in events { + self.device_manager.destroy_events(event); + } + } + // Reset the results buffers for reuse for dst in &[&self.results, &self.batch_results, &self.final_results] { reset_slice(self.device_manager.devices(), dst, 0xff, &self.streams[0]); From 3ea7ed53b85360489deeeae1c3638c8d10ebafb0 Mon Sep 17 00:00:00 2001 From: philsippl Date: Fri, 27 Dec 2024 14:53:13 +0100 Subject: [PATCH 2/7] assign context --- iris-mpc-gpu/src/helpers/device_manager.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/iris-mpc-gpu/src/helpers/device_manager.rs b/iris-mpc-gpu/src/helpers/device_manager.rs index fe3f7563f..4053324a4 100644 --- a/iris-mpc-gpu/src/helpers/device_manager.rs +++ b/iris-mpc-gpu/src/helpers/device_manager.rs @@ -103,8 +103,9 @@ impl DeviceManager { } pub fn destroy_events(&self, events: Vec) { - for event in events { - unsafe { event::destroy(event).unwrap() }; + for (device_idx, event) in events.iter().enumerate() { + self.device(device_idx).bind_to_thread().unwrap(); + unsafe { event::destroy(*event).unwrap() }; } } From 6e16499c53fb5fcd10b5c61a08c22fd1f332a892 Mon Sep 17 00:00:00 2001 From: philsippl Date: Fri, 27 Dec 2024 15:05:14 +0100 Subject: [PATCH 3/7] dbg --- iris-mpc-gpu/src/server/actor.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/iris-mpc-gpu/src/server/actor.rs b/iris-mpc-gpu/src/server/actor.rs index 8bb91ba22..951ca0b55 100644 --- a/iris-mpc-gpu/src/server/actor.rs +++ b/iris-mpc-gpu/src/server/actor.rs @@ -1361,18 +1361,18 @@ impl ServerActor { tracing::info!(party_id = self.party_id, "db search finished"); // Destroy all events - for events in [ - current_dot_events, - next_dot_events, - current_exchange_events, - next_exchange_events, - current_phase2_events, - next_phase2_events, - ] { - for event in events { - self.device_manager.destroy_events(event); - } - } + // for events in [ + // current_dot_events, + // next_dot_events, + // current_exchange_events, + // next_exchange_events, + // current_phase2_events, + // next_phase2_events, + // ] { + // for event in events { + // self.device_manager.destroy_events(event); + // } + // } // Reset the results buffers for reuse for dst in &[&self.results, &self.batch_results, &self.final_results] { From 3fd0b03572cc9a46f702d02ce6069fd4802c39f1 Mon Sep 17 00:00:00 2001 From: philsippl Date: Fri, 27 Dec 2024 15:18:16 +0100 Subject: [PATCH 4/7] init events once --- iris-mpc-gpu/src/server/actor.rs | 55 +++++++++++++------------------- 1 file changed, 23 insertions(+), 32 deletions(-) diff --git a/iris-mpc-gpu/src/server/actor.rs b/iris-mpc-gpu/src/server/actor.rs index 951ca0b55..1a31267a2 100644 --- a/iris-mpc-gpu/src/server/actor.rs +++ b/iris-mpc-gpu/src/server/actor.rs @@ -107,6 +107,9 @@ pub struct ServerActor { disable_persistence: bool, code_chunk_buffers: Vec, mask_chunk_buffers: Vec, + dot_events: Vec>, + exchange_events: Vec>, + phase2_events: Vec>, } const NON_MATCH_ID: u32 = u32::MAX; @@ -330,6 +333,11 @@ impl ServerActor { let code_chunk_buffers = vec![codes_engine.alloc_db_chunk_buffer(DB_CHUNK_SIZE); 2]; let mask_chunk_buffers = vec![masks_engine.alloc_db_chunk_buffer(DB_CHUNK_SIZE); 2]; + // Create all needed events + let dot_events = vec![device_manager.create_events(); 2]; + let exchange_events = vec![device_manager.create_events(); 2]; + let phase2_events = vec![device_manager.create_events(); 2]; + for dev in device_manager.devices() { dev.synchronize().unwrap(); } @@ -367,6 +375,9 @@ impl ServerActor { disable_persistence, code_chunk_buffers, mask_chunk_buffers, + dot_events, + exchange_events, + phase2_events, }) } @@ -1126,14 +1137,6 @@ impl ServerActor { tracing::info!(party_id = self.party_id, "Finished batch deduplication"); // ---- END BATCH DEDUP ---- - // Create all needed events - let current_dot_events = vec![self.device_manager.create_events(); 2]; - let next_dot_events = vec![self.device_manager.create_events(); 2]; - let current_exchange_events = vec![self.device_manager.create_events(); 2]; - let next_exchange_events = vec![self.device_manager.create_events(); 2]; - let current_phase2_events = vec![self.device_manager.create_events(); 2]; - let next_phase2_events = vec![self.device_manager.create_events(); 2]; - let chunk_sizes = |chunk_idx: usize| { self.current_db_sizes .iter() @@ -1195,11 +1198,11 @@ impl ServerActor { // First stream doesn't need to wait if db_chunk_idx == 0 { self.device_manager - .record_event(request_streams, ¤t_dot_events[db_chunk_idx % 2]); + .record_event(request_streams, &self.dot_events[db_chunk_idx % 2]); self.device_manager - .record_event(request_streams, ¤t_exchange_events[db_chunk_idx % 2]); + .record_event(request_streams, &self.exchange_events[db_chunk_idx % 2]); self.device_manager - .record_event(request_streams, ¤t_phase2_events[db_chunk_idx % 2]); + .record_event(request_streams, &self.phase2_events[db_chunk_idx % 2]); } // Prefetch next chunk @@ -1229,7 +1232,7 @@ impl ServerActor { ); self.device_manager - .await_event(request_streams, ¤t_dot_events[db_chunk_idx % 2]); + .await_event(request_streams, &self.dot_events[db_chunk_idx % 2]); // ---- START PHASE 1 ---- record_stream_time!(&self.device_manager, batch_streams, events, "db_dot", { @@ -1247,7 +1250,7 @@ impl ServerActor { // wait for the exchange result buffers to be ready self.device_manager - .await_event(request_streams, ¤t_exchange_events[db_chunk_idx % 2]); + .await_event(request_streams, &self.exchange_events[db_chunk_idx % 2]); record_stream_time!( &self.device_manager, @@ -1268,7 +1271,7 @@ impl ServerActor { ); self.device_manager - .record_event(request_streams, &next_dot_events[db_chunk_idx % 2]); + .record_event(request_streams, &self.dot_events[(db_chunk_idx + 1) % 2]); record_stream_time!( &self.device_manager, @@ -1286,7 +1289,7 @@ impl ServerActor { // ---- END PHASE 1 ---- self.device_manager - .await_event(request_streams, ¤t_phase2_events[db_chunk_idx % 2]); + .await_event(request_streams, &self.phase2_events[db_chunk_idx % 2]); // ---- START PHASE 2 ---- let max_chunk_size = dot_chunk_size.iter().max().copied().unwrap(); @@ -1318,8 +1321,10 @@ impl ServerActor { // we can now record the exchange event since the phase 2 is no longer using the // code_dots/mask_dots which are just reinterpretations of the exchange result // buffers - self.device_manager - .record_event(request_streams, &next_exchange_events[db_chunk_idx % 2]); + self.device_manager.record_event( + request_streams, + &self.exchange_events[(db_chunk_idx + 1) % 2], + ); let res = self.phase2.take_result_buffer(); record_stream_time!(&self.device_manager, request_streams, events, "db_open", { @@ -1340,7 +1345,7 @@ impl ServerActor { }); } self.device_manager - .record_event(request_streams, &next_phase2_events[db_chunk_idx % 2]); + .record_event(request_streams, &self.phase2_events[(db_chunk_idx + 1) % 2]); // ---- END PHASE 2 ---- @@ -1360,20 +1365,6 @@ impl ServerActor { self.device_manager.await_streams(&self.streams[1]); tracing::info!(party_id = self.party_id, "db search finished"); - // Destroy all events - // for events in [ - // current_dot_events, - // next_dot_events, - // current_exchange_events, - // next_exchange_events, - // current_phase2_events, - // next_phase2_events, - // ] { - // for event in events { - // self.device_manager.destroy_events(event); - // } - // } - // Reset the results buffers for reuse for dst in &[&self.results, &self.batch_results, &self.final_results] { reset_slice(self.device_manager.devices(), dst, 0xff, &self.streams[0]); From 4f8b1c6901378d829923a8d1a84f0be64f9e6fc4 Mon Sep 17 00:00:00 2001 From: Ertugrul Aypek Date: Sat, 28 Dec 2024 18:33:07 +0100 Subject: [PATCH 5/7] trigger image build --- .github/workflows/temp-branch-build-and-push.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/temp-branch-build-and-push.yaml b/.github/workflows/temp-branch-build-and-push.yaml index 678d37592..696d980ff 100644 --- a/.github/workflows/temp-branch-build-and-push.yaml +++ b/.github/workflows/temp-branch-build-and-push.yaml @@ -3,7 +3,7 @@ name: Branch - Build and push docker image on: push: branches: - - "ps/host-mem-alloc" + - "ps/reuse-events" concurrency: group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}' From cfc3ca2c988bf570c84bc734fedf06b04f4fcd27 Mon Sep 17 00:00:00 2001 From: Ertugrul Aypek Date: Sat, 28 Dec 2024 18:37:11 +0100 Subject: [PATCH 6/7] deploy test image to stage --- deploy/stage/common-values-iris-mpc.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy/stage/common-values-iris-mpc.yaml b/deploy/stage/common-values-iris-mpc.yaml index 39e7a9b19..c26a262b7 100644 --- a/deploy/stage/common-values-iris-mpc.yaml +++ b/deploy/stage/common-values-iris-mpc.yaml @@ -1,4 +1,4 @@ -image: "ghcr.io/worldcoin/iris-mpc:6b358589c25ef528f58ba02980103670b037a614" +image: "ghcr.io/worldcoin/iris-mpc:4f8b1c6901378d829923a8d1a84f0be64f9e6fc4" environment: stage replicaCount: 1 From edff5ba9a1ac3a896ebd0335a0df0e67e51db88f Mon Sep 17 00:00:00 2001 From: Ertugrul Aypek Date: Sat, 28 Dec 2024 18:59:48 +0100 Subject: [PATCH 7/7] bump stage image --- deploy/stage/common-values-iris-mpc.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy/stage/common-values-iris-mpc.yaml b/deploy/stage/common-values-iris-mpc.yaml index c26a262b7..276b120a1 100644 --- a/deploy/stage/common-values-iris-mpc.yaml +++ b/deploy/stage/common-values-iris-mpc.yaml @@ -1,4 +1,4 @@ -image: "ghcr.io/worldcoin/iris-mpc:4f8b1c6901378d829923a8d1a84f0be64f9e6fc4" +image: "ghcr.io/worldcoin/iris-mpc:v0.13.6" environment: stage replicaCount: 1