Skip to content

Commit 05b00d3

Browse files
authored
Merge pull request #6 from szymon-zadworny/event
Add synchronous and asynchronous events
2 parents 0680cd2 + bc60941 commit 05b00d3

22 files changed

Lines changed: 703 additions & 17 deletions

Cargo.lock

Lines changed: 157 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

oneapi-rs-sys/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ license = "MIT OR Apache-2.0"
66

77
[dependencies]
88
cxx = "1.0.194"
9+
futures = "0.3.33"
910

1011
[build-dependencies]
1112
cxx-build = "1.0.194"

oneapi-rs-sys/build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ fn main() {
1919
"src/device-sys.rs",
2020
"src/queue-sys.rs",
2121
"src/usm-sys.rs",
22+
"src/event-sys.rs",
2223
];
2324

2425
let cpp_sources = [
2526
"src/platform.cpp",
2627
"src/device.cpp",
2728
"src/queue.cpp",
2829
"src/usm.cpp",
30+
"src/event.cpp",
2931
];
3032

3133
let cpp_headers = [
@@ -34,6 +36,7 @@ fn main() {
3436
"include/device.hpp",
3537
"include/queue.hpp",
3638
"include/usm.hpp",
39+
"include/event.hpp",
3740
];
3841

3942
cxx_build::bridges(&rust_sources)

oneapi-rs-sys/include/event.hpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// Copyright (C) 2026 Intel Corporation
3+
//
4+
// Under the MIT License or the Apache License v2.0.
5+
// See LICENSE-MIT and LICENSE-APACHE for license information.
6+
// SPDX-License-Identifier: MIT OR Apache-2.0
7+
//
8+
9+
#pragma once
10+
11+
#include "oneapi-rs-sys/include/types.hpp"
12+
#include "oneapi-rs-sys/src/event-sys.rs.h"
13+
#include "rust/cxx.h"
14+
15+
#include <memory>
16+
17+
namespace sycl_shims {
18+
enum class EventCommandStatus : std::uint8_t;
19+
} // namespace sycl_shims
20+
21+
namespace sycl_shims::event {
22+
void wait(std::unique_ptr<Event> &);
23+
void register_callback(std::unique_ptr<Queue> &, Event const &, SharedWaker const *);
24+
EventCommandStatus get_command_execution_status(Event const &);
25+
std::unique_ptr<Event> clone(Event const &);
26+
} // namespace sycl_shims::event

oneapi-rs-sys/include/queue.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,22 @@
1313

1414
#include <memory>
1515

16+
namespace sycl_shims {
17+
struct EventPtr;
18+
} // namespace sycl_shims
19+
1620
namespace sycl_shims::queue {
1721
std::unique_ptr<Queue> new_queue();
22+
std::unique_ptr<Queue> new_queue_immediate();
1823
std::unique_ptr<Queue> new_queue_from_device(Device const &);
24+
std::unique_ptr<Queue> clone(Queue const &);
25+
std::unique_ptr<Event> memset(
26+
std::unique_ptr<Queue> &,
27+
std::uint8_t * ptr,
28+
int value,
29+
std::size_t num_bytes,
30+
rust::Vec<EventPtr>
31+
);
32+
std::unique_ptr<Event> barrier(std::unique_ptr<Queue> &, rust::Vec<EventPtr>);
33+
void wait(std::unique_ptr<Queue> &);
1934
} // namespace sycl_shims::queue

oneapi-rs-sys/include/types.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ namespace sycl_shims {
1414
using Device = sycl::device;
1515
using Platform = sycl::platform;
1616
using Queue = sycl::queue;
17+
using Event = sycl::event;
1718
}

oneapi-rs-sys/src/event-sys.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//
2+
// Copyright (C) 2026 Intel Corporation
3+
//
4+
// Under the MIT License or the Apache License v2.0.
5+
// See LICENSE-MIT and LICENSE-APACHE for license information.
6+
// SPDX-License-Identifier: MIT OR Apache-2.0
7+
//
8+
9+
use crate::types::SharedWaker;
10+
11+
#[cxx::bridge(namespace = "sycl_shims::event")]
12+
pub mod ffi {
13+
#[namespace = "sycl_shims"]
14+
extern "C++" {
15+
include!("oneapi-rs-sys/src/types-sys.rs.h");
16+
type EventCommandStatus = crate::types::ffi::EventCommandStatus;
17+
}
18+
19+
unsafe extern "C++" {
20+
include!("oneapi-rs-sys/include/event.hpp");
21+
22+
#[namespace = "sycl_shims"]
23+
type Event = crate::types::ffi::Event;
24+
25+
#[namespace = "sycl_shims"]
26+
type Queue = crate::types::ffi::Queue;
27+
28+
fn wait(event: &mut UniquePtr<Event>);
29+
unsafe fn register_callback(queue: &mut UniquePtr<Queue>, event: &Event, waker: *const SharedWaker);
30+
fn get_command_execution_status(event: &Event) -> EventCommandStatus;
31+
fn clone(event: &Event) -> UniquePtr<Event>;
32+
}
33+
34+
extern "Rust" {
35+
type SharedWaker;
36+
fn wake(&self);
37+
}
38+
}

oneapi-rs-sys/src/event.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//
2+
// Copyright (C) 2026 Intel Corporation
3+
//
4+
// Under the MIT License or the Apache License v2.0.
5+
// See LICENSE-MIT and LICENSE-APACHE for license information.
6+
// SPDX-License-Identifier: MIT OR Apache-2.0
7+
//
8+
9+
#include "oneapi-rs-sys/include/event.hpp"
10+
11+
using sycl::info::event_command_status;
12+
13+
namespace syclintel = sycl::ext::intel;
14+
15+
namespace sycl_shims::event {
16+
void wait(std::unique_ptr<Event> & event) {
17+
event->wait();
18+
}
19+
std::unique_ptr<Event> clone(Event const & event) {
20+
return std::make_unique<Event>(sycl::event(event));
21+
}
22+
EventCommandStatus get_command_execution_status(Event const & event) {
23+
auto status = event.get_info<sycl::info::event::command_execution_status>();
24+
switch (status) {
25+
case event_command_status::submitted:
26+
return EventCommandStatus::Submitted;
27+
case event_command_status::running:
28+
return EventCommandStatus::Running;
29+
case event_command_status::complete:
30+
return EventCommandStatus::Complete;
31+
default:
32+
return EventCommandStatus::Unknown;
33+
}
34+
}
35+
void register_callback(std::unique_ptr<Queue> & queue, Event const & event, SharedWaker const * waker) {
36+
queue->submit([=](sycl::handler& cgh) {
37+
cgh.depends_on(event);
38+
cgh.host_task([=]() { waker->wake(); });
39+
});
40+
}
41+
} // namespace sycl_shims::event

oneapi-rs-sys/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ pub mod queue;
2020

2121
#[path = "usm-sys.rs"]
2222
pub mod usm;
23+
24+
#[path = "event-sys.rs"]
25+
pub mod event;

0 commit comments

Comments
 (0)