pub struct GraphCaptureGuard { /* private fields */ }Expand description
RAII guard that runs CUDA graph capture in a scoped block.
Call GraphCaptureGuard::begin (or [begin_with_mode] /
[begin_with_pool]) to start capture; calling [finish] returns
the instantiated graph. If the guard is dropped without calling
finish (for example because a kernel returned an error
mid-capture), its Drop impl best-effort-ends capture and
discards the resulting graph so the stream returns to a usable
state. CL-454.
This mirrors PyTorch’s with torch.cuda.graph(g): ... context
manager semantics in Rust’s RAII idiom.
§Example
use ferrotorch_gpu::graph::GraphCaptureGuard;
let mut guard = GraphCaptureGuard::begin(device.stream())?;
run_kernels()?; // any kernel launched on device.stream() is recorded
let graph = guard.finish()?;
graph.upload()?;
for _ in 0..1000 { graph.launch()?; }Implementations§
Source§impl GraphCaptureGuard
impl GraphCaptureGuard
Sourcepub fn begin(stream: &Arc<CudaStream>) -> GpuResult<Self>
pub fn begin(stream: &Arc<CudaStream>) -> GpuResult<Self>
Begin graph capture on stream in the default
CaptureMode::ThreadLocal mode. CL-454.
Sourcepub fn begin_with_mode(
stream: &Arc<CudaStream>,
mode: CaptureMode,
) -> GpuResult<Self>
pub fn begin_with_mode( stream: &Arc<CudaStream>, mode: CaptureMode, ) -> GpuResult<Self>
Begin graph capture with an explicit CaptureMode. CL-454.
Sourcepub fn begin_with_pool(
stream: &Arc<CudaStream>,
pool: Arc<CapturePool>,
) -> GpuResult<Self>
pub fn begin_with_pool( stream: &Arc<CudaStream>, pool: Arc<CapturePool>, ) -> GpuResult<Self>
Begin graph capture bound to a CapturePool. The pool is
attached to the resulting graph by [finish]. CL-454.
Sourcepub fn finish(self) -> GpuResult<CapturedGraph>
pub fn finish(self) -> GpuResult<CapturedGraph>
Finish capture and return the instantiated CapturedGraph.
Consumes the guard so Drop becomes a no-op. If a pool was
attached at construction, the resulting graph is produced via
end_capture_with_pool and holds the pool Arc for the
lifetime of the graph.
Sourcepub fn status(&self) -> GpuResult<CaptureStatus>
pub fn status(&self) -> GpuResult<CaptureStatus>
Report whether the stream this guard is bound to is still
actively capturing. An unexpected Invalidated or None
usually means a forbidden API call (alloc, sync, host copy)
happened under capture.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for GraphCaptureGuard
impl RefUnwindSafe for GraphCaptureGuard
impl Send for GraphCaptureGuard
impl Sync for GraphCaptureGuard
impl Unpin for GraphCaptureGuard
impl UnsafeUnpin for GraphCaptureGuard
impl UnwindSafe for GraphCaptureGuard
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more