Skip to content

Commit 43f9081

Browse files
authored
Merge pull request #9 from szymon-zadworny/kernel_launch
Add kernel launch support
2 parents 26d0b0e + f594560 commit 43f9081

24 files changed

Lines changed: 656 additions & 0 deletions

oneapi-rs-sys/build.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ fn main() {
2020
"src/queue-sys.rs",
2121
"src/usm-sys.rs",
2222
"src/event-sys.rs",
23+
"src/context-sys.rs",
24+
"src/kernel-bundle-sys.rs",
2325
];
2426

2527
let cpp_sources = [
@@ -28,6 +30,8 @@ fn main() {
2830
"src/queue.cpp",
2931
"src/usm.cpp",
3032
"src/event.cpp",
33+
"src/context.cpp",
34+
"src/kernel-bundle.cpp",
3135
];
3236

3337
let cpp_headers = [
@@ -37,6 +41,8 @@ fn main() {
3741
"include/queue.hpp",
3842
"include/usm.hpp",
3943
"include/event.hpp",
44+
"include/context.hpp",
45+
"include/kernel-bundle.hpp",
4046
];
4147

4248
cxx_build::bridges(&rust_sources)

oneapi-rs-sys/include/context.hpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 <memory>
12+
13+
#include <sycl/sycl.hpp>
14+
15+
#include "oneapi-rs-sys/include/types.hpp"
16+
#include "rust/cxx.h"
17+
18+
namespace sycl_shims {
19+
struct DevicePtr;
20+
} // namespace sycl_shims
21+
22+
namespace sycl_shims::context {
23+
std::unique_ptr<Context> new_context(rust::Vec<DevicePtr>);
24+
} // namespace sycl_shims::context

oneapi-rs-sys/include/device.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ DeviceType get_device_type(Device const &);
2525
rust::String get_version(Device const &);
2626
rust::String get_name(Device const &);
2727
std::unique_ptr<Platform> get_platform(Device const &);
28+
std::unique_ptr<Device> clone(Device const &);
2829
} // namespace sycl_shims::device
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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 <memory>
12+
13+
#include <sycl/sycl.hpp>
14+
15+
#include "oneapi-rs-sys/include/types.hpp"
16+
#include "rust/cxx.h"
17+
18+
namespace sycl_shims::kernel_bundle {
19+
std::unique_ptr<SourceKernelBundle>
20+
create_kernel_bundle_from_source(Context const &ctxt, rust::Str source);
21+
std::unique_ptr<ExecutableKernelBundle>
22+
build(std::unique_ptr<SourceKernelBundle> &source);
23+
std::unique_ptr<Kernel> get_kernel(std::unique_ptr<ExecutableKernelBundle> &,
24+
rust::Str);
25+
} // namespace sycl_shims::kernel_bundle

oneapi-rs-sys/include/queue.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,35 @@
1515

1616
namespace sycl_shims {
1717
struct EventPtr;
18+
struct Range1;
19+
struct Range2;
20+
struct Range3;
1821
} // namespace sycl_shims
1922

2023
namespace sycl_shims::queue {
2124
std::unique_ptr<Queue> new_queue();
2225
std::unique_ptr<Queue> new_queue_immediate();
2326
std::unique_ptr<Queue> new_queue_from_device(Device const &);
27+
std::unique_ptr<Context> get_context(Queue const &);
2428
std::unique_ptr<Queue> clone(Queue const &);
2529
std::unique_ptr<Event> memset(std::unique_ptr<Queue> &, std::uint8_t *ptr,
2630
int value, std::size_t num_bytes,
2731
rust::Vec<EventPtr>);
2832
std::unique_ptr<Event> barrier(std::unique_ptr<Queue> &, rust::Vec<EventPtr>);
2933
void wait(std::unique_ptr<Queue> &);
34+
35+
std::unique_ptr<Event>
36+
launch_1d(std::unique_ptr<Queue> &, Range1 global_size, Range1 local_size,
37+
Kernel const &,
38+
rust::Slice<rust::slice<std::uint8_t const> const> args);
39+
40+
std::unique_ptr<Event>
41+
launch_2d(std::unique_ptr<Queue> &, Range2 global_size, Range2 local_size,
42+
Kernel const &,
43+
rust::Slice<rust::slice<std::uint8_t const> const> args);
44+
45+
std::unique_ptr<Event>
46+
launch_3d(std::unique_ptr<Queue> &, Range3 global_size, Range3 local_size,
47+
Kernel const &,
48+
rust::Slice<rust::slice<std::uint8_t const> const> args);
3049
} // namespace sycl_shims::queue

oneapi-rs-sys/include/types.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,10 @@ using Device = sycl::device;
1515
using Platform = sycl::platform;
1616
using Queue = sycl::queue;
1717
using Event = sycl::event;
18+
using Context = sycl::context;
19+
using Kernel = sycl::kernel;
20+
using SourceKernelBundle =
21+
sycl::kernel_bundle<sycl::bundle_state::ext_oneapi_source>;
22+
using ExecutableKernelBundle =
23+
sycl::kernel_bundle<sycl::bundle_state::executable>;
1824
} // namespace sycl_shims

oneapi-rs-sys/src/context-sys.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
#[cxx::bridge(namespace = "sycl_shims::context")]
10+
pub mod ffi {
11+
#[namespace = "sycl_shims"]
12+
extern "C++" {
13+
include!("oneapi-rs-sys/src/types-sys.rs.h");
14+
type DevicePtr = crate::types::ffi::DevicePtr;
15+
}
16+
17+
unsafe extern "C++" {
18+
include!("oneapi-rs-sys/include/context.hpp");
19+
20+
#[namespace = "sycl_shims"]
21+
type Context = crate::types::ffi::Context;
22+
23+
fn new_context(devices: Vec<DevicePtr>) -> UniquePtr<Context>;
24+
}
25+
}

oneapi-rs-sys/src/context.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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/context.hpp"
10+
#include "oneapi-rs-sys/src/context-sys.rs.h"
11+
12+
namespace sycl_shims::context {
13+
std::unique_ptr<Context> new_context(rust::Vec<DevicePtr> devices) {
14+
std::vector<sycl::device> raw_devices;
15+
for (auto &&d : devices)
16+
raw_devices.push_back(std::move(*d.ptr));
17+
return std::make_unique<Context>(raw_devices);
18+
}
19+
} // namespace sycl_shims::context

oneapi-rs-sys/src/device-sys.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@ pub mod ffi {
3131
fn get_device_type(device: &Device) -> DeviceType;
3232
fn get_version(device: &Device) -> String;
3333
fn get_name(device: &Device) -> String;
34+
fn clone(device: &Device) -> UniquePtr<Device>;
3435
}
3536
}

oneapi-rs-sys/src/device.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,8 @@ rust::String get_name(Device const &device) {
5353
std::unique_ptr<Platform> get_platform(Device const &device) {
5454
return std::make_unique<Platform>(device.get_platform());
5555
}
56+
57+
std::unique_ptr<Device> clone(Device const &device) {
58+
return std::make_unique<Device>(sycl::device(device));
59+
}
5660
} // namespace sycl_shims::device

0 commit comments

Comments
 (0)