Skip to content

Commit c47e0fc

Browse files
committed
Feat: impl Clone for Context
1 parent 1935bbf commit c47e0fc

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

crates/cust/src/context/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,18 @@ pub struct Context {
166166
device: cuda::CUdevice,
167167
}
168168

169+
impl Clone for Context {
170+
fn clone(&self) -> Self {
171+
// because we already retained a context on this device successfully (self), it is
172+
// exceedingly rare that this function would fail, therefore a silent panic
173+
// is mostly okay
174+
Self::new(Device {
175+
device: self.device,
176+
})
177+
.expect("Failed to clone context")
178+
}
179+
}
180+
169181
impl Context {
170182
/// Retains the primary context for this device and makes it current, incrementing the internal reference cycle
171183
/// that CUDA keeps track of. There is only one primary context associated with a device, multiple

0 commit comments

Comments
 (0)