diff --git a/zluda/src/impl/export_table.rs b/zluda/src/impl/export_table.rs index bfae799..00df754 100644 --- a/zluda/src/impl/export_table.rs +++ b/zluda/src/impl/export_table.rs @@ -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::(), - ) as *mut HeapAllocRecord; + let halloc = os::heap_alloc(global_state.global_heap, mem::size_of::()) + 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() diff --git a/zluda/src/impl/mod.rs b/zluda/src/impl/mod.rs index 48e9a24..55c047f 100644 --- a/zluda/src/impl/mod.rs +++ b/zluda/src/impl/mod.rs @@ -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); } diff --git a/zluda/src/impl/os_unix.rs b/zluda/src/impl/os_unix.rs new file mode 100644 index 0000000..e11211d --- /dev/null +++ b/zluda/src/impl/os_unix.rs @@ -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!() +} diff --git a/zluda/src/impl/os_win.rs b/zluda/src/impl/os_win.rs new file mode 100644 index 0000000..427920e --- /dev/null +++ b/zluda/src/impl/os_win.rs @@ -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); +}