use sycl_rs::prelude::*;
static IOTA_SRC: &str = r#"
#include <sycl/sycl.hpp>
namespace syclext = sycl::ext::oneapi;
namespace syclexp = sycl::ext::oneapi::experimental;
extern "C"
SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((syclexp::nd_range_kernel<1>))
void iota(float start, float *ptr) {
size_t id = syclext::this_work_item::get_nd_item<1>().get_global_linear_id();
ptr[id] = start + static_cast<float>(id);
}
"#;
#[tokio::main]
async fn main() -> sycl_rs::Result<()> {
let mut queue = Queue::new();
let mut device_array = queue.alloc_device::<f32>(1024)?.await?;
let kernel = queue
.get_context()
.create_kernel_bundle_from_source(IOTA_SRC)?
.build()?
.get_kernel("iota")?;
unsafe {
queue.launch(
NdRange::new([1024], [16]),
&kernel,
(3.14_f32, &mut device_array),
)
}?
.await?;
let mut host_array = queue.alloc_host::<f32>(1024)?.await?;
queue.copy(&device_array, &mut host_array)?.await?;
for e in host_array.iter() {
print!("{e} ");
}
println!();
Ok(())
}