gpu/
host_dev.rs

1/// Disallow arbitrary implementations of HostToDev.
2/// Allow the safe conversion from host types Self to device types T.
3trait HostToDevPrivateSeal<T> {}
4
5/// Expose the convert function to users.
6/// This trait is sealed to prevent arbitrary implementations.
7/// Only types that implement HostToDevPrivateSeal can implement this trait.
8/// This ensures that only safe conversions are allowed,
9/// ensuring safe host-to-device interface.
10#[allow(private_bounds)]
11pub trait HostToDev<T>: Sized + HostToDevPrivateSeal<T> {
12    fn convert(self) -> T {
13        unimplemented!()
14    }
15}
16
17impl<T> HostToDevPrivateSeal<T> for T {}
18
19impl<T> HostToDev<T> for T {}
20
21#[cfg(not(feature = "codegen_tests"))]
22impl<'a, 'b: 'a, T: ?Sized> HostToDevPrivateSeal<&'a T> for &'a cuda_bindings::TensorView<'b, T> {}
23
24/// Allow host-side &`CudaMemBox<T>`  to device-side &T
25#[cfg(not(feature = "codegen_tests"))]
26impl<'a, 'b: 'a, T: ?Sized> HostToDev<&'a T> for &'a cuda_bindings::TensorView<'b, T> {}
27
28/// Allow host-side &mut CudaMemBox<T>  to device-side GpuGlobal<T>
29#[cfg(not(feature = "codegen_tests"))]
30impl<'a, 'b: 'a, T: ?Sized> HostToDevPrivateSeal<crate::global::GpuGlobal<'a, T>>
31    for &'a mut cuda_bindings::TensorViewMut<'b, T>
32{
33}
34
35/// Allow host-side T to device-side T
36#[cfg(not(feature = "codegen_tests"))]
37impl<'a, 'b: 'a, T: ?Sized> HostToDev<crate::global::GpuGlobal<'a, T>>
38    for &'a mut cuda_bindings::TensorViewMut<'b, T>
39{
40}