Skip to content

Commit de528e2

Browse files
authored
Merge pull request #47 from szymon-zadworny/f16-example
Use f16 data in kernel launch example
2 parents 42ebb06 + f8c5c36 commit de528e2

3 files changed

Lines changed: 66 additions & 5 deletions

File tree

‎Cargo.lock‎

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

‎sycl/sycl-rs/Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ pin-project = "1.1.13"
2929
thiserror = "2.0.18"
3030

3131
[dev-dependencies]
32+
half = { version = "2.7.1", features = ["bytemuck"] }
3233
tokio = { version = "1.52.3", features = ["macros", "rt", "rt-multi-thread"] }

‎sycl/sycl-rs/examples/kernel_launch.rs‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// SPDX-License-Identifier: MIT OR Apache-2.0
77
//
88

9+
use half::f16;
910
use sycl_rs::prelude::*;
1011

1112
static IOTA_SRC: &str = r#"
@@ -15,16 +16,16 @@ namespace syclexp = sycl::ext::oneapi::experimental;
1516
1617
extern "C"
1718
SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((syclexp::nd_range_kernel<1>))
18-
void iota(float start, float *ptr) {
19+
void iota(sycl::half start, sycl::half *ptr) {
1920
size_t id = syclext::this_work_item::get_nd_item<1>().get_global_linear_id();
20-
ptr[id] = start + static_cast<float>(id);
21+
ptr[id] = start + static_cast<sycl::half>(id);
2122
}
2223
"#;
2324

2425
#[tokio::main]
2526
async fn main() -> sycl_rs::Result<()> {
2627
let mut queue = Queue::new();
27-
let mut device_array = queue.alloc_device::<f32>(1024)?.await?;
28+
let mut device_array = queue.alloc_device::<f16>(1024)?.await?;
2829

2930
let kernel = queue
3031
.get_context()
@@ -36,12 +37,12 @@ async fn main() -> sycl_rs::Result<()> {
3637
queue.launch(
3738
NdRange::new([1024], [16]),
3839
&kernel,
39-
(3.14_f32, &mut device_array),
40+
(f16::from_f32(3.14), &mut device_array),
4041
)
4142
}?
4243
.await?;
4344

44-
let mut host_array = queue.alloc_host::<f32>(1024)?.await?;
45+
let mut host_array = queue.alloc_host::<f16>(1024)?.await?;
4546

4647
queue.copy(&device_array, &mut host_array)?.await?;
4748

0 commit comments

Comments
 (0)