1#ifndef AMREX_GPU_ASYNC_ARRAY_H_
2#define AMREX_GPU_ASYNC_ARRAY_H_
3#include <AMReX_Config.H>
14#if defined(AMREX_USE_CUDA) || defined(AMREX_USE_HIP)
16#if defined(AMREX_USE_HIP)
18#elif defined(AMREX_USE_CUDA)
33requires (std::is_trivially_copyable_v<T>)
40 if (n == 0) {
return; }
42 std::memcpy(h_data, h_p, n*
sizeof(T));
53 requires (std::is_standard_layout_v<T> && std::is_trivial_v<T>)
56 if (n == 0) {
return; }
76 [[nodiscard]] T
const*
data () const noexcept {
return (d_data !=
nullptr) ? d_data : h_data; }
77 [[nodiscard]] T*
data () noexcept {
return (d_data !=
nullptr) ? d_data : h_data; }
83 if (d_data !=
nullptr) {
84#if defined(AMREX_USE_CUDA) || defined(AMREX_USE_HIP)
85 T** p =
static_cast<T**
>(std::malloc(2*
sizeof(T*)));
88#if defined(AMREX_USE_HIP)
91#elif defined(AMREX_USE_CUDA)
95#elif defined(AMREX_USE_SYCL)
100 q.submit([&] (sycl::handler& h) {
106 }
catch (sycl::exception
const& ex) {
107 amrex::Abort(std::string(
"host_task: ")+ex.what()+
"!!!!!");
123 if (n == 0) {
return; }
133 std::memcpy(h_p, h_data, n*
sizeof(T));
144using Gpu::AsyncArray;
void CUDART_CB amrex_asyncarray_delete(void *p)
Definition AMReX_GpuAsyncArray.cpp:10
void CUDART_CB amrex_asyncarray_delete(void *p)
Definition AMReX_GpuAsyncArray.cpp:10
#define AMREX_CUDA_SAFE_CALL(call)
Definition AMReX_GpuError.H:73
virtual void free(void *pt)=0
A pure virtual function for deleting the arena pointed to by pt.
virtual void * alloc(std::size_t sz)=0
Definition AMReX_GpuAsyncArray.H:35
void copyToHost(T *h_p, std::size_t n) const
Definition AMReX_GpuAsyncArray.H:121
AsyncArray(AsyncArray const &)=delete
AsyncArray(AsyncArray &&)=delete
void clear()
Definition AMReX_GpuAsyncArray.H:78
T * data() noexcept
Definition AMReX_GpuAsyncArray.H:77
~AsyncArray()
Definition AMReX_GpuAsyncArray.H:69
T const * data() const noexcept
Definition AMReX_GpuAsyncArray.H:76
AsyncArray(T const *h_p, const std::size_t n)
Definition AMReX_GpuAsyncArray.H:38
AsyncArray(const std::size_t n)
Definition AMReX_GpuAsyncArray.H:52
Arena * The_Pinned_Arena()
Definition AMReX_Arena.cpp:860
Arena * The_Arena()
Definition AMReX_Arena.cpp:820
bool inLaunchRegion() noexcept
Definition AMReX_GpuControl.H:88
void dtoh_memcpy(void *p_h, const void *p_d, const std::size_t sz) noexcept
Definition AMReX_GpuDevice.H:496
void htod_memcpy_async(void *p_d, const void *p_h, const std::size_t sz) noexcept
Definition AMReX_GpuDevice.H:421
gpuStream_t gpuStream() noexcept
Definition AMReX_GpuDevice.H:291
Definition AMReX_Amr.cpp:50
void Abort(const std::string &msg)
Print out message to cerr and exit via abort().
Definition AMReX.cpp:241