diff options
author | Andrzej Janik <[email protected]> | 2020-09-01 01:43:09 +0200 |
---|---|---|
committer | Andrzej Janik <[email protected]> | 2020-09-01 01:43:09 +0200 |
commit | 2e4cadc2ab061c61bacd43fab9a375b5492a1897 (patch) | |
tree | c5ca5d149c8621437a9d861e1a9872052792fda9 /level_zero | |
parent | 34dc149be1cc83ecd931c0da742befe3eb67feaf (diff) | |
download | ZLUDA-2e4cadc2ab061c61bacd43fab9a375b5492a1897.tar.gz ZLUDA-2e4cadc2ab061c61bacd43fab9a375b5492a1897.zip |
Refactor main library, implement some more functionality
Diffstat (limited to 'level_zero')
-rw-r--r-- | level_zero/src/ze.rs | 42 |
1 files changed, 17 insertions, 25 deletions
diff --git a/level_zero/src/ze.rs b/level_zero/src/ze.rs index 3e7d3ce..cee736c 100644 --- a/level_zero/src/ze.rs +++ b/level_zero/src/ze.rs @@ -1,7 +1,7 @@ use crate::sys;
use std::{
ffi::{c_void, CStr},
- fmt::{Debug, Display},
+ fmt::Debug,
marker::PhantomData,
mem, ptr,
};
@@ -12,7 +12,7 @@ macro_rules! check { {
let err = unsafe { $expr };
if err != crate::sys::ze_result_t::ZE_RESULT_SUCCESS {
- return Result::Err(Error(err));
+ return Result::Err(err);
}
}
};
@@ -27,39 +27,24 @@ macro_rules! check_panic { };
}
-pub type Result<T> = std::result::Result<T, Error>;
+pub type Result<T> = std::result::Result<T, sys::ze_result_t>;
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct Error(pub sys::ze_result_t);
-impl Error {
- fn new<T>(res: sys::ze_result_t, default: T) -> Result<T> {
- if res == sys::ze_result_t::ZE_RESULT_SUCCESS {
- Ok(default)
- } else {
- Err(Self(res))
- }
- }
-}
-
-impl Display for Error {
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- Debug::fmt(self, f)
- }
-}
-
-impl std::error::Error for Error {}
-
pub fn init() -> Result<()> {
- Error::new(
- unsafe { sys::zeInit(sys::ze_init_flags_t::ZE_INIT_FLAG_GPU_ONLY) },
- (),
- )
+ match unsafe { sys::zeInit(sys::ze_init_flags_t::ZE_INIT_FLAG_GPU_ONLY) } {
+ sys::ze_result_t::ZE_RESULT_SUCCESS => Ok(()),
+ e => Err(e),
+ }
}
#[repr(transparent)]
pub struct Driver(sys::ze_driver_handle_t);
+unsafe impl Send for Driver {}
+unsafe impl Sync for Driver {}
+
impl Driver {
pub unsafe fn as_ffi(&self) -> sys::ze_driver_handle_t {
self.0
@@ -184,6 +169,13 @@ impl Context { }
}
+impl Drop for Context {
+ #[allow(unused_must_use)]
+ fn drop(&mut self) {
+ check_panic! { sys::zeContextDestroy(self.0) };
+ }
+}
+
#[repr(transparent)]
pub struct CommandQueue(sys::ze_command_queue_handle_t);
|