From 0b3676769f2a7e7100c26904f8bdf2c9cc530eae Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Wed, 15 Mar 2017 14:10:41 +0000 Subject: [PATCH] wip: Wrap the cuda context Open question: leverage deref and drop to make push and pop more idiomatic. --- src/cuda/context.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/cuda/context.rs diff --git a/src/cuda/context.rs b/src/cuda/context.rs new file mode 100644 index 0000000..4eab0c5 --- /dev/null +++ b/src/cuda/context.rs @@ -0,0 +1,45 @@ +use ffi::cuda::*; + +use cuda::device::CuDevice; + +pub struct CuContext { + context : CUcontext, +} + +impl CuContext { + pub fn new(dev : CuDevice, flags : u32) -> Result { + let mut ctx = CuContext { context : 0 }; + let res = unsafe { cuCtxCreate(&mut ctx.context as *mut CUcontext, dev.device) } + + wrap!(ctx, res) + } + + pub fn get_api_version(&self) -> Result { + let mut ver = 0; + let res = unsafe { cuGetApiVersion(self.context, &mut ver as *mut u32)}; + + wrap!(ver, res) + } + + pub fn pop() -> Result<, CUresult> { + let res = unsafe { cuCtxPopCurrent + } +} + +/* TODO: leverage clone/drop/deref traits +impl Clone for CuContext { + +} + +impl Deref for CuContext { + +} +*/ + +impl Drop for CuContext { + fn drop(&mut self) { + unsafe { + cuCtxDestroy(self.context); + } + } +}