Skip to content

Commit 0a53649

Browse files
authored
Merge pull request #2 from szymon-zadworny/usm-alloc
Add USM allocations
2 parents 121e20b + 693bfaf commit 0a53649

17 files changed

Lines changed: 404 additions & 0 deletions

File tree

Cargo.lock

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

oneapi-rs-sys/build.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,23 @@ fn main() {
1717
"src/types-sys.rs",
1818
"src/platform-sys.rs",
1919
"src/device-sys.rs",
20+
"src/queue-sys.rs",
21+
"src/usm-sys.rs",
2022
];
2123

2224
let cpp_sources = [
2325
"src/platform.cpp",
2426
"src/device.cpp",
27+
"src/queue.cpp",
28+
"src/usm.cpp",
2529
];
2630

2731
let cpp_headers = [
2832
"include/types.hpp",
2933
"include/platform.hpp",
3034
"include/device.hpp",
35+
"include/queue.hpp",
36+
"include/usm.hpp",
3137
];
3238

3339
cxx_build::bridges(&rust_sources)

oneapi-rs-sys/include/queue.hpp

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+
#pragma once
10+
11+
#include "oneapi-rs-sys/include/types.hpp"
12+
#include "rust/cxx.h"
13+
14+
#include <memory>
15+
16+
namespace sycl_shims::queue {
17+
std::unique_ptr<Queue> new_queue();
18+
std::unique_ptr<Queue> new_queue_from_device(Device const &);
19+
} // namespace sycl_shims::queue

oneapi-rs-sys/include/types.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@
1313
namespace sycl_shims {
1414
using Device = sycl::device;
1515
using Platform = sycl::platform;
16+
using Queue = sycl::queue;
1617
}

oneapi-rs-sys/include/usm.hpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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 "rust/cxx.h"
13+
14+
#include <memory>
15+
16+
namespace sycl_shims::usm {
17+
std::uint8_t* aligned_alloc_device(std::size_t alignment, std::size_t num_bytes, Queue const &);
18+
std::uint8_t* aligned_alloc_host(std::size_t alignment, std::size_t num_bytes, Queue const &);
19+
std::uint8_t* aligned_alloc_shared(std::size_t alignment, std::size_t num_bytes, Queue const &);
20+
void free(std::uint8_t*, Queue const &);
21+
} // namespace sycl_shims::usm

oneapi-rs-sys/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,9 @@ pub mod platform;
1414

1515
#[path = "device-sys.rs"]
1616
pub mod device;
17+
18+
#[path = "queue-sys.rs"]
19+
pub mod queue;
20+
21+
#[path = "usm-sys.rs"]
22+
pub mod usm;

oneapi-rs-sys/src/queue-sys.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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::queue")]
10+
pub mod ffi {
11+
unsafe extern "C++" {
12+
include!("oneapi-rs-sys/include/queue.hpp");
13+
14+
#[namespace = "sycl_shims"]
15+
type Queue = crate::types::ffi::Queue;
16+
#[namespace = "sycl_shims"]
17+
type Device = crate::types::ffi::Device;
18+
19+
fn new_queue() -> UniquePtr<Queue>;
20+
fn new_queue_from_device(device: &Device) -> UniquePtr<Queue>;
21+
}
22+
}

oneapi-rs-sys/src/queue.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/queue.hpp"
10+
#include "oneapi-rs-sys/src/queue-sys.rs.h"
11+
12+
namespace sycl_shims::queue {
13+
std::unique_ptr<Queue> new_queue() {
14+
return std::make_unique<Queue>(sycl::queue());
15+
}
16+
std::unique_ptr<Queue> new_queue_from_device(Device const & device) {
17+
return std::make_unique<Queue>(sycl::queue(device));
18+
}
19+
} // namespace sycl_shims::queue

oneapi-rs-sys/src/types-sys.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub mod ffi {
1212
include!("oneapi-rs-sys/include/types.hpp");
1313
type Device;
1414
type Platform;
15+
type Queue;
1516
}
1617

1718
// This is a workaround - cxx currently doesn't support passing
@@ -39,6 +40,7 @@ pub mod ffi {
3940

4041
impl UniquePtr<Device> {}
4142
impl UniquePtr<Platform> {}
43+
impl UniquePtr<Queue> {}
4244

4345
impl Vec<DevicePtr> {}
4446
impl Vec<PlatformPtr> {}

oneapi-rs-sys/src/usm-sys.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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::usm")]
10+
pub mod ffi {
11+
unsafe extern "C++" {
12+
#[namespace = "sycl_shims"]
13+
type Queue = crate::types::ffi::Queue;
14+
}
15+
16+
extern "C++" {
17+
include!("oneapi-rs-sys/include/usm.hpp");
18+
unsafe fn aligned_alloc_device(alignment: usize, num_bytes: usize, queue: &Queue) -> Result<*mut u8>;
19+
unsafe fn aligned_alloc_host(alignment: usize, num_bytes: usize, queue: &Queue) -> Result<*mut u8>;
20+
unsafe fn aligned_alloc_shared(alignment: usize, num_bytes: usize, queue: &Queue) -> Result<*mut u8>;
21+
unsafe fn free(ptr: *mut u8, queue: &Queue);
22+
}
23+
}

0 commit comments

Comments
 (0)