1#[cfg(feature = "cuda")]
28use std::any::Any;
29
30#[cfg(feature = "cuda")]
31mod cubecl;
32#[cfg(feature = "cuda")]
33mod kernels;
34#[cfg(feature = "webgpu")]
35mod webgpu;
36
37#[cfg(feature = "cuda")]
38pub use cubecl::{
39 cuda_capabilities, device_ptr, download_tensor, gpu_available, upload_tensor, CudaBackend,
40 CudaRuntime,
41};
42#[cfg(feature = "cuda")]
43#[doc(hidden)]
44pub use cubecl::{CudaExtensionCache, CudaExtensionCacheGuard};
45#[cfg(feature = "webgpu")]
46pub use webgpu::{
47 download_webgpu_tensor, upload_webgpu_tensor, webgpu_available, WebGpuBackend, WebGpuRuntime,
48};
49
50#[cfg(feature = "cuda")]
51#[doc(hidden)]
52pub mod cuda_interop {
53 pub use crate::cubecl::interop::*;
54 pub use crate::cubecl::{CudaExtensionCache, CudaExtensionCacheGuard};
55}
56
57#[cfg(any(feature = "cuda", feature = "webgpu"))]
58use tenferro_tensor::*;
59
60#[cfg(feature = "cuda")]
61pub(crate) mod backend {
62 pub use tenferro_tensor::backend::*;
63}
64
65#[cfg(feature = "cuda")]
66pub(crate) mod config {
67 pub use tenferro_tensor::config::*;
68}
69
70#[cfg(feature = "cuda")]
71pub(crate) mod types {
72 pub(crate) use crate::CubeclBuffer;
73 pub use tenferro_tensor::types::*;
74}
75
76#[cfg(feature = "cuda")]
78#[derive(Clone)]
79pub(crate) struct CubeclBuffer<T> {
80 handle: cubecl_runtime::server::Handle,
81 len: usize,
82 pub(crate) _marker: std::marker::PhantomData<T>,
83}
84
85#[cfg(feature = "cuda")]
86impl<T> std::fmt::Debug for CubeclBuffer<T> {
87 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
88 f.debug_struct("CubeclBuffer")
89 .field("len", &self.len)
90 .finish()
91 }
92}
93
94#[cfg(feature = "cuda")]
95impl<T> CubeclBuffer<T> {
96 pub(crate) fn new(handle: cubecl_runtime::server::Handle, len: usize) -> Self {
97 Self {
98 handle,
99 len,
100 _marker: std::marker::PhantomData,
101 }
102 }
103
104 pub(crate) fn handle(&self) -> &cubecl_runtime::server::Handle {
105 &self.handle
106 }
107
108 pub(crate) fn element_len(&self) -> usize {
109 self.len
110 }
111}
112
113#[cfg(feature = "cuda")]
114impl<T: Send + Sync + 'static> BackendBuffer<T> for CubeclBuffer<T> {
115 fn backend_family(&self) -> &'static str {
116 "cubecl"
117 }
118
119 fn len(&self) -> usize {
120 self.len
121 }
122
123 fn as_any(&self) -> &dyn Any {
124 self
125 }
126}