use serde::{Deserialize, Serialize};
use super::{Backend, BackendForChannel};
use crate::core::vcs_lifted::blake2_merkle::{Blake2sM31MerkleChannel, Blake2sMerkleChannel};
use crate::core::vcs_lifted::poseidon252_merkle::Poseidon252MerkleChannel;
pub mod compat; pub mod column;
pub mod conversion;
#[allow(unused)]
pub mod fft;
#[allow(unused)]
pub mod fri;
pub mod poly_ops;
#[allow(unused)]
pub mod quotients;
pub mod accumulation;
#[allow(unused)]
pub mod merkle;
pub mod merkle_lifted;
pub mod gkr;
pub mod grind;
pub mod cuda_executor;
pub mod memory;
pub mod pipeline;
pub mod secure_session;
pub mod multi_gpu;
pub mod multi_gpu_executor;
pub mod cuda_streams;
pub mod large_proofs;
pub mod tee;
pub mod optimizations;
pub mod constraints;
#[derive(Copy, Clone, Debug, Deserialize, Serialize)]
pub struct GpuBackend;
impl GpuBackend {
pub fn is_available() -> bool {
#[cfg(feature = "cuda-runtime")]
{
cuda_executor::is_cuda_available()
}
#[cfg(not(feature = "cuda-runtime"))]
{
#[cfg(feature = "gpu")]
{
gpu_context::is_initialized()
}
#[cfg(not(feature = "gpu"))]
{
false
}
}
}
pub fn device_name() -> Option<String> {
#[cfg(feature = "cuda-runtime")]
{
cuda_executor::get_cuda_executor()
.ok()
.map(|e| e.device_info.name.clone())
}
#[cfg(not(feature = "cuda-runtime"))]
{
#[cfg(feature = "gpu")]
{
gpu_context::device_name()
}
#[cfg(not(feature = "gpu"))]
{
None
}
}
}
pub fn available_memory() -> Option<usize> {
#[cfg(feature = "cuda-runtime")]
{
cuda_executor::get_cuda_executor()
.ok()
.map(|e| e.device_info.total_memory_bytes)
}
#[cfg(not(feature = "cuda-runtime"))]
{
#[cfg(feature = "gpu")]
{
gpu_context::available_memory()
}
#[cfg(not(feature = "gpu"))]
{
None
}
}
}
pub fn compute_capability() -> Option<(u32, u32)> {
#[cfg(feature = "cuda-runtime")]
{
cuda_executor::get_cuda_executor()
.ok()
.map(|e| e.device_info.compute_capability)
}
#[cfg(not(feature = "cuda-runtime"))]
{
None
}
}
}
impl Backend for GpuBackend {}
impl BackendForChannel<Blake2sMerkleChannel> for GpuBackend {}
impl BackendForChannel<Blake2sM31MerkleChannel> for GpuBackend {}
impl BackendForChannel<Poseidon252MerkleChannel> for GpuBackend {}
#[cfg(all(feature = "gpu", not(feature = "cuda-runtime")))]
pub mod gpu_context {
use std::sync::OnceLock;
static GPU_CONTEXT: OnceLock<GpuContextInner> = OnceLock::new();
struct GpuContextInner {
device_name: String,
total_memory: usize,
}
pub fn initialize() -> bool {
GPU_CONTEXT.get_or_init(|| {
GpuContextInner {
device_name: "GPU (stub)".to_string(),
total_memory: 0,
}
});
true
}
pub fn is_initialized() -> bool {
GPU_CONTEXT.get().is_some()
}
pub fn device_name() -> Option<String> {
GPU_CONTEXT.get().map(|ctx| ctx.device_name.clone())
}
pub fn available_memory() -> Option<usize> {
GPU_CONTEXT.get().map(|ctx| ctx.total_memory)
}
}
#[cfg(feature = "cuda-runtime")]
pub mod gpu_context {
use super::cuda_executor;
pub fn initialize() -> bool {
cuda_executor::is_cuda_available()
}
pub fn is_initialized() -> bool {
cuda_executor::is_cuda_available()
}
pub fn device_name() -> Option<String> {
cuda_executor::get_cuda_executor()
.ok()
.map(|e| e.device_info.name.clone())
}
pub fn available_memory() -> Option<usize> {
cuda_executor::get_cuda_executor()
.ok()
.map(|e| e.device_info.total_memory_bytes)
}
}
#[cfg(not(feature = "gpu"))]
pub mod gpu_context {
pub fn initialize() -> bool { false }
pub fn is_initialized() -> bool { false }
pub fn device_name() -> Option<String> { None }
pub fn available_memory() -> Option<usize> { None }
}