mirror of
https://github.com/vosen/ZLUDA.git
synced 2025-04-24 18:38:53 +03:00
Fix minor bugs
This commit is contained in:
@ -2,7 +2,7 @@
|
|||||||
.target sm_30
|
.target sm_30
|
||||||
.address_size 64
|
.address_size 64
|
||||||
|
|
||||||
.func (.param.u64 output) incr (.param.u64 input);
|
.visible .func (.param.u64 output) incr (.param.u64 input);
|
||||||
|
|
||||||
.visible .entry call(
|
.visible .entry call(
|
||||||
.param .u64 input,
|
.param .u64 input,
|
||||||
@ -26,7 +26,7 @@
|
|||||||
ret;
|
ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
.func (.param .u64 output) incr(
|
.visible .func (.param .u64 output) incr(
|
||||||
.param .u64 input
|
.param .u64 input
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
@ -543,10 +543,10 @@ fn emit_directives<'input>(
|
|||||||
let f_body = match &f.body {
|
let f_body = match &f.body {
|
||||||
Some(f) => f,
|
Some(f) => f,
|
||||||
None => {
|
None => {
|
||||||
if f.linkage == ast::LinkingDirective::NONE {
|
if f.linkage.contains(ast::LinkingDirective::EXTERN) {
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
&empty_body
|
&empty_body
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -16,6 +16,7 @@ use hip_runtime_sys::{
|
|||||||
use tempfile::NamedTempFile;
|
use tempfile::NamedTempFile;
|
||||||
|
|
||||||
use crate::cuda::CUmodule;
|
use crate::cuda::CUmodule;
|
||||||
|
use crate::hip_call;
|
||||||
|
|
||||||
pub struct SpirvModule {
|
pub struct SpirvModule {
|
||||||
pub binaries: Vec<u32>,
|
pub binaries: Vec<u32>,
|
||||||
@ -73,28 +74,31 @@ pub(crate) fn load_data(
|
|||||||
module: *mut CUmodule,
|
module: *mut CUmodule,
|
||||||
image: *const std::ffi::c_void,
|
image: *const std::ffi::c_void,
|
||||||
) -> Result<(), hipError_t> {
|
) -> 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 _)?;
|
let spirv_data = SpirvModule::new_raw(image as *const _)?;
|
||||||
load_data_impl(module, spirv_data)
|
load_data_impl(module, spirv_data)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_data_impl(pmod: *mut CUmodule, spirv_data: SpirvModule) -> Result<(), hipError_t> {
|
pub fn load_data_impl(pmod: *mut CUmodule, spirv_data: SpirvModule) -> Result<(), hipError_t> {
|
||||||
let mut dev = 0;
|
let mut dev = 0;
|
||||||
let err = unsafe { hipCtxGetDevice(&mut dev) };
|
hip_call! { hipCtxGetDevice(&mut dev) };
|
||||||
if err != hipError_t::hipSuccess {
|
|
||||||
return Err(err);
|
|
||||||
}
|
|
||||||
let mut props = unsafe { mem::zeroed() };
|
let mut props = unsafe { mem::zeroed() };
|
||||||
let err = unsafe { hipGetDeviceProperties(&mut props, dev) };
|
hip_call! { hipGetDeviceProperties(&mut props, dev) };
|
||||||
let arch_binary = compile_amd(
|
let arch_binary = compile_amd(
|
||||||
&props,
|
&props,
|
||||||
iter::once(&spirv_data.binaries[..]),
|
iter::once(&spirv_data.binaries[..]),
|
||||||
spirv_data.should_link_ptx_impl,
|
spirv_data.should_link_ptx_impl,
|
||||||
)
|
)
|
||||||
.map_err(|_| hipError_t::hipErrorUnknown)?;
|
.map_err(|_| hipError_t::hipErrorUnknown)?;
|
||||||
let err = unsafe { hipModuleLoadData(pmod as _, arch_binary.as_ptr() as _) };
|
hip_call! { hipModuleLoadData(pmod as _, arch_binary.as_ptr() as _) };
|
||||||
if err != hipError_t::hipSuccess {
|
|
||||||
return Err(err);
|
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,7 +176,6 @@ pub(crate) fn compile_amd<'a>(
|
|||||||
llvm_link.push("llvm-link");
|
llvm_link.push("llvm-link");
|
||||||
let mut linker_cmd = Command::new(&llvm_link);
|
let mut linker_cmd = Command::new(&llvm_link);
|
||||||
linker_cmd
|
linker_cmd
|
||||||
.arg("--only-needed")
|
|
||||||
.arg("-o")
|
.arg("-o")
|
||||||
.arg(linked_binary.path())
|
.arg(linked_binary.path())
|
||||||
.args(llvm_files.iter().map(|f| f.path()))
|
.args(llvm_files.iter().map(|f| f.path()))
|
||||||
|
Reference in New Issue
Block a user