pub struct Context {
pub driver: ZeDriverHandle,
pub device: ZeDeviceHandle,
pub context: ZeContextHandle,
pub queue: ZeCommandQueueHandle,
pub list: ZeCommandListHandle,
pub queue_ordinal: u32,
/* private fields */
}Fields§
§driver: ZeDriverHandle§device: ZeDeviceHandle§context: ZeContextHandle§queue: ZeCommandQueueHandle§list: ZeCommandListHandle§queue_ordinal: u32Command-queue-group ordinal chosen for compute. Kept for later
zeCommandListAppendLaunchKernel dispatches.
Implementations§
Source§impl Context
impl Context
Sourcepub fn new(global_ordinal: u32) -> Option<Self>
pub fn new(global_ordinal: u32) -> Option<Self>
Walk drivers + devices, pick the global_ordinal-th device in
the same order drv::enumerate produces, and bring up a
context + compute queue + list on it.
Source§impl Context
impl Context
Sourcepub fn alloc_device(
&self,
size: usize,
alignment: usize,
) -> Option<DeviceBuffer>
pub fn alloc_device( &self, size: usize, alignment: usize, ) -> Option<DeviceBuffer>
Allocate size bytes of device-local memory on this context’s
device. Returned pointer is an unmapped USM address valid for
zeCommandListAppendMemoryCopy and kernel arg binding.
Allocate size bytes of shared USM (host + device accessible).
Sourcepub fn load_spirv(&self, spirv: &[u8]) -> Option<Module>
pub fn load_spirv(&self, spirv: &[u8]) -> Option<Module>
Load a SPIR-V module onto the device.
Trait Implementations§
Source§impl ComputeDevice for Context
Unified cross-backend compute surface. code is OpenCL/SYCL-flavored
SPIR-V — the Kernel execution model, where the entry point takes its
buffers as __global pointer arguments. This is not the descriptor-bound
GLCompute SPIR-V that Vulkan’s GLSL produces: dispatch binds each buffer
as a pointer argument (zeKernelSetArgumentValue), matching how oneAPI,
ocloc, and clang -target spir64 emit compute kernels. The entry point is
assumed to be main. Buffers are shared USM, so upload/download are a
memcpy through the pointer with no staging.
impl ComputeDevice for Context
Unified cross-backend compute surface. code is OpenCL/SYCL-flavored
SPIR-V — the Kernel execution model, where the entry point takes its
buffers as __global pointer arguments. This is not the descriptor-bound
GLCompute SPIR-V that Vulkan’s GLSL produces: dispatch binds each buffer
as a pointer argument (zeKernelSetArgumentValue), matching how oneAPI,
ocloc, and clang -target spir64 emit compute kernels. The entry point is
assumed to be main. Buffers are shared USM, so upload/download are a
memcpy through the pointer with no staging.
Like Metal, Level Zero sets the group size at dispatch rather than in the
shader, so dispatch
assumes a 1-D group of 64. Use Kernel::set_group_size +
Context::launch directly for other geometries.
Source§type Buffer = DeviceBuffer
type Buffer = DeviceBuffer
Source§type Error = String
type Error = String
Debug so generic callers can surface it; the
concrete backends carry richer error types on their inherent APIs.Source§fn device_buffer(&self, bytes: u64) -> Result<DeviceBuffer, String>
fn device_buffer(&self, bytes: u64) -> Result<DeviceBuffer, String>
bytes.Source§fn upload(&self, data: &[u8]) -> Result<DeviceBuffer, String>
fn upload(&self, data: &[u8]) -> Result<DeviceBuffer, String>
data into a fresh device-local buffer and wait for the copy.
The buffer is sized to data.len().Source§fn download(&self, buffer: &DeviceBuffer, out: &mut [u8]) -> Result<(), String>
fn download(&self, buffer: &DeviceBuffer, out: &mut [u8]) -> Result<(), String>
min(out.len(), len) bytes.Source§fn pipeline(&self, code: &[u8], _bindings: u32) -> Result<Pipeline, String>
fn pipeline(&self, code: &[u8], _bindings: u32) -> Result<Pipeline, String>
code (see the module table for the per-backend format) into a
pipeline that binds bindings storage buffers at slots 0..bindings.Source§fn dispatch(
&self,
pipeline: &Pipeline,
buffers: &[&DeviceBuffer],
groups: [u32; 3],
) -> Result<(), String>
fn dispatch( &self, pipeline: &Pipeline, buffers: &[&DeviceBuffer], groups: [u32; 3], ) -> Result<(), String>
buffers to slots 0..buffers.len() and dispatch a
groups[0] × groups[1] × groups[2] grid of workgroups, then block until
it completes. buffers.len() should match the pipeline’s bindings.