pub struct GpuContext { /* private fields */ }Expand description
GPU context for managing GPU resources and operations
Implementations§
Source§impl GpuContext
impl GpuContext
Sourcepub fn new(backend: GpuBackend) -> Result<Self, GpuError>
pub fn new(backend: GpuBackend) -> Result<Self, GpuError>
Create a new GPU context with the specified backend
Sourcepub fn backend(&self) -> GpuBackend
pub fn backend(&self) -> GpuBackend
Get the backend type
Sourcepub fn backend_name(&self) -> &str
pub fn backend_name(&self) -> &str
Get the backend name
Sourcepub fn create_buffer<T: GpuDataType>(&self, size: usize) -> GpuBuffer<T>
pub fn create_buffer<T: GpuDataType>(&self, size: usize) -> GpuBuffer<T>
Create a buffer with the given size
Sourcepub fn create_buffer_from_slice<T: GpuDataType>(
&self,
data: &[T],
) -> GpuBuffer<T>
pub fn create_buffer_from_slice<T: GpuDataType>( &self, data: &[T], ) -> GpuBuffer<T>
Create a buffer from a slice
Sourcepub fn execute<F, R>(&self, f: F) -> Rwhere
F: FnOnce(&GpuCompiler) -> R,
pub fn execute<F, R>(&self, f: F) -> Rwhere
F: FnOnce(&GpuCompiler) -> R,
Execute a function with a compiler
Sourcepub fn get_kernel(&self, name: &str) -> Result<GpuKernelHandle, GpuError>
pub fn get_kernel(&self, name: &str) -> Result<GpuKernelHandle, GpuError>
Get a kernel from the registry
Sourcepub fn get_specialized_kernel(
&self,
name: &str,
params: &KernelParams,
) -> Result<GpuKernelHandle, GpuError>
pub fn get_specialized_kernel( &self, name: &str, params: &KernelParams, ) -> Result<GpuKernelHandle, GpuError>
Get a specialized kernel from the registry
Sourcepub fn get_available_memory(&self) -> Option<usize>
pub fn get_available_memory(&self) -> Option<usize>
Get available memory on the device
Sourcepub fn get_total_memory(&self) -> Option<usize>
pub fn get_total_memory(&self) -> Option<usize>
Get total memory on the device
Sourcepub fn launch_kernel(
&self,
kernel_name: &str,
grid_size: (usize, usize, usize),
block_size: (usize, usize, usize),
args: &[DynamicKernelArg],
) -> Result<(), GpuError>
pub fn launch_kernel( &self, kernel_name: &str, grid_size: (usize, usize, usize), block_size: (usize, usize, usize), args: &[DynamicKernelArg], ) -> Result<(), GpuError>
Launch a kernel with the given parameters
Sourcepub fn transfer_async_host_to_device<T: GpuDataType>(
&self,
ptr: &GpuPtr<T>,
data: &[T],
) -> Result<(), GpuError>
pub fn transfer_async_host_to_device<T: GpuDataType>( &self, ptr: &GpuPtr<T>, data: &[T], ) -> Result<(), GpuError>
Transfer data from host to device asynchronously
Sourcepub fn transfer_host_to_device<T: GpuDataType>(
&self,
ptr: &GpuPtr<T>,
data: &[T],
) -> Result<(), GpuError>
pub fn transfer_host_to_device<T: GpuDataType>( &self, ptr: &GpuPtr<T>, data: &[T], ) -> Result<(), GpuError>
Transfer data from host to device synchronously
Sourcepub fn transfer_async_device_to_host<T: GpuDataType>(
&self,
ptr: &GpuPtr<T>,
data: &mut [T],
) -> Result<(), GpuError>
pub fn transfer_async_device_to_host<T: GpuDataType>( &self, ptr: &GpuPtr<T>, data: &mut [T], ) -> Result<(), GpuError>
Transfer data from device to host asynchronously
Sourcepub fn transfer_device_to_host<T: GpuDataType>(
&self,
ptr: &GpuPtr<T>,
data: &mut [T],
) -> Result<(), GpuError>
pub fn transfer_device_to_host<T: GpuDataType>( &self, ptr: &GpuPtr<T>, data: &mut [T], ) -> Result<(), GpuError>
Transfer data from device to host synchronously
Sourcepub fn execute_kernel(
&self,
source: &str,
buffers: &[GpuBuffer<f32>],
work_groups: (u32, u32, u32),
int_params: &[u32],
float_params: &[f32],
) -> Result<(), GpuError>
pub fn execute_kernel( &self, source: &str, buffers: &[GpuBuffer<f32>], work_groups: (u32, u32, u32), int_params: &[u32], float_params: &[f32], ) -> Result<(), GpuError>
Execute a kernel with dynamic compilation and parameter passing This method is expected by scirs2-vision for GPU operations
Sourcepub fn read_buffer<T: GpuDataType>(
&self,
buffer: &GpuBuffer<T>,
) -> Result<Vec<T>, GpuError>
pub fn read_buffer<T: GpuDataType>( &self, buffer: &GpuBuffer<T>, ) -> Result<Vec<T>, GpuError>
Read data from a GPU buffer This method is expected by scirs2-vision for reading GPU results
Auto Trait Implementations§
impl Freeze for GpuContext
impl !RefUnwindSafe for GpuContext
impl Send for GpuContext
impl Sync for GpuContext
impl Unpin for GpuContext
impl !UnwindSafe for GpuContext
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> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 moreSource§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.