From 79352b67b047a04c8c32e417f792a78c5df45686 Mon Sep 17 00:00:00 2001 From: Joe Isaacs Date: Mon, 17 Aug 2026 21:04:34 +0100 Subject: [PATCH] Skip CUDA events for default kernel launches Signed-off-by: Joe Isaacs <2413449+joseph-isaacs@users.noreply.github.com> --- vortex-cuda/src/executor.rs | 23 ++++++++++++++---- vortex-cuda/src/kernel/mod.rs | 44 ++++++++++++++++++++++------------- 2 files changed, 46 insertions(+), 21 deletions(-) diff --git a/vortex-cuda/src/executor.rs b/vortex-cuda/src/executor.rs index e5b9d057fe3..5d921cbc186 100644 --- a/vortex-cuda/src/executor.rs +++ b/vortex-cuda/src/executor.rs @@ -167,8 +167,15 @@ impl CudaExecutionCtx { let mut launcher = self.launch_builder(function); build_args(&mut launcher); - let events = launch_cuda_kernel_impl(&mut launcher, self.strategy.event_flags(), len)?; - self.strategy.on_complete(&events, len)?; + if let Some(events) = launch_cuda_kernel_impl( + &mut launcher, + self.strategy + .records_events() + .then(|| self.strategy.event_flags()), + len, + )? { + self.strategy.on_complete(&events, len)?; + } Ok(()) } @@ -187,9 +194,15 @@ impl CudaExecutionCtx { let mut launcher = self.launch_builder(function); build_args(&mut launcher); - let events = - launch_cuda_kernel_with_config(&mut launcher, cfg, self.strategy.event_flags())?; - self.strategy.on_complete(&events, len)?; + if let Some(events) = launch_cuda_kernel_with_config( + &mut launcher, + cfg, + self.strategy + .records_events() + .then(|| self.strategy.event_flags()), + )? { + self.strategy.on_complete(&events, len)?; + } Ok(()) } diff --git a/vortex-cuda/src/kernel/mod.rs b/vortex-cuda/src/kernel/mod.rs index 36735024c7f..7468969442f 100644 --- a/vortex-cuda/src/kernel/mod.rs +++ b/vortex-cuda/src/kernel/mod.rs @@ -49,6 +49,11 @@ pub trait LaunchStrategy: Debug + Send + Sync + 'static { /// Returns the event flags to use for this launch. fn event_flags(&self) -> CUevent_flags; + /// Whether this strategy records events around launches. + fn records_events(&self) -> bool { + true + } + /// Called after the kernel launch completes with the recorded events. fn on_complete(&self, events: &CudaKernelEvents, len: usize) -> VortexResult<()>; } @@ -66,6 +71,9 @@ impl LaunchStrategyExt for S { where F: FnMut() -> VortexResult<()>, { + if !self.records_events() { + return func(); + } let flags = self.event_flags(); let before = stream @@ -99,6 +107,10 @@ impl LaunchStrategy for DefaultLaunchStrategy { CUevent_flags::CU_EVENT_DISABLE_TIMING } + fn records_events(&self) -> bool { + false + } + fn on_complete(&self, _events: &CudaKernelEvents, _len: usize) -> VortexResult<()> { Ok(()) } @@ -132,15 +144,15 @@ impl LaunchStrategy for TracingLaunchStrategy { /// /// # Returns /// -/// A pair of CUDA events submitted before and after the kernel. -/// Depending on `CUevent_flags` these events can contain timestamps. Use +/// An optional pair of CUDA events submitted before and after the kernel. +/// Events are omitted when `event_flags` is `None`; otherwise they can contain timestamps. Use /// `CU_EVENT_DISABLE_TIMING` for minimal overhead and `CU_EVENT_DEFAULT` to /// enable timestamps. pub(crate) fn launch_cuda_kernel_impl( launch_builder: &mut LaunchArgs, - event_flags: CUevent_flags, + event_flags: Option, array_len: usize, -) -> VortexResult { +) -> VortexResult> { // Kernel launch configuration constants. // Must match ELEMENTS_PER_THREAD in CUDA kernels (kernels/*.cu). const THREADS_PER_BLOCK: u32 = 64; // 2 warps @@ -167,28 +179,28 @@ pub(crate) fn launch_cuda_kernel_impl( /// /// # Returns /// -/// A pair of CUDA events submitted before and after the kernel. -/// Depending on `CUevent_flags` these events can contain timestamps. Use +/// An optional pair of CUDA events submitted before and after the kernel. +/// Events are omitted when `event_flags` is `None`; otherwise they can contain timestamps. Use /// `CU_EVENT_DISABLE_TIMING` for minimal overhead and `CU_EVENT_DEFAULT` to /// enable timestamps. pub(crate) fn launch_cuda_kernel_with_config( launch_builder: &mut LaunchArgs, config: LaunchConfig, - event_flags: CUevent_flags, -) -> VortexResult { - launch_builder.record_kernel_launch(event_flags); + event_flags: Option, +) -> VortexResult> { + if let Some(event_flags) = event_flags { + launch_builder.record_kernel_launch(event_flags); + } unsafe { launch_builder .launch(config) .map_err(|e| vortex_err!("Failed to launch kernel: {}", e)) - .and_then(|events| { - events - .ok_or_else(|| vortex_err!("CUDA events not recorded")) - .map(|(before_launch, after_launch)| CudaKernelEvents { - before_launch, - after_launch, - }) + .map(|events| { + events.map(|(before_launch, after_launch)| CudaKernelEvents { + before_launch, + after_launch, + }) }) } }