Add error handling - #28
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces synchronous SYCL exception propagation into the safe Rust API by threading Result<T, cxx::Exception> through key SYCL operations (queue barriers/waits/launches, kernel bundle build/lookups, and event waits), and updates buffer initialization and examples to reflect the now-fallible workflow.
Changes:
- Add crate-level
SyclError/Result<T>aliases and update multiple APIs to returnResult(queue, event, kernel bundle, nd-range launch). - Update
EventFutureandBufferFuture/EnqueuedBufferto yieldResultso async usage can propagate SYCL exceptions. - Update examples to use
?with fallible queue/buffer/kernel operations.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| oneapi-rs/src/lib.rs | Defines public SyclError and Result<T> aliases used across the crate. |
| oneapi-rs/src/queue.rs | Makes barrier/wait/launch fallible (Result) to surface synchronous SYCL exceptions. |
| oneapi-rs/src/range.rs | Updates ND-range launch trait/impls to return Result<Event>. |
| oneapi-rs/src/event.rs | Makes Event::wait() and EventFuture return Result<()> for exception propagation in async flows. |
| oneapi-rs/src/context.rs | Makes kernel bundle creation from source fallible. |
| oneapi-rs/src/kernel.rs | Makes kernel bundle build and kernel lookup fallible. |
| oneapi-rs/src/buffer.rs | Makes buffer initialization waiting/awaiting return Result<Buffer<…>>. |
| oneapi-rs/examples/kernel_launch.rs | Updates async example to propagate errors via ? and return Result<()>. |
| oneapi-rs/examples/kernel_launch_derive.rs | Updates sync example to propagate errors via ? and return Result<()>. |
| oneapi-rs-sys/src/queue-sys.rs | Updates selected queue FFI bindings (barrier/wait/launch) to return Result for C++ exception capture. |
| oneapi-rs-sys/src/event-sys.rs | Updates event wait FFI binding to return Result<()> for C++ exception capture. |
| oneapi-rs-sys/src/kernel-bundle-sys.rs | Updates kernel-bundle FFI bindings to return Result for C++ exception capture. |
Suppressed comments (2)
oneapi-rs-sys/src/event-sys.rs:33
register_callbackis declared as infallible (unsafe fn ... -> ()), but the C++ implementation callsqueue->submit(...)(seeoneapi-rs-sys/src/event.cpp:37), which can throwsycl::exception. If an exception is thrown here it will unwind across the FFI boundary and likely abort/UB instead of being surfaced as a Rust error.
Consider changing the bridge signature to return Result<()> (so cxx catches C++ exceptions) and then propagating/handling the error in oneapi-rs/src/event.rs when setting the callback.
fn wait(event: &mut UniquePtr<Event>) -> Result<()>;
unsafe fn register_callback(
queue: &mut UniquePtr<Queue>,
event: &Event,
waker: *const SharedWaker,
);
oneapi-rs-sys/src/queue-sys.rs:81
memsetandmemcpyare still declared as infallible (-> UniquePtr<Event>), but their C++ implementations callqueue->memset(...)/queue->memcpy(...)(seeoneapi-rs-sys/src/queue.cpp:41and:100), which can throwsycl::exceptionsynchronously. As written, any thrown exception would unwind across the FFI boundary.
Consider updating these to return Result<UniquePtr<Event>> (matching barrier/wait/launch_*) and then adjusting the safe Rust wrappers in oneapi-rs/src/queue.rs accordingly (e.g., memset_with_deps / copy_with_deps should return Result<Event>).
) -> Result<UniquePtr<Event>>;
unsafe fn memcpy(
queue: &mut UniquePtr<Queue>,
dest: *mut u8,
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
bratpiorka
left a comment
There was a problem hiding this comment.
approved but please consider if Copilot suppressed comments are valid
This PR adds synchronous SYCL exception support to:
This also changes the Buffer API, since initialization requires waiting on an event.
The PR also updates the examples.