Struct Map

Source
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.

Source

pub fn get(&self) -> *mut Map

gets the raw pointer of the underlying FFI Map object.

Source

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);
Source

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 a c_void pointer.
  • user_data - User data as a c_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);
Source

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 a c_void pointer.
  • user_data - User data as a c_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);
Source

pub fn set_batch_size(&mut self, batch_size: &u32)

Source

pub fn set_cluster_bitmap(&mut self, cluster_bitmap: u32)

Sets the cluster bitmap for the map operation.

§Arguments
  • cluster_bitmap - The cluster bitmap to be used for the map operation (default = 0xF).
§Example
map.set_cluster_bitmap(0xF); // Use all clusters
Source

pub fn set_default_stream(&mut self)

Sets the stream to the default stream.

§Example
map.set_default_stream()?;
Source

pub fn set_stream(&mut self, stream: &Stream)

Sets the Stream for Map object.

§Arguments
  • stream - A reference to the Stream object to be set.
§Example
let stream = pxl::runtime::create_stream();
map.set_stream(&stream);
Source

pub fn stream_id(&self) -> u32

Returns the stream ID that the map operation is associated with.

§Returns

The stream ID as a u32.

§Example
let stream_id = map.stream_id();
println!("Current stream ID: {}", stream_id);
Source

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 of ArgInfo_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.

Source

pub fn synchronize(&mut self) -> PxlResult

Synchronizes the Map operation after execute request.

§Returns

Synchronization status as a PxlResult.

§Safety

Caller must ensure that execution status returned from execute is valid.

§Example
let ret = map.synchronize();
Source

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"),
}
Source

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);
    }
}

Auto Trait Implementations§

§

impl Freeze for Map

§

impl RefUnwindSafe for Map

§

impl !Send for Map

§

impl !Sync for Map

§

impl Unpin for Map

§

impl UnwindSafe for Map

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

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<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.