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.
impl Context
Implementation of the Context
struct.
Sourcepub fn new(device_id: u32) -> Self
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.
Sourcepub fn get(&self) -> *mut Context
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.
Sourcepub fn get_device_id(&self) -> u32
pub fn get_device_id(&self) -> u32
Sourcepub fn mem_alloc(&self, size: usize) -> *mut c_void
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
Sourcepub fn create_job(&self, num_sub: u32) -> Job
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 ofSub
§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`