Skip to main content

cubecl_std/throughput/runners/
launch_overhead.rs

1use cubecl::prelude::*;
2use cubecl_core as cubecl;
3
4pub fn build_kernel<R: cubecl_runtime::runtime::Runtime>(
5    client: &cubecl_runtime::client::ComputeClient<R>,
6    _key: cubecl_runtime::throughput::ThroughputKey,
7    _config: super::super::LaunchConfig,
8) -> cubecl_runtime::throughput::KernelConfig {
9    let client = client.clone();
10    let sample = alloc::boxed::Box::new(move |iterations: usize| {
11        let input = client.empty(core::mem::size_of::<i32>());
12        let output = client.empty(core::mem::size_of::<i32>());
13
14        let (_, duration) = client
15            .profile(
16                || unsafe {
17                    for _ in 0..iterations {
18                        launch_overhead::launch_unchecked::<R>(
19                            &client,
20                            cubecl_core::CubeCount::new_single(),
21                            cubecl_core::server::CubeDim::new_single(),
22                            1,
23                            cubecl_core::frontend::BufferArg::from_raw_parts(input.clone(), 1),
24                            cubecl_core::frontend::BufferArg::from_raw_parts(output.clone(), 1),
25                            cubecl_core::ir::ElemType::Int(cubecl_core::ir::IntKind::I32).into(),
26                        );
27                    }
28                },
29                "launch_overhead",
30            )
31            .expect("should succeed launch_overhead");
32
33        cubecl_core::future::block_on(duration.into_future()).duration()
34    });
35
36    cubecl_runtime::throughput::KernelConfig {
37        sample,
38        ops_count: 1,
39    }
40}
41
42#[cube(launch_unchecked)]
43pub fn launch_overhead<I: Numeric, N: Size>(
44    input: &[Vector<I, N>],
45    output: &mut [Vector<I, N>],
46    #[define(I)] _dtype: StorageType,
47) {
48    if ABSOLUTE_POS == 0 {
49        output[0] = input[0];
50    }
51}