File indexing completed on 2026-10-26 09:34:38
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include "corecel/Macros.hh"
0010
0011 #if CELER_USE_DEVICE
0012 # include <thrust/mr/memory_resource.h>
0013 #endif
0014 #include <cstdlib>
0015
0016 #include "corecel/DeviceRuntimeApi.hh"
0017
0018 namespace celeritas
0019 {
0020 namespace detail
0021 {
0022
0023
0024 #if CELER_USE_DEVICE
0025 using DeviceStream_t = CELER_DEVICE_API_SYMBOL(Stream_t);
0026 #else
0027 using DeviceStream_t = std::nullptr_t;
0028 #endif
0029
0030
0031 void* malloc_async(std::size_t bytes, DeviceStream_t s);
0032
0033 void free_async(void* ptr, DeviceStream_t s);
0034
0035 #if CELER_USE_DEVICE || defined(__DOXYGEN__)
0036
0037
0038
0039
0040 class AsyncMemoryResource final : public thrust::mr::memory_resource<void*>
0041 {
0042 public:
0043
0044
0045 using pointer = void*;
0046 using StreamT = DeviceStream_t;
0047
0048
0049
0050 explicit AsyncMemoryResource(StreamT stream) : stream_{stream} {}
0051
0052
0053 AsyncMemoryResource() = default;
0054
0055
0056 pointer do_allocate(std::size_t bytes, std::size_t) final;
0057
0058
0059 void do_deallocate(pointer p, std::size_t, std::size_t) final;
0060
0061 private:
0062 StreamT stream_{nullptr};
0063 };
0064 #else
0065 class AsyncMemoryResource;
0066 inline void* malloc_async(std::size_t, DeviceStream_t)
0067 {
0068 CELER_ASSERT_UNREACHABLE();
0069 }
0070 inline void free_async(void*, DeviceStream_t)
0071 {
0072 CELER_ASSERT_UNREACHABLE();
0073 }
0074
0075 #endif
0076
0077
0078 }
0079 }