pub struct Program { /* private fields */ }Expand description
Abstraction that contains everything to run an OpenCL kernel on a GPU.
The majority of methods are the same as crate::cuda::Program, so you can write code using this
API, which will then work with OpenCL as well as CUDA kernels.
Implementations§
Source§impl Program
impl Program
Sourcepub fn device_name(&self) -> &str
pub fn device_name(&self) -> &str
Returns the name of the GPU, e.g. “GeForce RTX 3090”.
Sourcepub fn from_opencl(device: &Device, src: &str) -> Result<Program, GPUError>
pub fn from_opencl(device: &Device, src: &str) -> Result<Program, GPUError>
Creates a program for a specific device from OpenCL source code.
Sourcepub fn from_binary(device: &Device, bin: Vec<u8>) -> Result<Program, GPUError>
pub fn from_binary(device: &Device, bin: Vec<u8>) -> Result<Program, GPUError>
Creates a program for a specific device from a compiled OpenCL binary.
Sourcepub unsafe fn create_buffer<T>(
&self,
length: usize,
) -> Result<Buffer<T>, GPUError>
pub unsafe fn create_buffer<T>( &self, length: usize, ) -> Result<Buffer<T>, GPUError>
Creates a new buffer that can be used for input/output with the GPU.
The length is the number of elements to create.
It is usually used to create buffers that are initialized by the GPU. If you want to
directly transfer data from the host to the GPU, you would use the safe
Program::create_buffer_from_slice instead.
§Safety
This function isn’t actually unsafe, it’s marked as unsafe due to the CUDA version of it,
where it is unsafe. This is done to have symmetry between both APIs.
Sourcepub fn create_buffer_from_slice<T>(
&self,
slice: &[T],
) -> Result<Buffer<T>, GPUError>
pub fn create_buffer_from_slice<T>( &self, slice: &[T], ) -> Result<Buffer<T>, GPUError>
Creates a new buffer on the GPU and initializes with the given slice.
Sourcepub fn create_kernel(
&self,
name: &str,
global_work_size: usize,
local_work_size: usize,
) -> Result<Kernel<'_>, GPUError>
pub fn create_kernel( &self, name: &str, global_work_size: usize, local_work_size: usize, ) -> Result<Kernel<'_>, GPUError>
Returns a kernel.
The global_work_size does not follow the OpenCL definition. It is not the total
number of threads. Instead it follows CUDA’s definition and is the number of
local_work_size sized thread groups. So the total number of threads is
global_work_size * local_work_size.
Sourcepub fn write_from_buffer<T>(
&self,
buffer: &mut Buffer<T>,
data: &[T],
) -> Result<(), GPUError>
pub fn write_from_buffer<T>( &self, buffer: &mut Buffer<T>, data: &[T], ) -> Result<(), GPUError>
Puts data from an existing buffer onto the GPU.
Sourcepub fn read_into_buffer<T>(
&self,
buffer: &Buffer<T>,
data: &mut [T],
) -> Result<(), GPUError>
pub fn read_into_buffer<T>( &self, buffer: &Buffer<T>, data: &mut [T], ) -> Result<(), GPUError>
Reads data from the GPU into an existing buffer.