#![allow(missing_docs)]
#![allow(unsafe_code)]
pub mod error;
pub mod parser;
pub mod transpiler;
pub mod runtime;
pub mod memory;
pub mod kernel;
pub mod backend;
pub mod utils;
pub mod prelude;
pub mod profiling;
pub mod simd;
pub mod neural_integration;
#[cfg(not(target_arch = "wasm32"))]
pub mod nutanix;
pub use error::{CudaRustError, Result};
pub use parser::CudaParser;
pub use transpiler::{Transpiler, CudaTranspiler};
pub use runtime::Runtime;
pub use neural_integration::{
NeuralBridge, BridgeConfig, NeuralOperation, ActivationFunction as NeuralActivationFunction,
SystemCapabilities as NeuralCapabilities, initialize as init_neural_integration,
get_capabilities as get_neural_capabilities,
};
pub struct CudaRust {
parser: CudaParser,
transpiler: Transpiler,
}
impl CudaRust {
pub fn new() -> Self {
Self {
parser: CudaParser::new(),
transpiler: Transpiler::new(),
}
}
pub fn transpile(&self, cuda_source: &str) -> Result<String> {
let ast = self.parser.parse(cuda_source)?;
let rust_code = self.transpiler.transpile(ast)?;
Ok(rust_code)
}
#[cfg(feature = "webgpu-only")]
pub fn to_webgpu(&self, cuda_source: &str) -> Result<String> {
let ast = self.parser.parse(cuda_source)?;
let wgsl = self.transpiler.to_wgsl(ast)?;
Ok(wgsl)
}
}
impl Default for CudaRust {
fn default() -> Self {
Self::new()
}
}
pub fn init() -> Result<Runtime> {
Runtime::new()
}
#[cfg(target_arch = "wasm32")]
pub mod wasm {
use wasm_bindgen::prelude::*;
#[wasm_bindgen(start)]
pub fn init_wasm() {
console_error_panic_hook::set_once();
#[cfg(feature = "debug-transpiler")]
{
console_log::init_with_level(log::Level::Debug).ok();
}
}
#[wasm_bindgen]
pub fn transpile_cuda(cuda_code: &str) -> Result<String, JsValue> {
let transpiler = super::CudaRust::new();
transpiler.transpile(cuda_code)
.map_err(|e| JsValue::from_str(&e.to_string()))
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_basic_transpilation() {
let cuda_rust = CudaRust::new();
let cuda_code = r#"
__global__ void add(float* a, float* b, float* c) {
int i = threadIdx.x;
c[i] = a[i] + b[i];
}
"#;
let result = cuda_rust.transpile(cuda_code);
assert!(result.is_ok());
}
}