use std::sync::Arc;
use crate::error::CudaError;
mod creation;
mod device;
mod diagnostics;
mod host_budget;
mod inner;
mod kernel_cache;
mod kernel_dispatch;
mod lifecycle;
mod operations;
mod pinned_host;
mod pointer;
mod resource_creation;
#[cfg(test)]
mod test_kernels;
pub use self::diagnostics::CudaContextDiagnostics;
#[doc(hidden)]
pub use self::host_budget::{CudaExternalHostOwner, CudaExternalHostReservation};
#[cfg(test)]
pub(crate) use self::pinned_host::validate_non_null_pinned_host_allocation;
#[cfg(test)]
pub(crate) use self::test_kernels::{CudaKernelModule, CudaKernelName};
pub(crate) use self::{
inner::{ContextInner, ContextOwnership},
kernel_cache::{CompiledKernel, CompiledKernelKey},
lifecycle::ContextResourceLifecycle,
pinned_host::PinnedUploadStaging,
resource_creation::{validate_device_allocation, validate_resource_handle},
};
#[derive(Clone)]
pub struct CudaContext {
pub(crate) inner: Arc<ContextInner>,
}
impl CudaContext {
#[doc(hidden)]
pub fn prepare_operation(&self) -> Result<(), CudaError> {
self.inner.set_current()
}
#[doc(hidden)]
#[must_use]
pub fn resource_lifetimes_poisoned(&self) -> bool {
self.inner.resource_lifetimes_poisoned()
}
#[doc(hidden)]
#[must_use]
pub fn is_same_context(&self, other: &Self) -> bool {
self.inner.context == other.inner.context
}
#[doc(hidden)]
#[must_use]
pub fn device_ordinal(&self) -> usize {
self.inner.device_ordinal
}
#[doc(hidden)]
pub fn validate_device_pointer(&self, ptr: u64) -> Result<u64, CudaError> {
self.inner.resolve_pointer_for_context(ptr)
}
}
impl std::fmt::Debug for CudaContext {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("CudaContext").finish_non_exhaustive()
}
}
#[cfg(test)]
mod structure_tests;