Skip to main content

cubecl_core/frontend/
validation.rs

1use crate as cubecl;
2use alloc::{format, string::String};
3use cubecl::prelude::*;
4use cubecl_ir::{ElemType, Scope, features::ComplexUsage};
5use cubecl_macros::intrinsic;
6
7#[cube]
8/// Push a validation error that will make kernel compilation fail.
9pub fn push_validation_error(#[comptime] msg: String) {
10    intrinsic! {|scope| scope.push_error(msg)}
11}
12
13pub(crate) fn require_complex_usage(
14    scope: &Scope,
15    ty: ElemType,
16    usage: ComplexUsage,
17    op_name: &'static str,
18) {
19    if !ty.is_complex() {
20        return;
21    }
22    let Some(properties) = scope.state().device_properties.clone() else {
23        return;
24    };
25    if !properties.supports_complex_usage(ty, usage) {
26        scope.push_error(format!(
27            "Complex operation `{op_name}` requires {usage:?} support for `{ty}`, but the active runtime does not advertise it."
28        ));
29    }
30}