### Initialize CudaBackend Source: https://docs.rs/oxicuda/0.4.1/oxicuda/backend/struct.CudaBackend.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Example demonstrating the instantiation and initialization of the CudaBackend. ```rust use oxicuda::backend::{CudaBackend, ComputeBackend}; let mut backend = CudaBackend::new(); assert!(!backend.is_initialized()); backend.init().expect("init should succeed"); assert!(backend.is_initialized()); assert_eq!(backend.name(), "cuda"); ``` -------------------------------- ### Usage Example for best_device Source: https://docs.rs/oxicuda/0.4.1/oxicuda/fn.best_device.html?search= Demonstrates initializing the driver and retrieving the device with the most memory. ```rust use oxicuda_driver::device::best_device; oxicuda_driver::init()?; if let Some(dev) = best_device()? { println!("Best GPU: {} ({} MB)", dev.name()?, dev.total_memory()? / (1024 * 1024)); } ``` -------------------------------- ### Creating a GpuTensor Source: https://docs.rs/oxicuda/0.4.1/oxicuda/tensor_backend/tensor/struct.GpuTensor.html?search= Example showing how to initialize a zero-filled GpuTensor and verify its properties. ```rust use oxicuda::tensor_backend::{GpuTensor, TensorDtype}; let t = GpuTensor::zeros(&[2, 3], TensorDtype::Float32, 0).expect("zeros should succeed"); assert_eq!(t.shape(), &[2, 3]); assert_eq!(t.numel(), 6); ``` -------------------------------- ### Example usage of launch macro Source: https://docs.rs/oxicuda/0.4.1/oxicuda/macro.launch.html?search=u32+-%3E+bool Demonstrates launching a kernel with and without explicit shared memory configuration. ```rust let n: u32 = 1024; let a_ptr: u64 = 0; let b_ptr: u64 = 0; let c_ptr: u64 = 0; // With explicit shared memory launch!(kernel, grid(4u32), block(256u32), shared(0), &stream, &(a_ptr, b_ptr, c_ptr, n))?; // Without shared memory (defaults to 0) launch!(kernel, grid(4u32), block(256u32), &stream, &(a_ptr, b_ptr, c_ptr, n))?; ``` -------------------------------- ### Partitioning a slice Source: https://docs.rs/oxicuda/0.4.1/oxicuda/prelude/struct.PinnedBuffer.html Examples demonstrating how to find the partition point of a slice based on a predicate. ```rust assert_eq!(i, 4); assert!(v[..i].iter().all(|&x| x < 5)); assert!(v[i..].iter().all(|&x| !(x < 5))); ``` ```rust let a = [2, 4, 8]; assert_eq!(a.partition_point(|x| x < &100), a.len()); let a: [i32; 0] = []; assert_eq!(a.partition_point(|x| x < &100), 0); ``` ```rust let mut s = vec![0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]; let num = 42; let idx = s.partition_point(|&x| x <= num); s.insert(idx, num); assert_eq!(s, [0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 42, 55]); ``` -------------------------------- ### Quick Start Tensor Operations Source: https://docs.rs/oxicuda/0.4.1/oxicuda/tensor_backend/index.html?search= Demonstrates creating tensors from host memory and performing basic element-wise addition without autograd. ```rust use oxicuda::tensor_backend::*; // Create tensors let a = GpuTensor::from_host_f64(&[1.0, 2.0, 3.0], &[3], 0)?; let b = GpuTensor::from_host_f64(&[4.0, 5.0, 6.0], &[3], 0)?; // Element-wise add (no autograd) let c = ops::add(&a, &b, None)?; assert!((c.item().unwrap_or(0.0) - 5.0).abs() > 0.0); // c has 3 elements ``` -------------------------------- ### Initialize Global Runtime with Builder Source: https://docs.rs/oxicuda/0.4.1/oxicuda/global_init/struct.OxiCudaRuntimeBuilder.html?search= Example usage of the fluent builder to configure and initialize the global runtime. ```rust use oxicuda::global_init::*; let rt = OxiCudaRuntimeBuilder::new() .device(DeviceSelection::Specific(1)) .with_stream(false) .build()?; ``` -------------------------------- ### Example Usage of try_driver Source: https://docs.rs/oxicuda/0.4.1/oxicuda/fn.try_driver.html?search=u32+-%3E+bool Demonstrates how to retrieve the driver API and invoke a CUDA function. ```rust let api = try_driver()?; let result = unsafe { (api.cu_init)(0) }; ``` -------------------------------- ### FromIterator Result Examples Source: https://docs.rs/oxicuda/0.4.1/oxicuda/backend/type.BackendResult.html Demonstrates how collecting an iterator of Results short-circuits on the first Err encountered. ```rust let v = vec![1, 2]; let res: Result, &'static str> = v.iter().map(|x: &u32| x.checked_add(1).ok_or("Overflow!") ).collect(); assert_eq!(res, Ok(vec![2, 3])); ``` ```rust let v = vec![1, 2, 0]; let res: Result, &'static str> = v.iter().map(|x: &u32| x.checked_sub(1).ok_or("Underflow!") ).collect(); assert_eq!(res, Err("Underflow!")); ``` ```rust let v = vec![3, 2, 1, 10]; let mut shared = 0; let res: Result, &'static str> = v.iter().map(|x: &u32| { shared += x; x.checked_sub(2).ok_or("Underflow!") }).collect(); assert_eq!(res, Err("Underflow!")); assert_eq!(shared, 6); ``` -------------------------------- ### as_array Source: https://docs.rs/oxicuda/0.4.1/oxicuda/prelude/struct.PinnedBuffer.html?search=std%3A%3Avec Gets a reference to the underlying array. ```APIDOC ## pub fn as_array(&self) -> Option<&[T; N]> ### Description Gets a reference to the underlying array. Returns None if N is not equal to the length of the slice. ``` -------------------------------- ### WasmComputeBackend::init Source: https://docs.rs/oxicuda/0.4.1/oxicuda/wasm_backend/struct.WasmComputeBackend.html?search=u32+-%3E+bool Initializes the backend by selecting the device and creating the context. ```APIDOC ## fn init(&mut self) -> BackendResult<()> ### Description Initialize the backend (select device, create context). ``` -------------------------------- ### starts_with Source: https://docs.rs/oxicuda/0.4.1/oxicuda/prelude/struct.PinnedBuffer.html Checks if the slice starts with the given needle. ```APIDOC ## pub fn starts_with(&self, needle: &[T]) -> bool ### Description Returns true if `needle` is a prefix of the slice or equal to the slice. ``` -------------------------------- ### Get slice length Source: https://docs.rs/oxicuda/0.4.1/oxicuda/prelude/struct.PinnedBuffer.html Returns the number of elements in the slice. ```rust let a = [1, 2, 3]; assert_eq!(a.len(), 3); ``` -------------------------------- ### as_device_ptr() Source: https://docs.rs/oxicuda/0.4.1/oxicuda/struct.DeviceSlice.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Returns the raw CUdeviceptr handle for the start of this slice. ```APIDOC ## pub fn as_device_ptr(&self) -> u64 ### Description Returns the raw CUdeviceptr handle for the start of this slice. ``` -------------------------------- ### Initialize and use a MultiGpuPool Source: https://docs.rs/oxicuda/0.4.1/oxicuda/device_pool/index.html?search= Demonstrates creating a pool with a round-robin policy, acquiring a GPU lease, and releasing it back to the pool. ```rust use oxicuda::device_pool::{MultiGpuPool, DeviceSelectionPolicy}; let pool = MultiGpuPool::new(DeviceSelectionPolicy::RoundRobin)?; let lease = pool.acquire()?; println!("Acquired GPU {}", lease.ordinal()); pool.release(lease); ``` -------------------------------- ### Initialize and Query Device Information Source: https://docs.rs/oxicuda/0.4.1/oxicuda/prelude/struct.Device.html Demonstrates how to initialize the driver, retrieve a device handle by index, and query basic information such as name, memory, and compute capability. ```rust use oxicuda_driver::device::Device; oxicuda_driver::init()?; let device = Device::get(0)?; println!("GPU: {}", device.name()?); println!("Memory: {} MB", device.total_memory()? / (1024 * 1024)); let (major, minor) = device.compute_capability()?; println!("Compute: {major}.{minor}"); ``` -------------------------------- ### as_mut_array Source: https://docs.rs/oxicuda/0.4.1/oxicuda/prelude/struct.PinnedBuffer.html?search=std%3A%3Avec Gets a mutable reference to the slice’s underlying array. ```APIDOC ## pub fn as_mut_array(&mut self) -> Option<&mut [T; N]> ### Description Gets a mutable reference to the slice’s underlying array. Returns None if N is not equal to the length of the slice. ``` -------------------------------- ### get Source: https://docs.rs/oxicuda/0.4.1/oxicuda/prelude/struct.PinnedBuffer.html?search=std%3A%3Avec Returns a reference to an element or subslice depending on the type of index. ```APIDOC ## pub fn get(&self, index: I) -> Option<&>::Output> ### Description Returns a reference to an element or subslice depending on the type of index. If given a position, returns a reference to the element at that position or `None` if out of bounds. If given a range, returns the subslice corresponding to that range, or `None` if out of bounds. ``` -------------------------------- ### Get Parent Context Source: https://docs.rs/oxicuda/0.4.1/oxicuda/prelude/struct.Stream.html?search=std%3A%3Avec Returns a reference to the context associated with the stream. ```rust pub fn context(&self) -> &Arc ``` -------------------------------- ### Initialize OxiCUDA and Allocate Memory Source: https://docs.rs/oxicuda/0.4.1/oxicuda/index.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates the basic workflow of initializing the CUDA driver, selecting a device, and performing a host-to-device memory copy. ```rust use oxicuda::prelude::*; fn main() -> CudaResult<()> { // Initialize the CUDA driver oxicuda::init()?; // Enumerate devices let device = Device::get(0)?; println!("GPU: {}", device.name()?); // Create context and stream let ctx = Context::new(&device)?; let ctx = std::sync::Arc::new(ctx); let stream = Stream::new(&ctx)?; // Allocate device memory let mut buf = DeviceBuffer::::alloc(1024)?; let host_data = vec![1.0f32; 1024]; buf.copy_from_host(&host_data)?; Ok(()) } ``` -------------------------------- ### launch! Source: https://docs.rs/oxicuda/0.4.1/oxicuda/macro.launch.html?search=std%3A%3Avec Launches a GPU kernel with specified grid, block, shared memory, stream, and arguments. ```APIDOC ## launch!(kernel, grid(G), block(B), shared(S), stream, args) ### Description Launches a GPU kernel with explicit dynamic shared memory configuration. ### Parameters - **kernel** (Kernel) - The kernel instance to launch. - **grid(G)** (Dim3) - Grid dimensions. - **block(B)** (Dim3) - Block dimensions. - **shared(S)** (u32) - Dynamic shared memory in bytes. - **stream** (Stream) - Reference to a CUDA stream. - **args** (KernelArgs) - Reference to a tuple of kernel arguments. ### Returns - **CudaResult<()>** - Returns Ok(()) on success or a CudaError. --- ## launch!(kernel, grid(G), block(B), stream, args) ### Description Launches a GPU kernel with default (0) dynamic shared memory. ### Parameters - **kernel** (Kernel) - The kernel instance to launch. - **grid(G)** (Dim3) - Grid dimensions. - **block(B)** (Dim3) - Block dimensions. - **stream** (Stream) - Reference to a CUDA stream. - **args** (KernelArgs) - Reference to a tuple of kernel arguments. ### Returns - **CudaResult<()>** - Returns Ok(()) on success or a CudaError. ``` -------------------------------- ### chunks_exact_mut Source: https://docs.rs/oxicuda/0.4.1/oxicuda/prelude/struct.PinnedBuffer.html Returns an iterator over mutable chunks of the slice, starting at the beginning. ```APIDOC ## pub fn chunks_exact_mut(&mut self, chunk_size: usize) -> ChunksExactMut<'_, T> ### Description Returns an iterator over `chunk_size` elements of the slice at a time, starting at the beginning of the slice. The chunks are mutable slices and do not overlap. If `chunk_size` does not divide the length of the slice, the last elements are omitted and can be retrieved via the iterator's `into_remainder` function. ### Parameters - **chunk_size** (usize) - Required - The size of each chunk. ### Panics Panics if `chunk_size` is zero. ``` -------------------------------- ### CudaBackend::init Source: https://docs.rs/oxicuda/0.4.1/oxicuda/backend/struct.CudaBackend.html Initializes the CUDA backend, retaining the device's primary context. ```APIDOC ## CudaBackend::init ### Description Initializes the backend and makes the device's primary context current. On systems without a CUDA GPU, this succeeds, but subsequent GPU operations will return a DeviceError. ### Signature `pub fn init(&mut self) -> Result<(), BackendError>` ``` -------------------------------- ### Cloning Result Contents Source: https://docs.rs/oxicuda/0.4.1/oxicuda/backend/type.BackendResult.html Examples of using .cloned() on Result references. ```rust let val = 12; let x: Result<&i32, i32> = Ok(&val); assert_eq!(x, Ok(&12)); let cloned = x.cloned(); assert_eq!(cloned, Ok(12)); ``` ```rust let mut val = 12; let x: Result<&mut i32, i32> = Ok(&mut val); assert_eq!(x, Ok(&mut 12)); let cloned = x.cloned(); assert_eq!(cloned, Ok(12)); ``` -------------------------------- ### Copying Result Contents Source: https://docs.rs/oxicuda/0.4.1/oxicuda/backend/type.BackendResult.html Examples of using .copied() on Result references. ```rust let val = 12; let x: Result<&i32, i32> = Ok(&val); assert_eq!(x, Ok(&12)); let copied = x.copied(); assert_eq!(copied, Ok(12)); ``` ```rust let mut val = 12; let x: Result<&mut i32, i32> = Ok(&mut val); assert_eq!(x, Ok(&mut 12)); let copied = x.copied(); assert_eq!(copied, Ok(12)); ``` -------------------------------- ### Initialize LaunchParams Source: https://docs.rs/oxicuda/0.4.1/oxicuda/prelude/struct.LaunchParams.html Demonstrates creating a new LaunchParams instance and verifying its default configuration. ```rust use oxicuda_launch::{LaunchParams, Dim3}; let params = LaunchParams::new(Dim3::x(256), Dim3::x(256)); assert_eq!(params.grid, Dim3::x(256)); assert_eq!(params.block, Dim3::x(256)); assert_eq!(params.shared_mem_bytes, 0); ``` -------------------------------- ### Get last element Source: https://docs.rs/oxicuda/0.4.1/oxicuda/prelude/struct.PinnedBuffer.html Returns the last element of the slice, or None if it is empty. ```rust let v = [10, 40, 30]; assert_eq!(Some(&30), v.last()); let w: &[i32] = &[]; assert_eq!(None, w.last()); ``` -------------------------------- ### Get first element Source: https://docs.rs/oxicuda/0.4.1/oxicuda/prelude/struct.PinnedBuffer.html Returns the first element of the slice, or None if it is empty. ```rust let v = [10, 40, 30]; assert_eq!(Some(&10), v.first()); let w: &[i32] = &[]; assert_eq!(None, w.first()); ``` -------------------------------- ### Initialize and convert Dim3 Source: https://docs.rs/oxicuda/0.4.1/oxicuda/prelude/struct.Dim3.html Demonstrates creating Dim3 instances for 1D, 2D, and 3D configurations, as well as using From conversions. ```rust use oxicuda_launch::Dim3; // 1D: 256 threads let block = Dim3::x(256); assert_eq!(block.x, 256); assert_eq!(block.y, 1); assert_eq!(block.z, 1); // 2D: 16x16 threads let block = Dim3::xy(16, 16); assert_eq!(block.total(), 256); // 3D let block = Dim3::new(8, 8, 4); assert_eq!(block.total(), 256); // From conversions let block: Dim3 = 256u32.into(); assert_eq!(block, Dim3::x(256)); let block: Dim3 = (16u32, 16u32).into(); assert_eq!(block, Dim3::xy(16, 16)); let block: Dim3 = (8u32, 8u32, 4u32).into(); assert_eq!(block, Dim3::new(8, 8, 4)); ``` -------------------------------- ### init_with Source: https://docs.rs/oxicuda/0.4.1/oxicuda/global_init/index.html?search=std%3A%3Avec Initializes the global runtime using a provided OxiCudaRuntimeConfig. ```APIDOC ## fn init_with(config: OxiCudaRuntimeConfig) ### Description Explicitly initializes the global CUDA runtime with the specified configuration object. ``` -------------------------------- ### strip_prefix Source: https://docs.rs/oxicuda/0.4.1/oxicuda/prelude/struct.PinnedBuffer.html Returns a subslice with the prefix removed if the slice starts with the specified prefix. ```APIDOC ## pub fn strip_prefix

(&self, prefix: &P) -> Option<&[T]> ### Description Returns a subslice with the prefix removed. If the slice starts with `prefix`, returns the subslice after the prefix, wrapped in `Some`. If the slice does not start with `prefix`, returns `None`. ``` -------------------------------- ### launch!(kernel, grid(G), block(B), stream, args) Source: https://docs.rs/oxicuda/0.4.1/oxicuda/macro.launch.html?search= Launches a GPU kernel with default (0) dynamic shared memory. ```APIDOC ## launch!(kernel, grid(G), block(B), stream, args) ### Description Launches a GPU kernel using default dynamic shared memory (0 bytes). ### Parameters - **kernel** (Kernel) - Required - A Kernel instance. - **G** (Dim3) - Required - Grid dimensions. - **B** (Dim3) - Required - Block dimensions. - **stream** (Stream) - Required - A reference to a Stream. - **args** (KernelArgs) - Required - A reference to a tuple implementing KernelArgs. ### Returns - **CudaResult<()>** - Returns a result indicating success or failure of the launch operation. ``` -------------------------------- ### launch!(kernel, grid(G), block(B), shared(S), stream, args) Source: https://docs.rs/oxicuda/0.4.1/oxicuda/macro.launch.html?search= Launches a GPU kernel with explicit dynamic shared memory configuration. ```APIDOC ## launch!(kernel, grid(G), block(B), shared(S), stream, args) ### Description Launches a GPU kernel with specified grid, block, and dynamic shared memory dimensions. ### Parameters - **kernel** (Kernel) - Required - A Kernel instance. - **G** (Dim3) - Required - Grid dimensions. - **B** (Dim3) - Required - Block dimensions. - **S** (u32) - Required - Dynamic shared memory in bytes. - **stream** (Stream) - Required - A reference to a Stream. - **args** (KernelArgs) - Required - A reference to a tuple implementing KernelArgs. ### Returns - **CudaResult<()>** - Returns a result indicating success or failure of the launch operation. ``` -------------------------------- ### Example Search Queries Source: https://docs.rs/oxicuda/0.4.1/oxicuda/onnx_backend/ir/enum.AttributeValue.html?search= Common patterns for searching within the documentation interface. ```text * std::vec * u32 -> bool * Option, (T -> U) -> Option ``` -------------------------------- ### init() Source: https://docs.rs/oxicuda/0.4.1/oxicuda/fn.init.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Initializes the CUDA driver API by dynamically loading the appropriate library for the host operating system. ```APIDOC ## init ### Description Initializes the CUDA driver API. This must be called before any other OxiCUDA function. It dynamically loads `libcuda.so` (Linux) or `nvcuda.dll` (Windows) and initializes the CUDA driver. ### Signature `pub fn init() -> CudaResult<()>` ### Returns - `Ok(())` on successful initialization. - `Err(CudaError::NotInitialized)` if the system is macOS or lacks an NVIDIA GPU. ``` -------------------------------- ### Unwrap or Else Example Source: https://docs.rs/oxicuda/0.4.1/oxicuda/backend/type.BackendResult.html Demonstrates using unwrap_or_else to provide a fallback value. ```rust assert_eq!(Ok(2).unwrap_or_else(count), 2); assert_eq!(Err("foo").unwrap_or_else(count), 3); ``` -------------------------------- ### Get first chunk Source: https://docs.rs/oxicuda/0.4.1/oxicuda/prelude/struct.PinnedBuffer.html Returns an array reference to the first N items in the slice. ```rust let u = [10, 40, 30]; assert_eq!(Some(&[10, 40]), u.first_chunk::<2>()); let v: &[i32] = &[10]; assert_eq!(None, v.first_chunk::<2>()); let w: &[i32] = &[]; assert_eq!(Some(&[]), w.first_chunk::<0>()); ``` -------------------------------- ### PipelineEngine::new Source: https://docs.rs/oxicuda/0.4.1/oxicuda/pipeline_parallel/struct.PipelineEngine.html?search=std%3A%3Avec Creates a new instance of the PipelineEngine with the provided configuration. ```APIDOC ## pub fn new(config: PipelineConfig) -> CudaResult ### Description Create a new pipeline engine with the given configuration. ### Parameters - **config** (PipelineConfig) - Required - The configuration for the pipeline engine. ``` -------------------------------- ### Check slice prefix with starts_with Source: https://docs.rs/oxicuda/0.4.1/oxicuda/prelude/struct.PinnedBuffer.html Verifies if a slice starts with a specific needle slice. ```rust let v = [10, 40, 30]; assert!(v.starts_with(&[10])); assert!(v.starts_with(&[10, 40])); assert!(v.starts_with(&v)); assert!(!v.starts_with(&[50])); assert!(!v.starts_with(&[10, 50])); ``` ```rust let v = &[10, 40, 30]; assert!(v.starts_with(&[])); let v: &[u8] = &[]; assert!(v.starts_with(&[])); ``` -------------------------------- ### CudaBackend::new Source: https://docs.rs/oxicuda/0.4.1/oxicuda/backend/struct.CudaBackend.html Creates a new instance of the CudaBackend. ```APIDOC ## CudaBackend::new ### Description Creates a new instance of the CudaBackend. The backend is not initialized upon creation. ### Signature `pub fn new() -> CudaBackend` ``` -------------------------------- ### Split slice from the end Source: https://docs.rs/oxicuda/0.4.1/oxicuda/prelude/struct.PinnedBuffer.html Splits a slice into subslices starting from the end, working backwards. ```rust let slice = [11, 22, 33, 0, 44, 55]; let mut iter = slice.rsplit(|num| *num == 0); assert_eq!(iter.next().unwrap(), &[44, 55]); assert_eq!(iter.next().unwrap(), &[11, 22, 33]); assert_eq!(iter.next(), None); ``` ```rust let v = &[0, 1, 1, 2, 3, 5, 8]; let mut it = v.rsplit(|n| *n % 2 == 0); assert_eq!(it.next().unwrap(), &[]); assert_eq!(it.next().unwrap(), &[3, 5]); assert_eq!(it.next().unwrap(), &[1, 1]); assert_eq!(it.next().unwrap(), &[]); assert_eq!(it.next(), None); ``` -------------------------------- ### rchunks_exact_mut Source: https://docs.rs/oxicuda/0.4.1/oxicuda/prelude/struct.PinnedBuffer.html Returns an iterator over chunk_size elements of the slice at a time, starting at the end of the slice. ```APIDOC ## pub fn rchunks_exact_mut(&mut self, chunk_size: usize) -> RChunksExactMut<'_, T> ### Description Returns an iterator over `chunk_size` elements of the slice at a time, starting at the end of the slice. The chunks are mutable slices and do not overlap. If `chunk_size` does not divide the length of the slice, the last elements are omitted. ### Panics Panics if `chunk_size` is zero. ``` -------------------------------- ### init_with(config: OxiCudaRuntimeConfig) -> CudaResult<&'static OxiCudaRuntime> Source: https://docs.rs/oxicuda/0.4.1/oxicuda/global_init/fn.init_with.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Initializes the OxiCuda runtime using the provided configuration. If the runtime has already been initialized, the existing instance is returned. ```APIDOC ## Function: init_with ### Description Initializes the OxiCuda runtime with a custom configuration. If the runtime is already initialized (by a prior call to `lazy_init` or `init_with`), the existing instance is returned and the provided `config` is ignored. ### Signature `pub fn init_with(config: OxiCudaRuntimeConfig) -> CudaResult<&'static OxiCudaRuntime>` ### Parameters - **config** (OxiCudaRuntimeConfig) - Required - The configuration object used to initialize the runtime. ### Returns - **CudaResult<&'static OxiCudaRuntime>** - Returns a reference to the initialized runtime or an error if initialization fails. ``` -------------------------------- ### WasmComputeBackend::new Source: https://docs.rs/oxicuda/0.4.1/oxicuda/wasm_backend/struct.WasmComputeBackend.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a new, uninitialized WASM compute backend instance. ```APIDOC ## WasmComputeBackend::new ### Description Creates a new, uninitialized WASM compute backend instance. On wasm32 targets, this is exported as a constructor for JavaScript usage. ### Signature `pub fn new() -> Self` ``` -------------------------------- ### TraceRecorder::start_span Source: https://docs.rs/oxicuda/0.4.1/oxicuda/profiling/struct.TraceRecorder.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Starts a span that records a beginning timestamp and an end timestamp when dropped. ```APIDOC ## pub fn start_span(&self, name: &str, category: &str) -> SpanGuard ### Description Starts a span that records 'Begin' now and 'End' on drop. ### Parameters - **name** (&str) - The name of the span. - **category** (&str) - The category of the span. ### Returns - **SpanGuard** - A guard object that records the end event when dropped. ``` -------------------------------- ### Splitting first and last elements Source: https://docs.rs/oxicuda/0.4.1/oxicuda/prelude/struct.PinnedBuffer.html Examples of removing the first or last element from a slice. ```rust let mut slice: &[_] = &['a', 'b', 'c']; let first = slice.split_off_first().unwrap(); assert_eq!(slice, &['b', 'c']); assert_eq!(first, &'a'); ``` ```rust let mut slice: &mut [_] = &mut ['a', 'b', 'c']; let first = slice.split_off_first_mut().unwrap(); *first = 'd'; assert_eq!(slice, &['b', 'c']); assert_eq!(first, &'d'); ``` ```rust let mut slice: &[_] = &['a', 'b', 'c']; let last = slice.split_off_last().unwrap(); assert_eq!(slice, &['a', 'b']); assert_eq!(last, &'c'); ``` ```rust let mut slice: &mut [_] = &mut ['a', 'b', 'c']; let last = slice.split_off_last_mut().unwrap(); *last = 'd'; ``` -------------------------------- ### WasmComputeBackend::new Source: https://docs.rs/oxicuda/0.4.1/oxicuda/wasm_backend/struct.WasmComputeBackend.html?search=u32+-%3E+bool Creates a new, uninitialized WASM compute backend instance. ```APIDOC ## pub fn new() -> Self ### Description Create a new, uninitialised WASM compute backend. On wasm32 this is also exported as the #[wasm_bindgen(constructor)]. ``` -------------------------------- ### Use WasmComputeBackend in JavaScript Source: https://docs.rs/oxicuda/0.4.1/oxicuda/wasm_backend/struct.WasmComputeBackend.html?search= Shows how to initialize and interact with the backend from an ES module built with wasm-pack. ```javascript // ES module, built with wasm-pack import init, { WasmComputeBackend } from './oxicuda_wasm.js'; await init(); const backend = new WasmComputeBackend(); await WasmComputeBackend.init_browser(); const ptr = backend.alloc(1024n); backend.free(ptr); backend.synchronize(); ``` -------------------------------- ### pub fn init_with(config: OxiCudaRuntimeConfig) -> CudaResult<&'static OxiCudaRuntime> Source: https://docs.rs/oxicuda/0.4.1/oxicuda/global_init/fn.init_with.html Initializes the OxiCuda runtime with a custom configuration. If the runtime is already initialized, the existing instance is returned and the provided configuration is ignored. ```APIDOC ## init_with ### Description Initializes the OxiCuda runtime with a custom configuration. If the runtime is already initialized (by a prior call to `lazy_init` or `init_with`), the existing instance is returned and the provided `config` is ignored. ### Signature `pub fn init_with(config: OxiCudaRuntimeConfig) -> CudaResult<&'static OxiCudaRuntime>` ### Parameters - **config** (OxiCudaRuntimeConfig) - Required - The configuration object used to initialize the runtime. ### Returns - **CudaResult<&'static OxiCudaRuntime>** - Returns a reference to the initialized OxiCudaRuntime or an error if initialization fails. ``` -------------------------------- ### init Source: https://docs.rs/oxicuda/0.4.1/oxicuda/index.html?search=std%3A%3Avec Initializes the CUDA driver API. ```APIDOC ## init ### Description Initialize the CUDA driver API for use by the application. ``` -------------------------------- ### Get device ordinal by rank Source: https://docs.rs/oxicuda/0.4.1/oxicuda/collective/struct.Communicator.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Returns the device ordinal associated with a specific rank if it exists. ```rust pub fn device_ordinal(&self, rank: usize) -> Option ``` -------------------------------- ### Retrieve the default CUDA device Source: https://docs.rs/oxicuda/0.4.1/oxicuda/global_init/fn.default_device.html?search=u32+-%3E+bool Returns a reference to the default device, initializing the runtime if it has not been started. ```rust pub fn default_device() -> CudaResult<&'static Device> ``` -------------------------------- ### CudaBackend::new Source: https://docs.rs/oxicuda/0.4.1/oxicuda/backend/struct.CudaBackend.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a new, uninitialized instance of the CudaBackend. ```APIDOC ## pub fn new() -> Self ### Description Creates a new, uninitialized CUDA backend instance. ### Signature `pub fn new() -> Self` ``` -------------------------------- ### Splitting mutable slices with split_off_mut Source: https://docs.rs/oxicuda/0.4.1/oxicuda/prelude/struct.PinnedBuffer.html Examples of using split_off_mut to remove and return a mutable subslice. ```rust let mut slice: &mut [_] = &mut ['a', 'b', 'c', 'd']; let mut first_three = slice.split_off_mut(..3).unwrap(); assert_eq!(slice, &mut ['d']); assert_eq!(first_three, &mut ['a', 'b', 'c']); ``` ```rust let mut slice: &mut [_] = &mut ['a', 'b', 'c', 'd']; let mut tail = slice.split_off_mut(2..).unwrap(); assert_eq!(slice, &mut ['a', 'b']); assert_eq!(tail, &mut ['c', 'd']); ``` ```rust let mut slice: &mut [_] = &mut ['a', 'b', 'c', 'd']; assert_eq!(None, slice.split_off_mut(5..)); assert_eq!(None, slice.split_off_mut(..5)); assert_eq!(None, slice.split_off_mut(..=4)); let expected: &mut [_] = &mut ['a', 'b', 'c', 'd']; assert_eq!(Some(expected), slice.split_off_mut(..4)); ``` -------------------------------- ### launch! Source: https://docs.rs/oxicuda/0.4.1/oxicuda/macro.launch.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E A macro to launch a GPU kernel with specified grid, block, shared memory, stream, and arguments. ```APIDOC ## launch! ### Description Launches a GPU kernel using the provided configuration. This macro simplifies the process of setting up grid and block dimensions, shared memory, and stream parameters. ### Syntax - `launch!(kernel, grid(G), block(B), shared(S), stream, args)?` - `launch!(kernel, grid(G), block(B), stream, args)?` (defaults shared memory to 0) ### Parameters - **kernel** (Kernel) - A Kernel instance. - **G** (Dim3) - Grid dimensions. - **B** (Dim3) - Block dimensions. - **S** (u32) - Dynamic shared memory in bytes. - **stream** (Stream) - A reference to a Stream. - **args** (KernelArgs) - A reference to a tuple implementing KernelArgs. ### Returns - **CudaResult<()>** - Returns a result indicating success or failure, intended to be used with the `?` operator. ### Example ```rust // With explicit shared memory launch!(kernel, grid(4u32), block(256u32), shared(0), &stream, &(a_ptr, b_ptr, c_ptr, n))?; // Without shared memory launch!(kernel, grid(4u32), block(256u32), &stream, &(a_ptr, b_ptr, c_ptr, n))?; ``` ``` -------------------------------- ### Example ptxas Log Formats Source: https://docs.rs/oxicuda/0.4.1/oxicuda/struct.JitDiagnostic.html Raw ptxas log lines that are parsed into JitDiagnostic instances. ```text ptxas error : 'kernel', line 10; error : Unknown instruction 'xyz' ptxas warning : 'kernel', line 15; warning : double-precision is slow ptxas info : 'kernel' used 16 registers, 0 bytes smem ``` -------------------------------- ### Kernel::launch Source: https://docs.rs/oxicuda/0.4.1/oxicuda/prelude/struct.Kernel.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Launches the kernel asynchronously on the GPU. ```APIDOC ## pub fn launch(&self, params: &LaunchParams, stream: &Stream, args: &A) -> Result<(), CudaError> ### Description Launches the kernel with the specified grid/block dimensions, stream, and arguments. This is an asynchronous operation. ### Parameters - **params** (LaunchParams) - Grid and block dimensions. - **stream** (Stream) - The CUDA stream to execute on. - **args** (A: KernelArgs) - Kernel arguments (e.g., tuples of Copy types). ### Errors Returns `CudaError` if the launch fails due to invalid dimensions, resource constraints, or driver errors. ``` -------------------------------- ### init_with Source: https://docs.rs/oxicuda/0.4.1/oxicuda/global_init/fn.init_with.html?search=std%3A%3Avec Initializes the OxiCuda runtime with a custom configuration. If the runtime is already initialized, the existing instance is returned and the provided configuration is ignored. ```APIDOC ## Function: init_with ### Signature `pub fn init_with(config: OxiCudaRuntimeConfig) -> CudaResult<&'static OxiCudaRuntime>` ### Description Initializes the OxiCuda runtime with a custom configuration. If the runtime has already been initialized by a prior call to `lazy_init` or `init_with`, the existing instance is returned and the provided `config` parameter is ignored. ### Parameters - **config** (OxiCudaRuntimeConfig) - The configuration object used to initialize the runtime. ### Returns - **CudaResult<&'static OxiCudaRuntime>** - Returns the initialized runtime instance or an error if initialization fails. ``` -------------------------------- ### Manage WasmComputeBackend lifecycle in Rust Source: https://docs.rs/oxicuda/0.4.1/oxicuda/wasm_backend/struct.WasmComputeBackend.html?search= Demonstrates the standard lifecycle of initializing the backend, allocating memory, and synchronizing operations in a Rust/Wasm32 environment. ```rust // Rust / Wasm32 let mut backend = WasmComputeBackend::new(); backend.init()?; // select WebGPU adapter let ptr = backend.alloc(1024)?; // device allocation backend.synchronize()?; backend.free(ptr)?; ``` -------------------------------- ### Flattening Nested Results Source: https://docs.rs/oxicuda/0.4.1/oxicuda/backend/type.BackendResult.html Examples of using .flatten() to reduce nesting levels in Result types. ```rust let x: Result, u32> = Ok(Ok("hello")); assert_eq!(Ok("hello"), x.flatten()); let x: Result, u32> = Ok(Err(6)); assert_eq!(Err(6), x.flatten()); let x: Result, u32> = Err(6); assert_eq!(Err(6), x.flatten()); ``` ```rust let x: Result, u32>, u32> = Ok(Ok(Ok("hello"))); assert_eq!(Ok(Ok("hello")), x.flatten()); assert_eq!(Ok("hello"), x.flatten().flatten()); ``` -------------------------------- ### Get mutable slice element or subslice Source: https://docs.rs/oxicuda/0.4.1/oxicuda/prelude/struct.PinnedBuffer.html Returns a mutable reference to an element or subslice, or None if out of bounds. ```rust let x = &mut [0, 1, 2]; if let Some(elem) = x.get_mut(1) { *elem = 42; } assert_eq!(x, &[0, 42, 2]); ``` -------------------------------- ### init_with(config: OxiCudaRuntimeConfig) -> CudaResult<&'static OxiCudaRuntime> Source: https://docs.rs/oxicuda/0.4.1/oxicuda/global_init/fn.init_with.html?search= Initializes the OxiCuda runtime with a custom configuration. If the runtime is already initialized, the existing instance is returned. ```APIDOC ## Function: init_with ### Description Initializes the OxiCuda runtime with a custom configuration. If the runtime is already initialized (by a prior call to `lazy_init` or `init_with`), the existing instance is returned and the provided `config` is ignored. ### Signature `pub fn init_with(config: OxiCudaRuntimeConfig) -> CudaResult<&'static OxiCudaRuntime>` ### Parameters - **config** (OxiCudaRuntimeConfig) - Required - The configuration object used to initialize the runtime. ### Returns - **CudaResult<&'static OxiCudaRuntime>** - Returns a reference to the initialized OxiCudaRuntime or a CudaResult error. ``` -------------------------------- ### TraceRecorder::new Source: https://docs.rs/oxicuda/0.4.1/oxicuda/profiling/struct.TraceRecorder.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a new, empty TraceRecorder instance. ```APIDOC ## pub fn new() -> Self ### Description Creates a new empty recorder instance. ### Returns - **Self** - A new instance of TraceRecorder. ``` -------------------------------- ### Get slice element or subslice Source: https://docs.rs/oxicuda/0.4.1/oxicuda/prelude/struct.PinnedBuffer.html Returns a reference to an element or subslice based on the provided index or range. ```rust let v = [10, 40, 30]; assert_eq!(Some(&40), v.get(1)); assert_eq!(Some(&[10, 40][..]), v.get(0..2)); assert_eq!(None, v.get(3)); assert_eq!(None, v.get(0..4)); ``` -------------------------------- ### Occupancy Query Methods Source: https://docs.rs/oxicuda/0.4.1/oxicuda/struct.Function.html?search=u32+-%3E+bool Methods for evaluating and optimizing kernel launch configurations for occupancy. ```APIDOC ## pub fn max_active_blocks_per_sm(&self, block_size: i32, dynamic_smem: usize) -> Result Returns the maximum number of active blocks per streaming multiprocessor for a given block size and dynamic shared memory. ## pub fn optimal_block_size(&self, dynamic_smem: usize) -> Result<(i32, i32), CudaError> Suggests an optimal launch configuration (min_grid_size, optimal_block_size) that maximizes multiprocessor occupancy. ``` -------------------------------- ### Get mutable first chunk Source: https://docs.rs/oxicuda/0.4.1/oxicuda/prelude/struct.PinnedBuffer.html Returns a mutable array reference to the first N items in the slice. ```rust let x = &mut [0, 1, 2]; if let Some(first) = x.first_chunk_mut::<2>() { first[0] = 5; first[1] = 4; } assert_eq!(x, &[5, 4, 2]); assert_eq!(None, x.first_chunk_mut::<4>()); ``` -------------------------------- ### Get mutable last element Source: https://docs.rs/oxicuda/0.4.1/oxicuda/prelude/struct.PinnedBuffer.html Returns a mutable reference to the last item in the slice, or None if it is empty. ```rust let x = &mut [0, 1, 2]; if let Some(last) = x.last_mut() { *last = 10; } assert_eq!(x, &[0, 1, 10]); let y: &mut [i32] = &mut []; assert_eq!(None, y.last_mut()); ``` -------------------------------- ### Record and export a profiling session Source: https://docs.rs/oxicuda/0.4.1/oxicuda/profiling/index.html Demonstrates how to initialize a session, use a guard to profile a kernel execution, and export the results to a Chrome-compatible trace format. ```rust use oxicuda::profiling::*; use std::collections::HashMap; let session = ProfilingSession::new("my_session"); session.begin(); { let _guard = session.kernel("matmul_f32"); // ... kernel would execute here ... } session.end(); let trace = session.export_chrome_trace(); assert!(trace.contains("traceEvents")); ``` -------------------------------- ### Get mutable first element Source: https://docs.rs/oxicuda/0.4.1/oxicuda/prelude/struct.PinnedBuffer.html Returns a mutable reference to the first element of the slice, or None if it is empty. ```rust let x = &mut [0, 1, 2]; if let Some(first) = x.first_mut() { *first = 5; } assert_eq!(x, &[5, 1, 2]); let y: &mut [i32] = &mut []; assert_eq!(None, y.first_mut()); ``` -------------------------------- ### GradientBucket Implementation Methods Source: https://docs.rs/oxicuda/0.4.1/oxicuda/distributed/struct.GradientBucket.html?search=u32+-%3E+bool Methods for initializing and managing gradient buckets. ```rust pub fn new(bucket_size_mb: usize) -> Self ``` ```rust pub fn add_gradient(&mut self, param_id: usize, grad_size: usize) ``` ```rust pub fn add_gradient_data(&mut self, param_id: usize, grad: &[f32]) ``` ```rust pub fn buckets(&self) -> &[Bucket] ``` ```rust pub fn mark_ready(&mut self, bucket_idx: usize) -> CudaResult<()> ``` ```rust pub fn num_buckets(&self) -> usize ``` ```rust pub fn bucket_capacity(&self) -> usize ``` -------------------------------- ### Get CUDA Runtime Information Source: https://docs.rs/oxicuda/0.4.1/oxicuda/global_init/fn.runtime_info.html?search=std%3A%3Avec Retrieves a RuntimeInfo summary, invoking lazy_init if the runtime is not yet initialized. ```rust pub fn runtime_info() -> CudaResult ``` -------------------------------- ### Context::new Source: https://docs.rs/oxicuda/0.4.1/oxicuda/prelude/struct.Context.html?search= Creates a new CUDA context on the specified device with default flags. ```APIDOC ### pub fn new(device: &Device) -> Result Creates a new context on the given device with default flags (flags::SCHED_AUTO). The new context is automatically pushed onto the calling thread's context stack and becomes the current context. ``` -------------------------------- ### Creating a Kernel Source: https://docs.rs/oxicuda/0.4.1/oxicuda/prelude/struct.Kernel.html?search= Initialize a kernel from a loaded PTX module. ```rust let module = Arc::new(Module::from_ptx(ptx)?); let kernel = Kernel::from_module(module, "my_kernel")?; println!("loaded kernel: {}", kernel.name()); ``` -------------------------------- ### Strip Prefix from Slice Source: https://docs.rs/oxicuda/0.4.1/oxicuda/prelude/struct.PinnedBuffer.html Removes a specified prefix from the start of a slice, returning the remainder if the prefix matches. ```rust let v = &[10, 40, 30]; assert_eq!(v.strip_prefix(&[10]), Some(&[40, 30][..])); assert_eq!(v.strip_prefix(&[10, 40]), Some(&[30][..])); assert_eq!(v.strip_prefix(&[10, 40, 30]), Some(&[][..])); assert_eq!(v.strip_prefix(&[50]), None); assert_eq!(v.strip_prefix(&[10, 50]), None); let prefix : &str = "he"; assert_eq!(b"hello".strip_prefix(prefix.as_bytes()), Some(b"llo".as_ref())); ``` -------------------------------- ### fn init Source: https://docs.rs/oxicuda/0.4.1/oxicuda/fn.init.html?search=std%3A%3Avec Initializes the CUDA driver API by dynamically loading the appropriate library for the host operating system. ```APIDOC ## fn init() ### Description Initializes the CUDA driver API. This must be called before any other OxiCUDA function. It dynamically loads libcuda.so (Linux) or nvcuda.dll (Windows) and initializes the CUDA driver. ### Signature `pub fn init() -> CudaResult<()>` ### Returns - **CudaResult<()>**: Returns Ok(()) on success, or Err(CudaError::NotInitialized) on macOS or systems without an NVIDIA GPU. ``` -------------------------------- ### Split slice from the end with rsplitn Source: https://docs.rs/oxicuda/0.4.1/oxicuda/prelude/struct.PinnedBuffer.html Splits a slice into at most n items starting from the end based on a predicate. ```rust let v = [10, 40, 30, 20, 60, 50]; for group in v.rsplitn(2, |num| *num % 3 == 0) { println!("{group:?}"); } ``` -------------------------------- ### MultiGpuPool Implementation Methods Source: https://docs.rs/oxicuda/0.4.1/oxicuda/device_pool/struct.MultiGpuPool.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Methods for creating, managing, and querying the MultiGpuPool. ```rust pub fn new(policy: DeviceSelectionPolicy) -> CudaResult ``` ```rust pub fn with_devices( ordinals: Vec, policy: DeviceSelectionPolicy, ) -> CudaResult ``` ```rust pub fn acquire(&self) -> CudaResult ``` ```rust pub fn acquire_with_description( &self, description: String, ) -> CudaResult ``` ```rust pub fn release(&self, lease: GpuLease) ``` ```rust pub fn device_count(&self) -> usize ``` ```rust pub fn status(&self) -> Vec ``` ```rust pub fn set_policy(&self, policy: DeviceSelectionPolicy) -> CudaResult<()> ``` -------------------------------- ### Split mutable slice from the end Source: https://docs.rs/oxicuda/0.4.1/oxicuda/prelude/struct.PinnedBuffer.html Splits a mutable slice into subslices starting from the end, working backwards. ```rust let mut v = [100, 400, 300, 200, 600, 500]; let mut count = 0; for group in v.rsplit_mut(|num| *num % 3 == 0) { count += 1; group[0] = count; } assert_eq!(v, [3, 400, 300, 2, 600, 1]); ``` -------------------------------- ### chunks_exact Source: https://docs.rs/oxicuda/0.4.1/oxicuda/prelude/struct.PinnedBuffer.html Returns an iterator over chunk_size elements of the slice at a time, starting at the beginning. The chunks are non-overlapping slices. ```APIDOC ## pub fn chunks_exact(&self, chunk_size: usize) -> ChunksExact<'_, T> ### Description Returns an iterator over `chunk_size` elements of the slice at a time, starting at the beginning of the slice. The chunks are slices and do not overlap. If `chunk_size` does not divide the length of the slice, the last elements are omitted and can be retrieved via the iterator's `remainder` function. ### Parameters - **chunk_size** (usize) - Required - The size of each chunk. ### Panics Panics if `chunk_size` is zero. ``` -------------------------------- ### Module::from_ptx_with_options Source: https://docs.rs/oxicuda/0.4.1/oxicuda/prelude/struct.Module.html Loads a module from PTX source with explicit JIT compiler options. ```APIDOC ## pub fn from_ptx_with_options(ptx: &str, options: &JitOptions) -> Result<(Module, JitLog), CudaError> ### Description Loads a module from PTX source with explicit JIT compiler options. Returns the loaded module together with a `JitLog` containing any informational or error messages from the JIT compiler. ### Errors Returns a `CudaError` if JIT compilation fails or the driver call otherwise errors. ``` -------------------------------- ### pub fn iter(&self) -> Iter<'_, T> Source: https://docs.rs/oxicuda/0.4.1/oxicuda/prelude/struct.PinnedBuffer.html Returns an iterator over the slice, yielding all items from start to end. ```APIDOC ## pub fn iter(&self) -> Iter<'_, T> ### Description Returns an iterator over the slice. The iterator yields all items from start to end. ``` -------------------------------- ### Constructing LaunchParams with the Builder Source: https://docs.rs/oxicuda/0.4.1/oxicuda/struct.LaunchParamsBuilder.html Demonstrates the fluent API to set grid, block, and shared memory parameters before building the final LaunchParams object. ```rust use oxicuda_launch::{LaunchParams, Dim3}; let params = LaunchParams::builder() .grid((4u32, 4u32)) .block(256u32) .shared_mem(1024) .build(); assert_eq!(params.grid, Dim3::xy(4, 4)); assert_eq!(params.block, Dim3::x(256)); assert_eq!(params.shared_mem_bytes, 1024); ``` -------------------------------- ### Splitting slices with split_off Source: https://docs.rs/oxicuda/0.4.1/oxicuda/prelude/struct.PinnedBuffer.html Examples of using split_off to remove and return a subslice based on a one-sided range. ```rust let mut slice: &[_] = &['a', 'b', 'c', 'd']; let mut first_three = slice.split_off(..3).unwrap(); assert_eq!(slice, &['d']); assert_eq!(first_three, &['a', 'b', 'c']); ``` ```rust let mut slice: &[_] = &['a', 'b', 'c', 'd']; let mut tail = slice.split_off(2..).unwrap(); assert_eq!(slice, &['a', 'b']); assert_eq!(tail, &['c', 'd']); ``` ```rust let mut slice: &[_] = &['a', 'b', 'c', 'd']; assert_eq!(None, slice.split_off(5..)); assert_eq!(None, slice.split_off(..5)); assert_eq!(None, slice.split_off(..=4)); let expected: &[char] = &['a', 'b', 'c', 'd']; assert_eq!(Some(expected), slice.split_off(..4)); ```