aboutsummaryrefslogtreecommitdiffhomepage
path: root/zluda/src/impl/memory.rs
diff options
context:
space:
mode:
authorAndrzej Janik <[email protected]>2024-12-02 00:29:57 +0100
committerGitHub <[email protected]>2024-12-02 00:29:57 +0100
commit7a6df9dcbf59edef371e7f63c16c64916ddb0c0b (patch)
tree7800524ba25d38c514f1c769c9c1b665542c5500 /zluda/src/impl/memory.rs
parent870fed4bb69d919a10822032d65ec20f385df9d7 (diff)
downloadZLUDA-7a6df9dcbf59edef371e7f63c16c64916ddb0c0b.tar.gz
ZLUDA-7a6df9dcbf59edef371e7f63c16c64916ddb0c0b.zip
Fix host code and update to CUDA 12.4 (#299)
Diffstat (limited to 'zluda/src/impl/memory.rs')
-rw-r--r--zluda/src/impl/memory.rs80
1 files changed, 30 insertions, 50 deletions
diff --git a/zluda/src/impl/memory.rs b/zluda/src/impl/memory.rs
index 6041623..3843776 100644
--- a/zluda/src/impl/memory.rs
+++ b/zluda/src/impl/memory.rs
@@ -1,55 +1,35 @@
-use hip_runtime_sys::{
- hipDrvMemcpy3D, hipError_t, hipMemcpy3D, hipMemcpy3DParms, hipMemoryType, hipPitchedPtr,
- hipPos, HIP_MEMCPY3D,
-};
-use std::ptr;
+use hip_runtime_sys::*;
-use crate::{
- cuda::{CUDA_MEMCPY3D_st, CUdeviceptr, CUmemorytype, CUresult},
- hip_call,
-};
+pub(crate) fn alloc_v2(dptr: *mut hipDeviceptr_t, bytesize: usize) -> hipError_t {
+ unsafe { hipMalloc(dptr.cast(), bytesize) }?;
+ // TODO: parametrize for non-Geekbench
+ unsafe { hipMemsetD8(*dptr, 0, bytesize) }
+}
+
+pub(crate) fn free_v2(dptr: hipDeviceptr_t) -> hipError_t {
+ unsafe { hipFree(dptr.0) }
+}
+
+pub(crate) fn copy_dto_h_v2(
+ dst_host: *mut ::core::ffi::c_void,
+ src_device: hipDeviceptr_t,
+ byte_count: usize,
+) -> hipError_t {
+ unsafe { hipMemcpyDtoH(dst_host, src_device, byte_count) }
+}
-// TODO change HIP impl to 64 bits
-pub(crate) unsafe fn copy_3d(cu_copy: *const CUDA_MEMCPY3D_st) -> Result<(), hipError_t> {
- if cu_copy == ptr::null() {
- return Err(hipError_t::hipErrorInvalidValue);
- }
- let cu_copy = *cu_copy;
- let hip_copy = HIP_MEMCPY3D {
- srcXInBytes: cu_copy.srcXInBytes as u32,
- srcY: cu_copy.srcY as u32,
- srcZ: cu_copy.srcZ as u32,
- srcLOD: cu_copy.srcLOD as u32,
- srcMemoryType: memory_type(cu_copy.srcMemoryType)?,
- srcHost: cu_copy.srcHost,
- srcDevice: cu_copy.srcDevice.0 as _,
- srcArray: cu_copy.srcArray as _,
- srcPitch: cu_copy.srcPitch as u32,
- srcHeight: cu_copy.srcHeight as u32,
- dstXInBytes: cu_copy.dstXInBytes as u32,
- dstY: cu_copy.dstY as u32,
- dstZ: cu_copy.dstZ as u32,
- dstLOD: cu_copy.dstLOD as u32,
- dstMemoryType: memory_type(cu_copy.dstMemoryType)?,
- dstHost: cu_copy.dstHost,
- dstDevice: cu_copy.dstDevice.0 as _,
- dstArray: cu_copy.dstArray as _,
- dstPitch: cu_copy.dstPitch as u32,
- dstHeight: cu_copy.dstHeight as u32,
- WidthInBytes: cu_copy.WidthInBytes as u32,
- Height: cu_copy.Height as u32,
- Depth: cu_copy.Depth as u32,
- };
- hip_call! { hipDrvMemcpy3D(&hip_copy) };
- Ok(())
+pub(crate) fn copy_hto_d_v2(
+ dst_device: hipDeviceptr_t,
+ src_host: *const ::core::ffi::c_void,
+ byte_count: usize,
+) -> hipError_t {
+ unsafe { hipMemcpyHtoD(dst_device, src_host.cast_mut(), byte_count) }
}
-pub(crate) fn memory_type(cu: CUmemorytype) -> Result<hipMemoryType, hipError_t> {
- match cu {
- CUmemorytype::CU_MEMORYTYPE_HOST => Ok(hipMemoryType::hipMemoryTypeHost),
- CUmemorytype::CU_MEMORYTYPE_DEVICE => Ok(hipMemoryType::hipMemoryTypeDevice),
- CUmemorytype::CU_MEMORYTYPE_ARRAY => Ok(hipMemoryType::hipMemoryTypeArray),
- CUmemorytype::CU_MEMORYTYPE_UNIFIED => Ok(hipMemoryType::hipMemoryTypeUnified),
- _ => Err(hipError_t::hipErrorInvalidValue),
- }
+pub(crate) fn get_address_range_v2(
+ pbase: *mut hipDeviceptr_t,
+ psize: *mut usize,
+ dptr: hipDeviceptr_t,
+) -> hipError_t {
+ unsafe { hipMemGetAddressRange(pbase, psize, dptr) }
}