j2k_cuda_runtime/context/device.rs
1// SPDX-License-Identifier: MIT OR Apache-2.0
2
3use crate::error::CudaError;
4
5use super::{creation::create_context, CudaContext};
6
7impl CudaContext {
8 /// Create a context for the system default CUDA device.
9 pub fn system_default() -> Result<Self, CudaError> {
10 Self::create_owned(0)
11 }
12
13 /// Retain the CUDA primary context for a selected device ordinal.
14 ///
15 /// This is the interoperability constructor for runtimes such as `CubeCL`
16 /// that also use CUDA primary contexts. Dropping the final clone releases
17 /// the retain; it never destroys the primary context directly.
18 pub fn retain_primary(device_ordinal: usize) -> Result<Self, CudaError> {
19 create_context(device_ordinal, true)
20 }
21
22 fn create_owned(device_ordinal: usize) -> Result<Self, CudaError> {
23 create_context(device_ordinal, false)
24 }
25}