pub struct Map { /* private fields */ }
Expand description
Abstracts data-parallel computation based on a map operation for a given job.
This struct wraps a FFI pointer to the C++ pxl::runtime::Map
class.
It provides methods for executing parallel processing, synchronizing operations,
and setting up asynchronous callbacks and stream.
Implementations§
Source§impl Map
Implementation of the Map
struct.
impl Map
Implementation of the Map
struct.
Sourcepub fn set_completion_callback(
&mut self,
callback: *mut c_void,
user_data: *mut c_void,
)
pub fn set_completion_callback( &mut self, callback: *mut c_void, user_data: *mut c_void, )
Sets success callback function with user data.
§Arguments
callback
- Callback function as a c_void pointer.user_data
- User data as a c_void pointer.
§Safety
Caller must ensure that the callback, user data remain valid for the lifetime of Map
.
§Example
use std::ffi::c_void;
use std::sync::{
atomic::{AtomicBool, Ordering},
Arc,
}; ///
unsafe extern "C" fn completion_callback(ptr: *mut c_void) {
let flag = ptr as *const AtomicBool;
println!("✅ Completion callback called with ptr: {:?}", flag);
(*flag).store(true, Ordering::SeqCst);
}
let done_flag = Arc::new(AtomicBool::new(false));
let done_ptr = Arc::into_raw(done_flag.clone()) as *mut c_void;
map.set_completion_callback(completion_callback as *mut c_void, done_ptr);
Sourcepub fn set_error_callback(
&mut self,
callback: *mut c_void,
user_data: *mut c_void,
)
pub fn set_error_callback( &mut self, callback: *mut c_void, user_data: *mut c_void, )
Sets error callback function with user data.
§Arguments
callback
- Callback function as ac_void
pointer.user_data
- User data as ac_void
pointer.
§Safety
Caller must ensure that the callback and user data remain valid for the lifetime of Map
.
§Example
use std::ffi::c_void;
use std::sync::{
atomic::{AtomicBool, Ordering},
Arc,
};
unsafe extern "C" fn error_callback(ptr: *mut c_void) {
let flag = ptr as *const AtomicBool;
println!("❌ Error callback called with ptr: {:?}", flag);
(*flag).store(true, Ordering::SeqCst);
}
let error_flag = Arc::new(AtomicBool::new(false));
let error_ptr = Arc::into_raw(error_flag.clone()) as *mut c_void;
map.set_error_callback(error_callback as *mut c_void, error_ptr);
Sourcepub fn set_message_callback(
&mut self,
callback: *mut c_void,
user_data: *mut c_void,
)
pub fn set_message_callback( &mut self, callback: *mut c_void, user_data: *mut c_void, )
Sets message callback function with user data.
§Arguments
callback
- Callback function as ac_void
pointer.user_data
- User data as ac_void
pointer.
§Safety
Caller must ensure that the callback and user data remain valid for the lifetime of Map
.
§Example
use std::ffi::c_void;
use std::sync::Arc;
unsafe extern "C" fn message_callback(ptr: *mut c_void) {
println!("📩 Message callback called with ptr: {:?}", ptr);
}
let message_data = Arc::new(42); // Example user data
let message_ptr = Arc::into_raw(message_data.clone()) as *mut c_void;
map.set_message_callback(message_callback as *mut c_void, message_ptr);
pub fn set_batch_size(&mut self, batch_size: &u32)
Sourcepub fn set_cluster_bitmap(&mut self, cluster_bitmap: u32)
pub fn set_cluster_bitmap(&mut self, cluster_bitmap: u32)
Sourcepub fn set_default_stream(&mut self)
pub fn set_default_stream(&mut self)
Sourcepub fn set_stream(&mut self, stream: &Stream)
pub fn set_stream(&mut self, stream: &Stream)
Sourcepub fn execute(&mut self, args: &Vec<ArgInfo_t>) -> PxlResult
pub fn execute(&mut self, args: &Vec<ArgInfo_t>) -> PxlResult
Executes with the given arguments. This is called in execute! macro.
§Arguments
args
- A vector ofArgInfo_t
objects representing the arguments to be passed.
§Returns
Execution status as a PxlResult.
§Safety
Caller must ensure that the args
vector is valid and contains valid pointers.
§Example
Please refer to usage of execute!
macro.
Sourcepub fn synchronize(&mut self) -> PxlResult
pub fn synchronize(&mut self) -> PxlResult
Sourcepub fn get_execute_status(&self) -> ExecuteStatus
pub fn get_execute_status(&self) -> ExecuteStatus
Gets the execution status of the map operation.
§Returns
ExecuteStatus
indicating the current execution status.
§Example
use pxl::ExecuteStatus;
let status = map.get_execute_status();
match status {
ExecuteStatus::ExecuteDone => println!("Execution completed successfully"),
ExecuteStatus::Fail => println!("Execution failed"),
_ => println!("Execution in progress or other status"),
}
Sourcepub fn get_kernel_error(&mut self) -> Vec<KernelError_t>
pub fn get_kernel_error(&mut self) -> Vec<KernelError_t>
Gets the error report of the map operation.
§Returns
Vec<KernelError_t>
containing the error report.
If successful, the beginIndex and endIndex will be 0xFFFFFFFF.
If unsuccessful, they indicate the range of failed task index.
§Example
let kernel_errors = map.get_kernel_error();
for error in &kernel_errors {
if error.beginIndex != 0xFFFFFFFF && error.endIndex != 0xFFFFFFFF {
println!("Error in range: {} - {}", error.beginIndex, error.endIndex);
}
}