1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use const_type_layout::{TypeGraphLayout, TypeLayout};

use crate::{
    lend::CudaAsRust,
    safety::{PortableBitSemantics, StackOnly},
    utils::ffi::DeviceMutPointer,
};

use super::{CudaExchangeBuffer, CudaExchangeItem};

#[doc(hidden)]
#[derive(TypeLayout)]
#[repr(C)]
pub struct CudaExchangeBufferCudaRepresentation<
    T: StackOnly + PortableBitSemantics + TypeGraphLayout,
    const M2D: bool,
    const M2H: bool,
>(
    pub(super) DeviceMutPointer<CudaExchangeItem<T, M2D, M2H>>,
    pub(super) usize,
);

unsafe impl<T: StackOnly + PortableBitSemantics + TypeGraphLayout, const M2D: bool, const M2H: bool>
    CudaAsRust for CudaExchangeBufferCudaRepresentation<T, M2D, M2H>
{
    type RustRepresentation = CudaExchangeBuffer<T, M2D, M2H>;

    #[cfg(feature = "device")]
    unsafe fn as_rust(
        this: &crate::utils::ffi::DeviceAccessible<Self>,
    ) -> Self::RustRepresentation {
        CudaExchangeBuffer {
            inner: super::device::CudaExchangeBufferDevice(core::mem::ManuallyDrop::new(
                crate::deps::alloc::boxed::Box::from_raw(core::slice::from_raw_parts_mut(
                    (**this).0 .0,
                    this.1,
                )),
            )),
        }
    }
}