pub unsafe fn handle(
call_frame: *mut XLA_FFI_CallFrame,
body: impl FnOnce(&[FfiBuffer], &mut [FfiBuffer]) -> Result<(), String>,
) -> *mut XLA_FFI_ErrorExpand description
Runs the body of an FFI handler.
Answers XLA’s metadata query (the FFI API version this crate was built
against), does nothing in the stages before execution, and calls body
with the argument and result buffers when the program runs. An error
returned by body, or a panic in it, fails the execution with its
message, as do arguments or results that are not buffers or that alias.
§Safety
call_frame must be the pointer XLA passed to the handler, registered
for the host.
§Examples
use ruxla_pjrt::ffi;
unsafe extern "C" fn double(frame: *mut ruxla_pjrt::sys::XLA_FFI_CallFrame) -> *mut ruxla_pjrt::sys::XLA_FFI_Error {
// SAFETY: XLA passes a valid call frame.
unsafe {
ffi::handle(frame, |args, rets| {
let x = args[0].as_f64()?;
let y = rets[0].as_f64_mut()?;
for (y, x) in y.iter_mut().zip(x) {
*y = 2.0 * x;
}
Ok(())
})
}
}