diff options
author | Andrzej Janik <[email protected]> | 2024-12-02 00:29:57 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2024-12-02 00:29:57 +0100 |
commit | 7a6df9dcbf59edef371e7f63c16c64916ddb0c0b (patch) | |
tree | 7800524ba25d38c514f1c769c9c1b665542c5500 /zluda/src/impl/pointer.rs | |
parent | 870fed4bb69d919a10822032d65ec20f385df9d7 (diff) | |
download | ZLUDA-7a6df9dcbf59edef371e7f63c16c64916ddb0c0b.tar.gz ZLUDA-7a6df9dcbf59edef371e7f63c16c64916ddb0c0b.zip |
Fix host code and update to CUDA 12.4 (#299)
Diffstat (limited to 'zluda/src/impl/pointer.rs')
-rw-r--r-- | zluda/src/impl/pointer.rs | 57 |
1 files changed, 22 insertions, 35 deletions
diff --git a/zluda/src/impl/pointer.rs b/zluda/src/impl/pointer.rs index 2b925cd..6b458a0 100644 --- a/zluda/src/impl/pointer.rs +++ b/zluda/src/impl/pointer.rs @@ -1,53 +1,40 @@ -use std::{ffi::c_void, mem, ptr}; - -use hip_runtime_sys::{hipError_t, hipMemoryType, hipPointerGetAttributes}; - -use crate::{ - cuda::{CUdeviceptr, CUmemorytype, CUpointer_attribute}, - hip_call, -}; +use cuda_types::*; +use hip_runtime_sys::*; +use std::{ffi::c_void, ptr}; pub(crate) unsafe fn get_attribute( data: *mut c_void, - attribute: CUpointer_attribute, - ptr: CUdeviceptr, -) -> Result<(), hipError_t> { + attribute: hipPointer_attribute, + ptr: hipDeviceptr_t, +) -> hipError_t { if data == ptr::null_mut() { - return Err(hipError_t::hipErrorInvalidValue); + return hipError_t::ErrorInvalidValue; } - let mut attribs = mem::zeroed(); - hip_call! { hipPointerGetAttributes(&mut attribs, ptr.0 as _) }; match attribute { - CUpointer_attribute::CU_POINTER_ATTRIBUTE_CONTEXT => { - *(data as *mut _) = attribs.device; - Ok(()) - } - CUpointer_attribute::CU_POINTER_ATTRIBUTE_MEMORY_TYPE => { - *(data as *mut _) = memory_type(attribs.memoryType)?; - Ok(()) - } - CUpointer_attribute::CU_POINTER_ATTRIBUTE_DEVICE_POINTER => { - *(data as *mut _) = attribs.devicePointer; - Ok(()) - } - CUpointer_attribute::CU_POINTER_ATTRIBUTE_HOST_POINTER => { - *(data as *mut _) = attribs.hostPointer; - Ok(()) - } - CUpointer_attribute::CU_POINTER_ATTRIBUTE_IS_MANAGED => { - *(data as *mut _) = attribs.isManaged; + // TODO: implement by getting device ordinal & allocation start, + // then go through every context for that device + hipPointer_attribute::HIP_POINTER_ATTRIBUTE_CONTEXT => hipError_t::ErrorNotSupported, + hipPointer_attribute::HIP_POINTER_ATTRIBUTE_MEMORY_TYPE => { + let mut hip_result = hipMemoryType(0); + hipPointerGetAttribute( + (&mut hip_result as *mut hipMemoryType).cast::<c_void>(), + attribute, + ptr, + )?; + let cuda_result = memory_type(hip_result)?; + unsafe { *(data.cast()) = cuda_result }; Ok(()) } - _ => Err(hipError_t::hipErrorNotSupported), + _ => unsafe { hipPointerGetAttribute(data, attribute, ptr) }, } } -pub(crate) fn memory_type(cu: hipMemoryType) -> Result<CUmemorytype, hipError_t> { +fn memory_type(cu: hipMemoryType) -> Result<CUmemorytype, hipErrorCode_t> { match cu { hipMemoryType::hipMemoryTypeHost => Ok(CUmemorytype::CU_MEMORYTYPE_HOST), hipMemoryType::hipMemoryTypeDevice => Ok(CUmemorytype::CU_MEMORYTYPE_DEVICE), hipMemoryType::hipMemoryTypeArray => Ok(CUmemorytype::CU_MEMORYTYPE_ARRAY), hipMemoryType::hipMemoryTypeUnified => Ok(CUmemorytype::CU_MEMORYTYPE_UNIFIED), - _ => Err(hipError_t::hipErrorInvalidValue), + _ => Err(hipErrorCode_t::InvalidValue), } } |