Skip to content

Add memcpy binding - #11

Merged
bratpiorka merged 8 commits into
oneapi-src:mainfrom
szymon-zadworny:memcpy
Jul 28, 2026
Merged

Add memcpy binding#11
bratpiorka merged 8 commits into
oneapi-src:mainfrom
szymon-zadworny:memcpy

Conversation

@szymon-zadworny

Copy link
Copy Markdown
Contributor

This PR adds:

  • Support for device-allocated buffers
  • Generic Queue::copy binding
  • An updated kernel launch example which showcases all current abstractions.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR expands the oneapi-rs USM buffer abstractions by adding device-allocated buffers and a generic Queue::copy (memcpy) binding, and updates the kernel launch example to demonstrate device→host transfers using the async event model.

Changes:

  • Add a DeviceAllocator and a HostAccessible marker trait to differentiate host-accessible vs device-only USM buffers.
  • Add Queue::alloc_device* and Queue::{copy, copy_with_deps} backed by a new SYCL queue::memcpy FFI binding.
  • Update examples/kernel_launch.rs to allocate device buffers, launch a kernel, then copy results back to host and print.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
oneapi-rs/src/usm.rs Introduces host-accessibility marker trait and exposes a public device allocator kind.
oneapi-rs/src/queue.rs Adds device allocation helpers and new copy/memcpy APIs on Queue.
oneapi-rs/src/buffer.rs Restricts slice deref to host-accessible allocators and adds buffer length accessor.
oneapi-rs/examples/kernel_launch.rs Updates example to use async/await and device→host copy.
oneapi-rs-sys/src/queue.cpp Adds C++ shim for queue->memcpy(...) with dependency events.
oneapi-rs-sys/src/queue-sys.rs Exposes memcpy over cxx bridge to Rust.
oneapi-rs-sys/include/queue.hpp Declares the new memcpy shim in the sys header.
Comments suppressed due to low confidence (1)

oneapi-rs/src/queue.rs:201

  • Same as copy: please constrain T to Pod for this raw memcpy-based API so the safe surface area stays bitwise-sound.
    pub fn copy_with_deps<T, A1, A2>(
        &mut self,
        src: &Buffer<T, A1>,
        dst: &mut Buffer<T, A2>,
        dep_events: &[&Event],
    ) -> Event
    where
        A1: UsmAlloc,
        A2: UsmAlloc,
    {

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread oneapi-rs/src/queue.rs
Comment thread oneapi-rs/src/queue.rs
Comment thread oneapi-rs/src/buffer.rs
Comment thread oneapi-rs-sys/src/queue-sys.rs

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (2)

oneapi-rs/src/queue.rs:214

  • size_of::<T>() is not in scope in this module, which will cause a compile error. Use a qualified path (or import it explicitly).
        let amount = min(src.get_len(), dst.get_len());
        let num_bytes = amount * size_of::<T>();
        unsafe {

oneapi-rs/src/usm.rs:34

  • HostAccessible is declared as an unsafe trait, but it doesn't document the safety contract that implementers must uphold. For unsafe marker traits, add a # Safety section that spells out the required invariant (e.g., that allocations are directly readable/writable from the host for the lifetime of the allocation).
/// A marker trait for host-accessible USM allocators.
pub unsafe trait HostAccessible {}

@bratpiorka
bratpiorka merged commit abe3d79 into oneapi-src:main Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants