Files
rustytorch/cudarc/DevicePTR.md
T
2026-03-04 00:08:42 +00:00

9.1 KiB
Raw Blame History

pub struct Profiler; Calls profiler_start() in Profiler::new(), and profiler_stop() in Drop.

Implementations Source impl Profiler Source pub fn new() -> Result<Self, DriverError> Enables profile collection by the active profiling tool for the current context. If profiling is already enabled, then Profiler::new() has no effect. More info in Cuda docs

use cudarc::driver::{Profiler};

{ let profiler = Profiler::new()?; // Hotpath // Profiler stops on drop } // Now check your results // nsys profile -c cudaProfilerApi /path/to/bin // And this will profile only the hotpath. Trait Implementations Source impl Default for Profiler Source fn default() -> Profiler Returns the “default value” for a type. Read more Source impl Drop for Profiler Source fn drop(&mut self) Executes the destructor for this type. Read more Auto Trait Implementations impl Freeze for Profiler impl RefUnwindSafe for Profiler impl Send for Profiler impl Sync for Profiler impl Unpin for Profiler impl UnwindSafe for Profiler Blanket Implementations Source impl Any for T where T: 'static + ?Sized, Source fn type_id(&self) -> TypeId Gets the TypeId of self. Read more Source impl Borrow for T where T: ?Sized, Source fn borrow(&self) -> &T Immutably borrows from an owned value. Read more Source impl BorrowMut for T where T: ?Sized, Source fn borrow_mut(&mut self) -> &mut T Mutably borrows from an owned value. Read more Source impl From for T Source fn from(t: T) -> T Returns the argument unchanged.

Source impl<T, U> Into for T where U: From, Source fn into(self) -> U Calls U::from(self).

That is, this conversion is whatever the implementation of From for U chooses to do.

Source impl<T, U> TryFrom for T where U: Into, Source type Error = Infallible The type returned in the event of a conversion error. Source fn try_from(value: U) -> Result<T, <T as TryFrom>::Error> Performs the conversion. Source impl<T, U> TryInto for T where U: TryFrom, Source type Error = <U as TryFrom>::Error The type returned in the event of a conversion error. Source fn try_into(self) -> Result<U, <U as TryFrom>::Error> Performs the conversion. Source impl<V, T> VZip for T where V: MultiLane,


Enum SyncOnDrop Copy item path Source Search Settings Help

Summary pub enum SyncOnDrop<'a> { Record(Option<(&'a CudaEvent, &'a CudaStream)>), Sync(Option<&'a CudaStream>), } A synchronization primitive to enable stream & event synchronization. Primarily used with DevicePtr and DevicePtrMut

Variants Record(Option<(&'a CudaEvent, &'a CudaStream)>) Will record the streams workload to the event on drop.

Sync(Option<&'a CudaStream>) Will call stream synchronize on drop.

Implementations Source impl<'a> SyncOnDrop<'a> Source pub fn record_event( event: &'a Option, stream: &'a CudaStream, ) -> Self Construct a SyncOnDrop::Record variant

Source pub fn sync_stream(stream: &'a CudaStream) -> Self Construct a SyncOnDrop::Sync variant

Trait Implementations Source impl<'a> Debug for SyncOnDrop<'a> Source fn fmt(&self, f: &mut Formatter<'>) -> Result Formats the value using the given formatter. Read more Source impl Drop for SyncOnDrop<'> Source fn drop(&mut self) Executes the destructor for this type. Read more Auto Trait Implementations impl<'a> Freeze for SyncOnDrop<'a> impl<'a> RefUnwindSafe for SyncOnDrop<'a> impl<'a> Send for SyncOnDrop<'a> impl<'a> Sync for SyncOnDrop<'a> impl<'a> Unpin for SyncOnDrop<'a> impl<'a> UnwindSafe for SyncOnDrop<'a> Blanket Implementations Source impl Any for T where T: 'static + ?Sized, Source impl Borrow for T where T: ?Sized, Source impl BorrowMut for T where T: ?Sized, Source impl From for T Source impl<T, U> Into for T where U: From, Source impl<T, U> TryFrom for T where U: Into, Source impl<T, U> TryInto for T where U: TryFrom, Source impl<V, T> VZip for T where V: MultiLane,


pub trait DevicePtr: DeviceSlice { // Required method fn device_ptr<'a>( &'a self, stream: &'a CudaStream, ) -> (CUdeviceptr, SyncOnDrop<'a>); } Abstraction over CudaSlice/CudaView

Required Methods Source fn device_ptr<'a>( &'a self, stream: &'a CudaStream, ) -> (CUdeviceptr, SyncOnDrop<'a>) Retrieve the device pointer with the intent to read the device memory associated with it.

Implementations of this method should ensure stream waits for any previous writes of this memory before continuing (do not need to wait for any previous reads).

The SyncOnDrop item of the return tuple should be dropped after the read of the sys::CUdeviceptr is scheduled.

In most cases you can use like:

ⓘ let (src, _record_src) = src.device_ptr(&stream); Which will drop the SyncOnDrop at the end of the scope.

Implementors Source impl DevicePtr for MappedBuffer Source impl DevicePtr for CudaSlice Source impl DevicePtr for CudaView<', T> Source impl DevicePtr for CudaViewMut<', T> Source impl DevicePtr for UnifiedSlice


pub trait DevicePtrMut: DeviceSlice { // Required method fn device_ptr_mut<'a>( &'a mut self, stream: &'a CudaStream, ) -> (CUdeviceptr, SyncOnDrop<'a>); } Abstraction over CudaSlice/CudaViewMut

Required Methods Source fn device_ptr_mut<'a>( &'a mut self, stream: &'a CudaStream, ) -> (CUdeviceptr, SyncOnDrop<'a>) Retrieve the device pointer with the intent to modify the device memory associated with it.

Implementations of this method should ensure stream waits for any previous reads/writes of this memory before continuing.

The SyncOnDrop item of the return tuple should be dropped after the write of the sys::CUdeviceptr is scheduled.

In most cases you can use like:

ⓘ let (src, _record_src) = src.device_ptr_mut(&stream); Which will drop the SyncOnDrop at the end of the scope.

Implementors Source impl DevicePtrMut for CudaSlice Source impl DevicePtrMut for CudaViewMut<'_, T> Source§ impl DevicePtrMut for UnifiedSlice


pub unsafe trait DeviceRepr { } Something that can be copied to device memory and turned into a parameter for result::launch_kernel.

Safety This is unsafe because a struct should likely be #[repr(C)] to be represented in cuda memory, and not all types are valid.

Implementations on Foreign Types Source impl DeviceRepr for bool Source impl DeviceRepr for f32 Source impl DeviceRepr for f64 Source impl DeviceRepr for i8 Source impl DeviceRepr for i16 Source impl DeviceRepr for i32 Source impl DeviceRepr for i64 Source impl DeviceRepr for i128 Source impl DeviceRepr for isize Source impl DeviceRepr for u8 Source impl DeviceRepr for u16 Source impl DeviceRepr for u32 Source impl DeviceRepr for u64 Source impl DeviceRepr for u128 Source impl DeviceRepr for usize Source impl DeviceRepr for bf16 Source§ impl DeviceRepr for f16


pub trait DeviceSlice { // Required methods fn len(&self) -> usize; fn stream(&self) -> &Arc;

// Provided methods
fn num_bytes(&self) -> usize { ... }
fn is_empty(&self) -> bool { ... }

} Base trait for abstracting over CudaSlice/CudaView/CudaViewMut.

Dont use this directly - use DevicePtr/DevicePtrMut.

Required Methods Source fn len(&self) -> usize Source fn stream(&self) -> &Arc Provided Methods Source fn num_bytes(&self) -> usize Source fn is_empty(&self) -> bool Implementors Source impl DeviceSlice for MappedBuffer Source impl DeviceSlice for CudaSlice Source impl DeviceSlice for CudaView<', T> Source impl DeviceSlice for CudaViewMut<', T> Source impl DeviceSlice for UnifiedSlice


pub trait HostSlice { // Required methods fn len(&self) -> usize; unsafe fn stream_synced_slice<'a>( &'a self, stream: &'a CudaStream, ) -> (&'a [T], SyncOnDrop<'a>); unsafe fn stream_synced_mut_slice<'a>( &'a mut self, stream: &'a CudaStream, ) -> (&'a mut [T], SyncOnDrop<'a>);

// Provided method
fn is_empty(&self) -> bool { ... }

} Abstraction over &[T], &Vec and PinnedHostSlice.

Required Methods Source fn len(&self) -> usize Source unsafe fn stream_synced_slice<'a>( &'a self, stream: &'a CudaStream, ) -> (&'a [T], SyncOnDrop<'a>) Safety This is only safe if the resulting slice is used with stream. Otherwise You may run into device synchronization errors

Source unsafe fn stream_synced_mut_slice<'a>( &'a mut self, stream: &'a CudaStream, ) -> (&'a mut [T], SyncOnDrop<'a>) Safety This is only safe if the resulting slice is used with stream. Otherwise You may run into device synchronization errors

Provided Methods Source fn is_empty(&self) -> bool Implementations on Foreign Types Source impl HostSlice for [T] Source impl HostSlice for Vec Source impl<T, const N: usize> HostSlice for [T; N] Implementors Source impl HostSlice for PinnedHostSlice Source impl HostSlice for UnifiedSlice