Struct Context

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

Represents a specific device context to execute jobs.

This struct wraps a FFI pointer to the C++ pxl::runtime::Context class. It provides methods for managing device-specific execution contexts, allocating memory, and creating jobs for execution.

Implementations§

Source§

impl Context

Implementation of the Context struct.

Source

pub fn new(device_id: u32) -> Self

Creates a new Context wrapper from the specified device ID. This is called in runtime wrapper APIs requiring actual Context object.

§Arguments
  • device_id - ID of the device for which the context is created.
§Panics

This function will panic if the context creation fails (e.g., if the returned pointer is null).

§Safety

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

Source

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

Returns a raw pointer to the underlying FFI Context object. This is called in runtime wrapper APIs requiring a raw pointer.

§Safety

Caller must ensure that FFI object is valid.

Source

pub fn get_device_id(&self) -> u32

Retrieves the device ID associated with this context.

§Returns

Device ID as a u32.

§Safety

Caller must ensure that the context is valid.

§Example
let context = Context::new(0);
let device_id = context.get_device_id();
println!("Device ID: {}", device_id);
Source

pub fn mem_alloc(&self, size: usize) -> *mut c_void

Allocates memory of the specified size in the context.

§Arguments
  • size - The size of the memory to allocate, in bytes.
§Returns

A raw pointer to the allocated memory.

§Safety

Caller must ensure that the context is valid and that the memory is properly managed.

§Example
let context = Context::new(0);
let memory = context.mem_alloc(1024); // Allocate 1024 bytes
Source

pub fn create_job(&self, num_sub: u32) -> Job

Creates a new job in the context with the specified number of Sub

§Arguments
  • num_sub - The number of Sub
§Returns

A Job object representing the newly created job.

§Safety

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

§Example
let context = Context::new(0);
let job = context.create_job(2); // Create a job with 2 `Sub`

Auto Trait Implementations§

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.