Skip to main content

ringkernel_accnet/cuda/
mod.rs

1//! CUDA code generation and GPU execution for accelerated analysis.
2//!
3//! This module provides:
4//! - Transpiled CUDA kernels from Rust DSL
5//! - Actual GPU execution via ringkernel-cuda
6//! - Benchmarking infrastructure for CPU vs GPU comparison
7
8#[cfg(feature = "cuda")]
9pub mod codegen;
10#[cfg(feature = "cuda")]
11pub mod executor;
12pub mod runtime;
13
14#[cfg(feature = "cuda")]
15pub use codegen::*;
16#[cfg(feature = "cuda")]
17pub use executor::{BenchmarkResults, GpuAnalysisResult, GpuExecutor, KernelBenchmark};
18pub use runtime::{AnalysisRuntime, Backend, RuntimeStatus};
19
20/// CUDA kernel configuration.
21#[derive(Debug, Clone)]
22pub struct CudaKernelConfig {
23    /// Block size (threads per block).
24    pub block_size: u32,
25    /// Shared memory size in bytes.
26    pub shared_mem_size: u32,
27    /// Enable async execution.
28    pub async_execution: bool,
29}
30
31impl Default for CudaKernelConfig {
32    fn default() -> Self {
33        Self {
34            block_size: 256,
35            shared_mem_size: 0,
36            async_execution: true,
37        }
38    }
39}
40
41/// Available CUDA kernels.
42#[derive(Debug, Clone, Copy, PartialEq, Eq)]
43pub enum CudaKernelType {
44    /// Journal entry transformation.
45    JournalTransform,
46    /// Suspense account detection.
47    SuspenseDetection,
48    /// GAAP violation detection.
49    GaapViolation,
50    /// Fraud pattern detection.
51    FraudPattern,
52    /// Benford's Law analysis.
53    BenfordAnalysis,
54    /// Network PageRank.
55    PageRank,
56    /// Circular flow detection.
57    CircularFlowDetection,
58    /// Temporal anomaly detection.
59    TemporalAnomaly,
60}
61
62impl CudaKernelType {
63    /// Get recommended block size for this kernel.
64    pub fn recommended_block_size(&self) -> u32 {
65        match self {
66            Self::JournalTransform => 256,
67            Self::SuspenseDetection => 128,
68            Self::GaapViolation => 256,
69            Self::FraudPattern => 128,
70            Self::BenfordAnalysis => 256,
71            Self::PageRank => 256,
72            Self::CircularFlowDetection => 64,
73            Self::TemporalAnomaly => 128,
74        }
75    }
76
77    /// Get kernel name.
78    pub fn name(&self) -> &'static str {
79        match self {
80            Self::JournalTransform => "journal_transform_kernel",
81            Self::SuspenseDetection => "suspense_detection_kernel",
82            Self::GaapViolation => "gaap_violation_kernel",
83            Self::FraudPattern => "fraud_pattern_kernel",
84            Self::BenfordAnalysis => "benford_analysis_kernel",
85            Self::PageRank => "pagerank_kernel",
86            Self::CircularFlowDetection => "circular_flow_kernel",
87            Self::TemporalAnomaly => "temporal_anomaly_kernel",
88        }
89    }
90}
91
92#[cfg(test)]
93mod tests {
94    use super::*;
95
96    #[test]
97    fn test_kernel_config() {
98        let config = CudaKernelConfig::default();
99        assert_eq!(config.block_size, 256);
100    }
101
102    #[test]
103    fn test_kernel_types() {
104        assert_eq!(
105            CudaKernelType::JournalTransform.name(),
106            "journal_transform_kernel"
107        );
108        assert_eq!(CudaKernelType::PageRank.recommended_block_size(), 256);
109    }
110}