Skip to main content

cube

Attribute Macro cube 

Source
#[cube]
Expand description

Mark a cube function, trait or implementation for expansion.

§Arguments

  • launch - generates a function to launch the kernel
  • launch_unchecked - generates a launch function without checks
  • debug - panics after generation to print the output to console
  • create_dummy_kernel - Generates a function to create a kernel without launching it. Used for testing.
  • harness - generates a harness function that runs the function on a single unit of a runtime and returns its result to the host, so a test can call f::harness::<R>(..) instead of writing a kernel, buffers and a read back by hand. Every parameter must be a scalar, a slice or array of scalars, a comptime scalar or a cube type that derives CubeHarness, and the function must return them or a tuple of them, or nothing when it writes into a mutable slice. The harness is gated:
    • harness - same as harness(cfg(test))
    • harness(cfg(<predicate>)) - compiled under #[cfg(<predicate>)]. The predicate is evaluated in the crate using the macro, so feature = "..." names one of its features.
    • harness(always) - ungated

§Trait arguments

  • expand_base_traits - base traits for the expanded “second half” of a trait with methods.

§Example

# use cubecl_macros::cube;
#[cube]
fn my_addition(a: u32, b: u32) -> u32 {
    a + b
}

§Harness example

#[cube(harness)]
fn add<F: Float>(x: F, y: F) -> F {
    x + y
}

#[test]
fn adds() {
    assert_eq!(add::harness::<CpuRuntime, f32>(1.0, 2.0), 3.0);
}