Skip to content

Commit fb73938

Browse files
committed
Merge branch 'vmx-uuid'
2 parents ad5630b + 3e46242 commit fb73938

File tree

15 files changed

+269
-168
lines changed

15 files changed

+269
-168
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Added
9+
- `Device::uuid` function, which returns the UUID of a device.
10+
11+
### Fixed
12+
- Upgraded `cuda-sys` 0.2 to `cuda-driver-sys` 0.3.
813

914
## [0.1.2] - February 29, 2019
1015
### Fixed
@@ -30,4 +35,4 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
3035
[Unreleased]: https://github.com/bheisler/RustaCUDA/compare/0.1.2...HEAD
3136
[0.1.0]: https://github.com/bheisler/RustaCUDA/compare/5e6d7bd...0.1.0
3237
[0.1.1]: https://github.com/bheisler/RustaCUDA/compare/0.1.0...0.1.1
33-
[0.1.2]: https://github.com/bheisler/RustaCUDA/compare/0.1.1...0.1.2
38+
[0.1.2]: https://github.com/bheisler/RustaCUDA/compare/0.1.1...0.1.2

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: 62 additions & 2 deletions
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

@@ -192,8 +192,37 @@ pub enum DeviceAttribute {
192192
ComputePreemptionSupported = 90,
193193
/// Device can access host registered memory at the same virtual address as the CPU
194194
CanUseHostPointerForRegisteredMem = 91,
195+
/// Stream memory operations are supported.
196+
CanUseStreamMemOps = 92,
197+
/// 64-bit stream memory operations are supported.
198+
CanUse64BitStreamMemOps = 93,
199+
/// Wait value NOR is supported
200+
CanUseStreamWaitValueNor = 94,
201+
/// Supports launching cooperative kernels
202+
CooperativeLaunch = 95,
203+
/// Supports launching cooperative kernels on multiple devices.
204+
CooperativeMultiDeviceLaunch = 96,
205+
/// Maximum opt-in shared memory per block.
206+
MaxSharedMemoryPerBlockOptin = 97,
207+
/// Stream memory operations can wait for flush.
208+
CanFlushRemoteWrites = 98,
209+
/// Device supports host memory registration
210+
HostRegisterSupported = 99,
211+
/// Device accesses pageable memory via the host page tables
212+
PageableMemoryAccessUsesHostPageTable = 100,
213+
/// Device supports direct access to device memory without migration
214+
DirectManagedMemAccessFromhost = 101,
215+
/// Device supports virual memory management APIs
216+
VirtualMemoryManagementSupported = 102,
217+
/// Device supports exporting memory to a posix file descriptor
218+
HandleTypePosixFileDescriptorSupported = 103,
219+
/// Device supports exporting memory to a Win32 NT handle
220+
HandleTypeWin32HandleSupported = 104,
221+
/// Device supports exporting memory to a Win32 KMT handle
222+
HandleTypeWin32KmtHandleSupported = 105,
223+
195224
#[doc(hidden)]
196-
__NonExhaustive = 92,
225+
__NonExhaustive = 106,
197226
}
198227

199228
/// Opaque handle to a CUDA device.
@@ -328,6 +357,29 @@ impl Device {
328357
}
329358
}
330359

360+
/// Returns the UUID of this device.
361+
///
362+
/// # Example
363+
/// ```
364+
/// # use rustacuda::*;
365+
/// # use std::error::Error;
366+
/// # fn main() -> Result<(), Box<dyn Error>> {
367+
/// # init(CudaFlags::empty())?;
368+
/// use rustacuda::device::Device;
369+
/// let device = Device::get_device(0)?;
370+
/// println!("Device UUID: {:?}", device.uuid()?);
371+
/// # Ok(())
372+
/// # }
373+
/// ```
374+
pub fn uuid(self) -> CudaResult<[u8; 16]> {
375+
unsafe {
376+
let mut cu_uuid = CUuuid { bytes: [0i8; 16] };
377+
cuDeviceGetUuid(&mut cu_uuid, self.device).to_result()?;
378+
let uuid: [u8; 16] = ::std::mem::transmute(cu_uuid.bytes);
379+
Ok(uuid)
380+
}
381+
}
382+
331383
/// Returns information about this device.
332384
///
333385
/// # Example
@@ -429,4 +481,12 @@ mod test {
429481
CUdevice_attribute_enum::CU_DEVICE_ATTRIBUTE_MAX as u32
430482
);
431483
}
484+
485+
#[test]
486+
fn test_uuid() -> Result<(), Box<dyn Error>> {
487+
test_init()?;
488+
let uuid = Device::get_device(0)?.uuid()?;
489+
println!("{:?}", uuid);
490+
Ok(())
491+
}
432492
}

0 commit comments

Comments
 (0)