Skip to main content

validate_function_with_mode

Function validate_function_with_mode 

Source
pub fn validate_function_with_mode(
    func: &ItemFn,
    mode: ValidationMode,
) -> Result<(), ValidationError>
Expand description

Validate a function with a specific validation mode.

Different kernel types have different validation requirements:

  • ValidationMode::Stencil: No loops allowed (current behavior for stencil kernels)
  • ValidationMode::Generic: Loops allowed for general CUDA kernels
  • ValidationMode::RingKernel: Loops required for persistent actor kernels

§Arguments

  • func - The function to validate
  • mode - The validation mode to use

§Returns

Ok(()) if validation passes, Err with the first validation error otherwise.

§Example

use ringkernel_cuda_codegen::{validate_function_with_mode, ValidationMode};
use syn::parse_quote;

// Generic kernel with loops allowed
let func: syn::ItemFn = parse_quote! {
    fn process(data: &mut [f32], n: i32) {
        for i in 0..n {
            data[i as usize] = data[i as usize] * 2.0;
        }
    }
};

// This would fail with Stencil mode, but passes with Generic mode
assert!(validate_function_with_mode(&func, ValidationMode::Generic).is_ok());