pub struct AsyncExecutor { /* private fields */ }Expand description
§AsyncExecutor
The AsyncExecutor is the central engine of this library. Its job is to simplify
all the “dirty work” of OpenCL: finding the best graphics card, creating the context,
managing command queues, and distributing work intelligently.
Think of it as an orchestra conductor that decides which musicians (GPUs) play each part.
Implementations§
Source§impl AsyncExecutor
impl AsyncExecutor
Sourcepub fn new_best_platform() -> Result<Self, ClError>
pub fn new_best_platform() -> Result<Self, ClError>
Creates an executor by automatically selecting the best available platform.
It will search among all cards (NVIDIA, AMD, Intel) and choose the one with the most computing power and memory.
Sourcepub fn new_best_platform_with_options(
profiling_enabled: bool,
) -> Result<Self, ClError>
pub fn new_best_platform_with_options( profiling_enabled: bool, ) -> Result<Self, ClError>
Creates an executor with the best platform, allowing profiling to be enabled.
If profiling_enabled is true, you can measure exactly how many nanoseconds
each kernel takes to execute on the card.
pub fn new_all_platforms() -> Result<Self, ClError>
pub fn new_from_platforms(platforms: &[ClPlatform]) -> Result<Self, ClError>
pub fn new_from_devices(devices: &[ClDevice]) -> Result<Self, ClError>
pub fn new_from_devices_with_options( devices: &[ClDevice], profiling_enabled: bool, ) -> Result<Self, ClError>
pub fn is_profiling_enabled(&self) -> bool
pub fn get_context(&self) -> Arc<ClContext>
pub fn get_device_versions(&self) -> &[OpenCLVersion]
pub fn get_devices(&self) -> Result<Vec<ClDevice>, ClError>
pub fn get_queues(&self) -> &[ClCommandQueue]
Sourcepub fn create_task(&self, kernel: ClKernel) -> TaskBuilder<'_>
pub fn create_task(&self, kernel: ClKernel) -> TaskBuilder<'_>
Creates a task to be executed.
This is the entry point for the declarative workflow.
It receives a ClKernel (the function that will run on the GPU) and returns
a TaskBuilder to configure the arguments and work size.
Sourcepub fn build_program(
&self,
source: String,
options: Option<&str>,
) -> Result<ClProgram<Builded>, ClError>
pub fn build_program( &self, source: String, options: Option<&str>, ) -> Result<ClProgram<Builded>, ClError>
Compiles an OpenCL program from source code (C-like).
§Example
let source = "kernel void add(...) { ... }";
let program = executor.build_program(source.to_string(), None)?;Sourcepub fn compile_or_binary(
&self,
src_path: &str,
binary_dest_folder: &str,
options: Option<&str>,
) -> Result<ClProgram<Builded>, ClError>
pub fn compile_or_binary( &self, src_path: &str, binary_dest_folder: &str, options: Option<&str>, ) -> Result<ClProgram<Builded>, ClError>
Compiles the program or loads it from binary if available.
Checks if binaries exist in binary_dest_folder. If so, loads them.
Otherwise, compiles from src_path and saves binaries to binary_dest_folder.
Sourcepub fn create_kernel(
&self,
program: &ClProgram<Builded>,
name: &str,
) -> Result<ClKernel, ClError>
pub fn create_kernel( &self, program: &ClProgram<Builded>, name: &str, ) -> Result<ClKernel, ClError>
Creates a Kernel from an already compiled program.
The name must exactly match the name of the kernel function in your C code.
Sourcepub fn create_buffer(
&self,
flags: &[MemoryFlags],
size: usize,
host_ptr: *mut c_void,
) -> Result<ClBuffer, ClError>
pub fn create_buffer( &self, flags: &[MemoryFlags], size: usize, host_ptr: *mut c_void, ) -> Result<ClBuffer, ClError>
Creates a memory Buffer on the GPU.
Buffers are “boxes” of data that the GPU can read or write.
Sourcepub fn create_image(
&self,
flags: &[MemoryFlags],
format: &ClImageFormats,
desc: &ClImageDesc,
host_ptr: *mut c_void,
) -> Result<ClImage, ClError>
pub fn create_image( &self, flags: &[MemoryFlags], format: &ClImageFormats, desc: &ClImageDesc, host_ptr: *mut c_void, ) -> Result<ClImage, ClError>
Creates an OpenCL Image (requires OpenCL 1.2+). Images are optimized for 2D/3D access and filtering.
Sourcepub fn create_svm_buffer<T>(
&self,
flags: &[MemoryFlags],
len: usize,
) -> Result<ClSvmBuffer<T>, ClError>
pub fn create_svm_buffer<T>( &self, flags: &[MemoryFlags], len: usize, ) -> Result<ClSvmBuffer<T>, ClError>
Creates an SVM Buffer (Shared Virtual Memory). (Requires OpenCL 2.0+). Allows sharing pointers directly between CPU and GPU without manual copies.
Sourcepub async fn read_buffer<T: Sized>(
&self,
buffer: &ClBuffer,
host_memory: &mut [T],
) -> Result<ClEvent, ClError>
pub async fn read_buffer<T: Sized>( &self, buffer: &ClBuffer, host_memory: &mut [T], ) -> Result<ClEvent, ClError>
Reads data from a buffer to host memory. Uses the most powerful GPU available to perform the copy.
Sourcepub async fn write_buffer<T: Sized>(
&self,
buffer: &ClBuffer,
host_memory: &mut [T],
) -> Result<ClEvent, ClError>
pub async fn write_buffer<T: Sized>( &self, buffer: &ClBuffer, host_memory: &mut [T], ) -> Result<ClEvent, ClError>
Writes data from host memory to a buffer. Uses the most powerful GPU available to perform the copy.