aboutsummaryrefslogtreecommitdiffhomepage
path: root/zluda
diff options
context:
space:
mode:
authorAndrzej Janik <[email protected]>2021-09-19 00:39:43 +0000
committerAndrzej Janik <[email protected]>2021-09-19 00:39:43 +0000
commit9609f86033e9bff1e080ab9f7e856ed8ce3bd93d (patch)
treef2fca44b75f1f9788eb67a020ea20db89d2d2394 /zluda
parentafe912086895bb6a9c5d7f386fd8e7dd90561d63 (diff)
downloadZLUDA-9609f86033e9bff1e080ab9f7e856ed8ce3bd93d.tar.gz
ZLUDA-9609f86033e9bff1e080ab9f7e856ed8ce3bd93d.zip
Fix minor bugs
Diffstat (limited to 'zluda')
-rw-r--r--zluda/src/impl/module.rs23
1 files changed, 13 insertions, 10 deletions
diff --git a/zluda/src/impl/module.rs b/zluda/src/impl/module.rs
index 6234909..9732ec9 100644
--- a/zluda/src/impl/module.rs
+++ b/zluda/src/impl/module.rs
@@ -16,6 +16,7 @@ use hip_runtime_sys::{
use tempfile::NamedTempFile;
use crate::cuda::CUmodule;
+use crate::hip_call;
pub struct SpirvModule {
pub binaries: Vec<u32>,
@@ -73,28 +74,31 @@ pub(crate) fn load_data(
module: *mut CUmodule,
image: *const std::ffi::c_void,
) -> Result<(), hipError_t> {
+ if image == ptr::null() {
+ return Err(hipError_t::hipErrorInvalidValue);
+ }
+ if unsafe { *(image as *const u32) } == 0x464c457f {
+ return match unsafe { hipModuleLoadData(module as _, image) } {
+ hipError_t::hipSuccess => Ok(()),
+ e => Err(e),
+ };
+ }
let spirv_data = SpirvModule::new_raw(image as *const _)?;
load_data_impl(module, spirv_data)
}
pub fn load_data_impl(pmod: *mut CUmodule, spirv_data: SpirvModule) -> Result<(), hipError_t> {
let mut dev = 0;
- let err = unsafe { hipCtxGetDevice(&mut dev) };
- if err != hipError_t::hipSuccess {
- return Err(err);
- }
+ hip_call! { hipCtxGetDevice(&mut dev) };
let mut props = unsafe { mem::zeroed() };
- let err = unsafe { hipGetDeviceProperties(&mut props, dev) };
+ hip_call! { hipGetDeviceProperties(&mut props, dev) };
let arch_binary = compile_amd(
&props,
iter::once(&spirv_data.binaries[..]),
spirv_data.should_link_ptx_impl,
)
.map_err(|_| hipError_t::hipErrorUnknown)?;
- let err = unsafe { hipModuleLoadData(pmod as _, arch_binary.as_ptr() as _) };
- if err != hipError_t::hipSuccess {
- return Err(err);
- }
+ hip_call! { hipModuleLoadData(pmod as _, arch_binary.as_ptr() as _) };
Ok(())
}
@@ -172,7 +176,6 @@ pub(crate) fn compile_amd<'a>(
llvm_link.push("llvm-link");
let mut linker_cmd = Command::new(&llvm_link);
linker_cmd
- .arg("--only-needed")
.arg("-o")
.arg(linked_binary.path())
.args(llvm_files.iter().map(|f| f.path()))