Skip to content

Commit f1fa04f

Browse files
committed
Upgrade to latest cuda-sys
`cuda-sys` was split into several crates with the release of version 0.3. For RustaCUDA, the `cuda-driver-sys` crate is used, which contains all the functionality that is currently needed.
1 parent ad5630b commit f1fa04f

File tree

14 files changed

+201
-165
lines changed

14 files changed

+201
-165
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ travis-ci = { repository = "bheisler/RustaCUDA" }
1616
maintenance = { status = "actively-developed" }
1717

1818
[dependencies]
19-
cuda-sys = "0.2"
19+
cuda-driver-sys = "0.3"
2020
bitflags = "1.2"
2121
rustacuda_derive = { version = "0.1.2", path = "rustacuda_derive" }
2222
rustacuda_core = { version = "0.1.2", path = "rustacuda_core" }

src/context.rs

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ use crate::device::Device;
116116
use crate::error::{CudaResult, DropResult, ToResult};
117117
use crate::private::Sealed;
118118
use crate::CudaApiVersion;
119-
use cuda_sys::cuda::{self, CUcontext};
119+
use cuda_driver_sys::CUcontext;
120120
use std::mem;
121121
use std::mem::transmute;
122122
use std::ptr;
@@ -262,7 +262,7 @@ impl Context {
262262
// lifetime guarantees so we create-and-push, then pop, then the programmer has to
263263
// push again.
264264
let mut ctx: CUcontext = ptr::null_mut();
265-
cuda::cuCtxCreate_v2(
265+
cuda_driver_sys::cuCtxCreate_v2(
266266
&mut ctx as *mut CUcontext,
267267
flags.bits(),
268268
device.into_inner(),
@@ -294,7 +294,8 @@ impl Context {
294294
pub fn get_api_version(&self) -> CudaResult<CudaApiVersion> {
295295
unsafe {
296296
let mut api_version = 0u32;
297-
cuda::cuCtxGetApiVersion(self.inner, &mut api_version as *mut u32).to_result()?;
297+
cuda_driver_sys::cuCtxGetApiVersion(self.inner, &mut api_version as *mut u32)
298+
.to_result()?;
298299
Ok(CudaApiVersion {
299300
version: api_version as i32,
300301
})
@@ -358,7 +359,7 @@ impl Context {
358359

359360
unsafe {
360361
let inner = mem::replace(&mut ctx.inner, ptr::null_mut());
361-
match cuda::cuCtxDestroy_v2(inner).to_result() {
362+
match cuda_driver_sys::cuCtxDestroy_v2(inner).to_result() {
362363
Ok(()) => {
363364
mem::forget(ctx);
364365
Ok(())
@@ -377,7 +378,7 @@ impl Drop for Context {
377378
unsafe {
378379
let inner = mem::replace(&mut self.inner, ptr::null_mut());
379380
// No choice but to panic here.
380-
cuda::cuCtxDestroy_v2(inner)
381+
cuda_driver_sys::cuCtxDestroy_v2(inner)
381382
.to_result()
382383
.expect("Failed to destroy context");
383384
}
@@ -434,7 +435,8 @@ impl UnownedContext {
434435
pub fn get_api_version(&self) -> CudaResult<CudaApiVersion> {
435436
unsafe {
436437
let mut api_version = 0u32;
437-
cuda::cuCtxGetApiVersion(self.inner, &mut api_version as *mut u32).to_result()?;
438+
cuda_driver_sys::cuCtxGetApiVersion(self.inner, &mut api_version as *mut u32)
439+
.to_result()?;
438440
Ok(CudaApiVersion {
439441
version: api_version as i32,
440442
})
@@ -468,7 +470,7 @@ impl ContextStack {
468470
pub fn pop() -> CudaResult<UnownedContext> {
469471
unsafe {
470472
let mut ctx: CUcontext = ptr::null_mut();
471-
cuda::cuCtxPopCurrent_v2(&mut ctx as *mut CUcontext).to_result()?;
473+
cuda_driver_sys::cuCtxPopCurrent_v2(&mut ctx as *mut CUcontext).to_result()?;
472474
Ok(UnownedContext { inner: ctx })
473475
}
474476
}
@@ -493,7 +495,7 @@ impl ContextStack {
493495
/// ```
494496
pub fn push<C: ContextHandle>(ctx: &C) -> CudaResult<()> {
495497
unsafe {
496-
cuda::cuCtxPushCurrent_v2(ctx.get_inner()).to_result()?;
498+
cuda_driver_sys::cuCtxPushCurrent_v2(ctx.get_inner()).to_result()?;
497499
Ok(())
498500
}
499501
}
@@ -540,8 +542,10 @@ impl CurrentContext {
540542
pub fn get_cache_config() -> CudaResult<CacheConfig> {
541543
unsafe {
542544
let mut config = CacheConfig::PreferNone;
543-
cuda::cuCtxGetCacheConfig(&mut config as *mut CacheConfig as *mut cuda::CUfunc_cache)
544-
.to_result()?;
545+
cuda_driver_sys::cuCtxGetCacheConfig(
546+
&mut config as *mut CacheConfig as *mut cuda_driver_sys::CUfunc_cache,
547+
)
548+
.to_result()?;
545549
Ok(config)
546550
}
547551
}
@@ -566,7 +570,8 @@ impl CurrentContext {
566570
pub fn get_device() -> CudaResult<Device> {
567571
unsafe {
568572
let mut device = Device { device: 0 };
569-
cuda::cuCtxGetDevice(&mut device.device as *mut cuda::CUdevice).to_result()?;
573+
cuda_driver_sys::cuCtxGetDevice(&mut device.device as *mut cuda_driver_sys::CUdevice)
574+
.to_result()?;
570575
Ok(device)
571576
}
572577
}
@@ -591,7 +596,7 @@ impl CurrentContext {
591596
pub fn get_flags() -> CudaResult<ContextFlags> {
592597
unsafe {
593598
let mut flags = 0u32;
594-
cuda::cuCtxGetFlags(&mut flags as *mut u32).to_result()?;
599+
cuda_driver_sys::cuCtxGetFlags(&mut flags as *mut u32).to_result()?;
595600
Ok(ContextFlags::from_bits_truncate(flags))
596601
}
597602
}
@@ -616,7 +621,8 @@ impl CurrentContext {
616621
pub fn get_resource_limit(resource: ResourceLimit) -> CudaResult<usize> {
617622
unsafe {
618623
let mut limit: usize = 0;
619-
cuda::cuCtxGetLimit(&mut limit as *mut usize, transmute(resource)).to_result()?;
624+
cuda_driver_sys::cuCtxGetLimit(&mut limit as *mut usize, transmute(resource))
625+
.to_result()?;
620626
Ok(limit)
621627
}
622628
}
@@ -641,8 +647,8 @@ impl CurrentContext {
641647
pub fn get_shared_memory_config() -> CudaResult<SharedMemoryConfig> {
642648
unsafe {
643649
let mut cfg = SharedMemoryConfig::DefaultBankSize;
644-
cuda::cuCtxGetSharedMemConfig(
645-
&mut cfg as *mut SharedMemoryConfig as *mut cuda::CUsharedconfig,
650+
cuda_driver_sys::cuCtxGetSharedMemConfig(
651+
&mut cfg as *mut SharedMemoryConfig as *mut cuda_driver_sys::CUsharedconfig,
646652
)
647653
.to_result()?;
648654
Ok(cfg)
@@ -676,7 +682,7 @@ impl CurrentContext {
676682
least: 0,
677683
greatest: 0,
678684
};
679-
cuda::cuCtxGetStreamPriorityRange(
685+
cuda_driver_sys::cuCtxGetStreamPriorityRange(
680686
&mut range.least as *mut i32,
681687
&mut range.greatest as *mut i32,
682688
)
@@ -711,7 +717,7 @@ impl CurrentContext {
711717
/// # }
712718
/// ```
713719
pub fn set_cache_config(cfg: CacheConfig) -> CudaResult<()> {
714-
unsafe { cuda::cuCtxSetCacheConfig(transmute(cfg)).to_result() }
720+
unsafe { cuda_driver_sys::cuCtxSetCacheConfig(transmute(cfg)).to_result() }
715721
}
716722

717723
/// Sets a requested resource limit for the current context.
@@ -756,7 +762,7 @@ impl CurrentContext {
756762
/// ```
757763
pub fn set_resource_limit(resource: ResourceLimit, limit: usize) -> CudaResult<()> {
758764
unsafe {
759-
cuda::cuCtxSetLimit(transmute(resource), limit).to_result()?;
765+
cuda_driver_sys::cuCtxSetLimit(transmute(resource), limit).to_result()?;
760766
Ok(())
761767
}
762768
}
@@ -782,7 +788,7 @@ impl CurrentContext {
782788
/// # }
783789
/// ```
784790
pub fn set_shared_memory_config(cfg: SharedMemoryConfig) -> CudaResult<()> {
785-
unsafe { cuda::cuCtxSetSharedMemConfig(transmute(cfg)).to_result() }
791+
unsafe { cuda_driver_sys::cuCtxSetSharedMemConfig(transmute(cfg)).to_result() }
786792
}
787793

788794
/// Returns a non-owning handle to the current context.
@@ -805,7 +811,7 @@ impl CurrentContext {
805811
pub fn get_current() -> CudaResult<UnownedContext> {
806812
unsafe {
807813
let mut ctx: CUcontext = ptr::null_mut();
808-
cuda::cuCtxGetCurrent(&mut ctx as *mut CUcontext).to_result()?;
814+
cuda_driver_sys::cuCtxGetCurrent(&mut ctx as *mut CUcontext).to_result()?;
809815
Ok(UnownedContext { inner: ctx })
810816
}
811817
}
@@ -833,15 +839,15 @@ impl CurrentContext {
833839
/// ```
834840
pub fn set_current<C: ContextHandle>(c: &C) -> CudaResult<()> {
835841
unsafe {
836-
cuda::cuCtxSetCurrent(c.get_inner()).to_result()?;
842+
cuda_driver_sys::cuCtxSetCurrent(c.get_inner()).to_result()?;
837843
Ok(())
838844
}
839845
}
840846

841847
/// Block to wait for a context's tasks to complete.
842848
pub fn synchronize() -> CudaResult<()> {
843849
unsafe {
844-
cuda::cuCtxSynchronize().to_result()?;
850+
cuda_driver_sys::cuCtxSynchronize().to_result()?;
845851
Ok(())
846852
}
847853
}

src/device.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Functions and types for enumerating CUDA devices and retrieving information about them.
22
33
use crate::error::{CudaResult, ToResult};
4-
use cuda_sys::cuda::*;
4+
use cuda_driver_sys::*;
55
use std::ffi::CStr;
66
use std::ops::Range;
77

0 commit comments

Comments
 (0)