Fix build on Linux

This commit is contained in:
Andrzej Janik 2021-06-27 02:33:57 +02:00
commit 23306e944b
4 changed files with 37 additions and 11 deletions

View file

@ -1,6 +1,5 @@
use winapi::um::heapapi::{HeapAlloc, HeapFree};
use crate::cuda::CUresult;
use crate::r#impl::os;
use crate::{
cuda::{CUcontext, CUdevice, CUmodule, CUuuid},
cuda_impl,
@ -488,11 +487,8 @@ unsafe extern "system" fn heap_alloc(
return CUresult::CUDA_ERROR_INVALID_VALUE;
}
let halloc = GlobalState::lock(|global_state| {
let halloc = HeapAlloc(
global_state.global_heap,
0,
mem::size_of::<HeapAllocRecord>(),
) as *mut HeapAllocRecord;
let halloc = os::heap_alloc(global_state.global_heap, mem::size_of::<HeapAllocRecord>())
as *mut HeapAllocRecord;
if halloc == ptr::null_mut() {
return Err(CUresult::CUDA_ERROR_OUT_OF_MEMORY);
}
@ -520,7 +516,7 @@ unsafe extern "system" fn heap_free(halloc: *mut HeapAllocRecord, arg1: *mut usi
*arg1 = (*halloc).arg2;
}
GlobalState::lock(|global_state| {
HeapFree(global_state.global_heap, 0, halloc as *mut _);
os::heap_free(global_state.global_heap, halloc as *mut _);
()
})
.encuda()

View file

@ -1,5 +1,3 @@
use winapi::um::{heapapi::HeapCreate, winnt::HEAP_NO_SERIALIZE};
use crate::{
cuda::{CUctx_st, CUdevice, CUdeviceptr, CUfunc_st, CUmod_st, CUresult, CUstream_st},
r#impl::device::Device,
@ -22,6 +20,9 @@ pub mod export_table;
pub mod function;
pub mod memory;
pub mod module;
#[cfg_attr(windows, path = "os_win.rs")]
#[cfg_attr(not(windows), path = "os_unix.rs")]
pub(crate) mod os;
pub mod stream;
#[cfg(debug_assertions)]
@ -304,7 +305,7 @@ pub fn init() -> Result<(), CUresult> {
None => return Err(CUresult::CUDA_ERROR_UNKNOWN),
Some(driver) => device::init(&driver)?,
};
let global_heap = unsafe { HeapCreate(HEAP_NO_SERIALIZE, 0, 0) };
let global_heap = unsafe { os::heap_create() };
if global_heap == ptr::null_mut() {
return Err(CUresult::CUDA_ERROR_OUT_OF_MEMORY);
}

13
zluda/src/impl/os_unix.rs Normal file
View file

@ -0,0 +1,13 @@
use std::ptr;
unsafe fn heap_create() -> *mut c_void {
ptr::null_mut()
}
unsafe fn heap_alloc(heap: *mut c_void, bytes: usize) -> *mut c_void {
todo!()
}
unsafe fn heap_free(heap: *mut c_void, alloc: *mut c_void) {
todo!()
}

16
zluda/src/impl/os_win.rs Normal file
View file

@ -0,0 +1,16 @@
use std::ffi::c_void;
use winapi::um::heapapi::{HeapAlloc, HeapFree};
use winapi::um::{heapapi::HeapCreate, winnt::HEAP_NO_SERIALIZE};
pub unsafe fn heap_create() -> *mut c_void {
HeapCreate(HEAP_NO_SERIALIZE, 0, 0)
}
pub unsafe fn heap_alloc(heap: *mut c_void, bytes: usize) -> *mut c_void {
HeapAlloc(heap, 0, bytes)
}
pub unsafe fn heap_free(heap: *mut c_void, alloc: *mut c_void) {
HeapFree(heap, 0, alloc);
}