From bc765534ed59e23036bf0e6fecea576e90a2dc29 Mon Sep 17 00:00:00 2001 From: Kjetil Date: Wed, 16 Feb 2022 15:03:57 +0100 Subject: [PATCH] feat: Add memcpy_dtoh in cust to allow users of cust to also copy memory from device to host --- crates/cust/CHANGELOG.md | 4 ++++ crates/cust/src/memory/mod.rs | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/crates/cust/CHANGELOG.md b/crates/cust/CHANGELOG.md index 540182a8..af5aa2b9 100644 --- a/crates/cust/CHANGELOG.md +++ b/crates/cust/CHANGELOG.md @@ -2,6 +2,10 @@ Notable changes to this project will be documented in this file. +## Unreleased + + - Add `memory::memcpy_dtoh` to allow copying from device to host. + ## 0.3.2 - 2/16/22 - Fixed `ModuleJitOptions` not working (due to cursed reasons). diff --git a/crates/cust/src/memory/mod.rs b/crates/cust/src/memory/mod.rs index 43fa2dd7..c0639e13 100644 --- a/crates/cust/src/memory/mod.rs +++ b/crates/cust/src/memory/mod.rs @@ -214,6 +214,17 @@ pub unsafe fn memcpy_htod( Ok(()) } +/// Simple wrapper over cuMemcpyDtoH_v2 +#[allow(clippy::missing_safety_doc)] +pub unsafe fn memcpy_dtoh( + d_ptr: *mut c_void, + src_ptr: cust_raw::CUdeviceptr, + size: usize, +) -> CudaResult<()> { + crate::sys::cuMemcpyDtoH_v2(d_ptr, src_ptr, size).to_result()?; + Ok(()) +} + /// Get the current free and total memory. /// /// Returns in `.1` the total amount of memory available to the the current context.