#[cfg(feature = "cuda")]
use std::any::Any;
#[cfg(feature = "cuda")]
mod cubecl;
#[cfg(feature = "cuda")]
mod kernels;
#[cfg(feature = "webgpu")]
mod webgpu;
#[cfg(feature = "cuda")]
pub use cubecl::{
device_ptr, download_tensor, gpu_available, upload_tensor, CudaBackend, CudaRuntime,
};
#[cfg(feature = "cuda")]
#[doc(hidden)]
pub use cubecl::{CudaExtensionCache, CudaExtensionCacheGuard};
#[cfg(feature = "webgpu")]
pub use webgpu::{
download_webgpu_tensor, upload_webgpu_tensor, webgpu_available, WebGpuBackend, WebGpuRuntime,
};
#[cfg(feature = "cuda")]
#[doc(hidden)]
pub mod cuda_interop {
pub use crate::cubecl::interop::*;
pub use crate::cubecl::{CudaExtensionCache, CudaExtensionCacheGuard};
}
#[cfg(any(feature = "cuda", feature = "webgpu"))]
use tenferro_tensor::*;
#[cfg(feature = "cuda")]
pub(crate) mod backend {
pub use tenferro_tensor::backend::*;
}
#[cfg(feature = "cuda")]
pub(crate) mod config {
pub use tenferro_tensor::config::*;
}
#[cfg(feature = "cuda")]
pub(crate) mod types {
pub(crate) use crate::CubeclBuffer;
pub use tenferro_tensor::types::*;
}
#[cfg(feature = "cuda")]
#[derive(Clone)]
pub(crate) struct CubeclBuffer<T> {
handle: cubecl_runtime::server::Handle,
len: usize,
pub(crate) _marker: std::marker::PhantomData<T>,
}
#[cfg(feature = "cuda")]
impl<T> std::fmt::Debug for CubeclBuffer<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("CubeclBuffer")
.field("len", &self.len)
.finish()
}
}
#[cfg(feature = "cuda")]
impl<T> CubeclBuffer<T> {
pub(crate) fn new(handle: cubecl_runtime::server::Handle, len: usize) -> Self {
Self {
handle,
len,
_marker: std::marker::PhantomData,
}
}
pub(crate) fn handle(&self) -> &cubecl_runtime::server::Handle {
&self.handle
}
pub(crate) fn element_len(&self) -> usize {
self.len
}
}
#[cfg(feature = "cuda")]
impl<T: Send + Sync + 'static> BackendBuffer<T> for CubeclBuffer<T> {
fn backend_family(&self) -> &'static str {
"cubecl"
}
fn len(&self) -> usize {
self.len
}
fn as_any(&self) -> &dyn Any {
self
}
}