Skip to content

Commit 0763719

Browse files
Add derive macro example
1 parent 2583836 commit 0763719

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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 oneapi_rs::{
10+
buffer::Buffer,
11+
kernel::KernelArgument,
12+
queue::Queue,
13+
range::NdRange,
14+
usm::{SharedAllocator, UsmAllocator},
15+
};
16+
use oneapi_rs_derive::KernelArgumentList;
17+
18+
static IOTA_SRC: &str = r#"
19+
#include <sycl/sycl.hpp>
20+
namespace syclext = sycl::ext::oneapi;
21+
namespace syclexp = sycl::ext::oneapi::experimental;
22+
23+
extern "C"
24+
SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((syclexp::nd_range_kernel<1>))
25+
void iota(double start, double *ptr) {
26+
size_t id = syclext::this_work_item::get_nd_item<1>().get_global_linear_id();
27+
ptr[id] = start + static_cast<double>(id);
28+
}
29+
"#;
30+
31+
#[derive(KernelArgumentList)]
32+
struct IotaArgs<'a> {
33+
start: f64,
34+
ptr: &'a mut Buffer<f64, UsmAllocator<SharedAllocator>>,
35+
}
36+
37+
fn main() {
38+
let mut queue = Queue::new();
39+
let mut buffer = queue.alloc_shared::<f64>(1024).wait();
40+
41+
let kernel = queue
42+
.get_context()
43+
.create_kernel_bundle_from_source(IOTA_SRC)
44+
.build()
45+
.get_kernel("iota");
46+
47+
unsafe {
48+
queue.launch(
49+
NdRange::new([1024], [16]),
50+
&kernel,
51+
IotaArgs {
52+
start: 3.14,
53+
ptr: &mut buffer,
54+
},
55+
)
56+
}
57+
.wait();
58+
59+
for e in buffer.iter() {
60+
print!("{e} ");
61+
}
62+
println!();
63+
}

0 commit comments

Comments
 (0)