#![cfg_attr(coverage_nightly, coverage(off))]
#![allow(clippy::wildcard_in_or_patterns)]
#![allow(clippy::useless_format)]
#![allow(clippy::single_char_add_str)]
use crate::cli::commands::{CudaTdgCommand, CudaTdgOutputFormat};
use crate::tdg::{
CudaSimdAnalyzer, CudaSimdConfig, CudaSimdTdgResult, CudaTdgGrade, DefectSeverity,
DefectTaxonomy, PopperScore,
};
use anyhow::{anyhow, Result};
use std::fs;
use std::path::PathBuf;
pub struct CudaTdgCommandConfig {
pub path: PathBuf,
pub command: Option<CudaTdgCommand>,
pub format: CudaTdgOutputFormat,
pub min_score: f64,
pub fail_on_p0: bool,
pub simd: bool,
pub wgpu: bool,
pub output: Option<PathBuf>,
pub quiet: bool,
}
pub async fn handle_cuda_tdg_command(config: CudaTdgCommandConfig) -> Result<()> {
if let Some(ref cmd) = config.command {
return handle_cuda_tdg_subcommand(cmd, &config).await;
}
let analyzer_config = CudaSimdConfig {
min_score: config.min_score,
fail_on_p0: config.fail_on_p0,
analyze_simd: config.simd,
analyze_wgpu: config.wgpu,
..Default::default()
};
let analyzer = CudaSimdAnalyzer::with_config(analyzer_config);
let result = analyzer.analyze(&config.path)?;
let output = format_result(&result, &config)?;
write_output(&output, &config)?;
Ok(())
}
async fn handle_cuda_tdg_subcommand(
cmd: &CudaTdgCommand,
config: &CudaTdgCommandConfig,
) -> Result<()> {
match cmd {
CudaTdgCommand::Analyze { path } => handle_analyze(path, config).await,
CudaTdgCommand::Score { path, breakdown } => handle_score(path, *breakdown, config).await,
CudaTdgCommand::Report {
path,
format,
output,
} => handle_report(path, format, output.as_ref(), config).await,
CudaTdgCommand::BarrierCheck { path } => handle_barrier_check(path, config).await,
CudaTdgCommand::ValidateTiles {
head_dim,
tile_kv,
shared_memory,
} => handle_validate_tiles(*head_dim, *tile_kv, *shared_memory, config).await,
CudaTdgCommand::Gate {
path,
min_score,
fail_on_p0,
} => handle_gate(path, *min_score, *fail_on_p0, config).await,
CudaTdgCommand::Kaizen { path, since } => {
handle_kaizen(path, since.as_deref(), config).await
}
CudaTdgCommand::Taxonomy => handle_taxonomy(config).await,
}
}
include!("cuda_tdg_handlers_subcommands.rs");
include!("cuda_tdg_handlers_gate_kaizen.rs");
include!("cuda_tdg_handlers_format_score.rs");
include!("cuda_tdg_handlers_format_report.rs");
#[cfg(test)]
#[path = "cuda_tdg_handlers_tests.rs"]
mod tests;