Struct Job

Source
pub struct Job { /* private fields */ }
Expand description

Groups compute units (Sub) within a Context to execute device kernels in parallel.

This struct wraps a FFI pointer to the C++ pxl::runtime::Job class. It provides methods for loading jobs from binary files or modules, and for creating execute interfaces(eg. Map).

Implementations§

Source§

impl Job

Implementation of the Job struct.

Source

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

gets the raw pointer of the underlying FFI Job object.

§Returns

A raw pointer to the underlying FFI Job object.

§Safety

Caller must ensure that the job is valid and that the job is properly managed.

§Example
let job = context.create_job(2); // Create a job with 2 `Sub`
let job_ptr = job.get(); // Get the raw pointer of the job
Source

pub fn load(&mut self, filename: &str) -> PxlResult

Loads a job from a MU binary file.

§Arguments
  • filename - Path to the binary file (.mubin) to load.
§Safety

Caller must ensure that filename is valid and corresponds to an actual file.

§Example
job.load("mu_kernel.mubin");
Source

pub fn load_module(&mut self, module: &Module) -> PxlResult

Loads a job from a specified Module.

§Arguments
  • module - A reference to the Module object to be executed.
§Safety

Caller must ensure that module is valid and corresponds to an actual module.

§Example
let module = pxl::create_module("tests/mu_kernel.mubin");
job.load_module(&module);
Source

pub fn is_loaded(&self) -> bool

Check whether mu binary is loaded on the job.

§Returns

True if the mu binary or module is loaded, false otherwise.

§Safety

Caller must ensure that the job is valid.

§Example
let mut job = context.create_job();
job.load("test.mubin");
assert!(job.is_loaded());
Source

pub fn sub_id_list(&self) -> Vec<u32>

Returns the list of sub IDs associated with this job.

§Returns

A vector containing the IDs of the sub associated with this job.

§Safety

Caller must ensure that the job is valid.

§Example
let job = context.create_job_with_sub(2);
let sub_ids = job.sub_id_list();
println!("Sub IDs: {:?}", sub_ids);
Source

pub fn sub_alloc(&mut self) -> PxlResult

Allocates all available subs for this job.

§Returns

PxlResult indicating the success or failure of the operation.

§Safety

Caller must ensure that the job is valid.

§Example
let mut job = context.create_job();
let result = job.sub_alloc();
assert_eq!(result, PxlResult::Success);
Source

pub fn sub_alloc_with_num(&mut self, num_sub: u32) -> PxlResult

Allocates a specified number of subs for this job.

§Arguments
  • num_sub - The number of subs to allocate.
§Returns

PxlResult indicating the success or failure of the operation.

§Safety

Caller must ensure that the job is valid and there are enough available subs.

§Example
let mut job = context.create_job();
let result = job.sub_alloc_with_num(2);
assert_eq!(result, PxlResult::Success);
Source

pub fn sub_free(&mut self)

Frees all allocated subs from this job.

§Safety

Caller must ensure that the job is valid.

§Example
let mut job = context.create_job();
job.sub_alloc();
job.sub_free();
Source

pub fn sub_free_with_num(&mut self, num_sub: u32)

Frees a specified number of subs from this job.

§Arguments
  • num_sub - The number of subs to free.
§Safety

Caller must ensure that the job is valid.

§Example
let mut job = context.create_job();
job.sub_alloc_with_num(4);
job.sub_free_with_num(2); // Free 2 subs, 2 remain allocated
Source

pub fn build_map_with_func_name( &mut self, mu_func_name: &str, test_count: u32, ) -> Map

Creates a new Map object from the job using function name.

§Arguments
  • mu_func_name - Name of the function to be executed.
  • test_count - The number of tasks to launch.
§Returns

A new Map object.

§Safety

Caller must ensure that the function name is valid.

§Example
let mut job = context.create_job();
job.load("test.mubin");
let map = job.build_map_with_func_name("myFunction", 100);
Source

pub fn build_map(&mut self, function: &Function, count: &usize) -> Map

Creates a new Map object from the job.

§Arguments
  • function - A reference to the Function to be executed.
  • count - Parallelism count (The number of tasks to launch).
§Returns

A new Map object.

§Panics

Panics if the count exceeds the range of u32.

Source

pub fn build_map_with_count(&mut self, test_count: u32) -> Map

Creates a new Map object from the job with just test count.

§Arguments
  • test_count - The number of tasks to launch.
§Returns

A new Map object.

§Example
let mut job = context.create_job();
job.load("test.mubin");
let map = job.build_map_with_count(100);
Source

pub fn destroy_map(&self, map: Map)

Destroys the Map object.

§Safety

Caller must ensure that map is valid.

§Example
job.destroy_map(map);

Auto Trait Implementations§

§

impl Freeze for Job

§

impl RefUnwindSafe for Job

§

impl !Send for Job

§

impl !Sync for Job

§

impl Unpin for Job

§

impl UnwindSafe for Job

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.