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