aboutsummaryrefslogtreecommitdiffhomepage
path: root/level_zero
diff options
context:
space:
mode:
authorAndrzej Janik <[email protected]>2020-10-02 20:34:45 +0200
committerAndrzej Janik <[email protected]>2020-10-04 19:53:07 +0200
commit27d25865af2bf51ca55b223e634208234d1a141a (patch)
tree695f081f09cd22ffbc04effa0e947abba82bc50d /level_zero
parent9a65dd32f5898eb9dd3edf7cdddb1513a7a754ed (diff)
downloadZLUDA-27d25865af2bf51ca55b223e634208234d1a141a.tar.gz
ZLUDA-27d25865af2bf51ca55b223e634208234d1a141a.zip
Add support for top-level global variables, improve array support
Diffstat (limited to 'level_zero')
-rw-r--r--level_zero/src/ze.rs57
1 files changed, 38 insertions, 19 deletions
diff --git a/level_zero/src/ze.rs b/level_zero/src/ze.rs
index 559805e..5ced5d0 100644
--- a/level_zero/src/ze.rs
+++ b/level_zero/src/ze.rs
@@ -1,6 +1,6 @@
use crate::sys;
use std::{
- ffi::{c_void, CStr},
+ ffi::{c_void, CStr, CString},
fmt::Debug,
marker::PhantomData,
mem, ptr,
@@ -238,23 +238,16 @@ impl Drop for CommandQueue {
pub struct Module(sys::ze_module_handle_t);
impl Module {
- pub unsafe fn as_ffi(&self) -> sys::ze_module_handle_t {
- self.0
- }
- pub unsafe fn from_ffi(x: sys::ze_module_handle_t) -> Self {
- Self(x)
- }
-
pub fn new_spirv(
ctx: &mut Context,
d: &Device,
bin: &[u8],
opts: Option<&CStr>,
- ) -> Result<Self> {
+ ) -> (Result<Self>, BuildLog) {
Module::new(ctx, true, d, bin, opts)
}
- pub fn new_native(ctx: &mut Context, d: &Device, bin: &[u8]) -> Result<Self> {
+ pub fn new_native(ctx: &mut Context, d: &Device, bin: &[u8]) -> (Result<Self>, BuildLog) {
Module::new(ctx, false, d, bin, None)
}
@@ -264,7 +257,7 @@ impl Module {
d: &Device,
bin: &[u8],
opts: Option<&CStr>,
- ) -> Result<Self> {
+ ) -> (Result<Self>, BuildLog) {
let desc = sys::ze_module_desc_t {
stype: sys::ze_structure_type_t::ZE_STRUCTURE_TYPE_MODULE_DESC,
pNext: ptr::null(),
@@ -279,14 +272,14 @@ impl Module {
pConstants: ptr::null(),
};
let mut result: sys::ze_module_handle_t = ptr::null_mut();
- check!(sys::zeModuleCreate(
- ctx.0,
- d.0,
- &desc,
- &mut result,
- ptr::null_mut()
- ));
- Ok(Module(result))
+ let mut log_handle = ptr::null_mut();
+ let err = unsafe { sys::zeModuleCreate(ctx.0, d.0, &desc, &mut result, &mut log_handle) };
+ let log = BuildLog(log_handle);
+ if err != crate::sys::ze_result_t::ZE_RESULT_SUCCESS {
+ (Result::Err(err), log)
+ } else {
+ (Ok(Module(result)), log)
+ }
}
}
@@ -297,6 +290,32 @@ impl Drop for Module {
}
}
+pub struct BuildLog(sys::ze_module_build_log_handle_t);
+
+impl BuildLog {
+ pub unsafe fn as_ffi(&self) -> sys::ze_module_build_log_handle_t {
+ self.0
+ }
+ pub unsafe fn from_ffi(x: sys::ze_module_build_log_handle_t) -> Self {
+ Self(x)
+ }
+
+ pub fn get_cstring(&self) -> Result<CString> {
+ let mut size = 0;
+ check! { sys::zeModuleBuildLogGetString(self.0, &mut size, ptr::null_mut()) };
+ let mut str_vec = vec![0u8; size];
+ check! { sys::zeModuleBuildLogGetString(self.0, &mut size, str_vec.as_mut_ptr() as *mut i8) };
+ str_vec.pop();
+ Ok(CString::new(str_vec).map_err(|_| sys::ze_result_t::ZE_RESULT_ERROR_UNKNOWN)?)
+ }
+}
+
+impl Drop for BuildLog {
+ fn drop(&mut self) {
+ check_panic!(sys::zeModuleBuildLogDestroy(self.0));
+ }
+}
+
pub trait SafeRepr {}
impl SafeRepr for u8 {}
impl SafeRepr for i8 {}