1 #ifndef HeterogeneousCore_AlpakaInterface_interface_CachingAllocator_h 2 #define HeterogeneousCore_AlpakaInterface_interface_CachingAllocator_h 14 #include <type_traits> 16 #include <alpaka/alpaka.hpp> 29 unsigned int power = 1;
44 }
else if (
value >= (1 << 30) and
value % (1 << 30) == 0) {
46 }
else if (
value >= (1 << 20) and
value % (1 << 20) == 0) {
48 }
else if (
value >= (1 << 10) and
value % (1 << 10) == 0) {
86 template <
typename TDev,
typename TQueue>
89 #ifdef ALPAKA_ACC_GPU_CUDA_ENABLED 90 friend class alpaka_cuda_async::AlpakaService;
92 #ifdef ALPAKA_ACC_GPU_HIP_ENABLED 93 friend class alpaka_rocm_async::AlpakaService;
95 #ifdef ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED 96 friend class alpaka_serial_sync::AlpakaService;
98 #ifdef ALPAKA_ACC_CPU_B_TBB_T_SEQ_ENABLED 99 friend class alpaka_tbb_async::AlpakaService;
105 using Buffer = alpaka::Buf<Device, std::byte, alpaka::DimInt<1u>,
size_t>;
108 static_assert(alpaka::isDevice<Device>,
"TDev should be an alpaka Device type.");
109 static_assert(alpaka::isQueue<Queue>,
"TQueue should be an alpaka Queue type.");
110 static_assert(std::is_same_v<
Device, alpaka::Dev<Queue>>
or std::is_same_v<Device, alpaka::DevCpu>,
111 "The \"memory device\" type can either be the same as the \"synchronisation device\" type, or be the " 131 bool reuseSameQueueAllocations,
144 std::ostringstream
out;
145 out <<
"CachingAllocator settings\n" 147 <<
" min bin " <<
minBin_ <<
"\n" 148 <<
" max bin " <<
maxBin_ <<
"\n" 149 <<
" resulting bins:\n";
181 block.requested = bytes;
189 return block.buffer->data();
198 std::stringstream
ss;
199 ss <<
"Trying to free a non-live block at " << ptr;
200 throw std::runtime_error(
ss.str());
210 alpaka::enqueue(*(
block.queue), *(
block.event));
217 std::ostringstream
out;
219 << ptr <<
" from associated queue " <<
block.queue->m_spQueueImpl.get() <<
" , event " 220 <<
block.event->m_spEventImpl.get() <<
" .\n\t\t " <<
cachedBlocks_.size() <<
" available blocks cached (" 222 <<
" bytes) outstanding." << std::endl;
228 std::ostringstream
out;
230 << ptr <<
" from associated queue " <<
block.queue->m_spQueueImpl.get() <<
", event " 231 <<
block.event->m_spEventImpl.get() <<
" .\n\t\t " <<
cachedBlocks_.size() <<
" available blocks cached (" 233 <<
" bytes) outstanding." << std::endl;
256 size_t totalMemory = alpaka::getMemBytes(
device_);
262 if (memoryFraction > 0 and memoryFraction <
size) {
263 size = memoryFraction;
269 std::tuple<unsigned int, size_t>
findBin(
size_t bytes)
const {
274 throw std::runtime_error(
"Requested allocation size " +
std::to_string(bytes) +
275 " bytes is too large for the caching detail with maximum bin " +
277 " bytes. You might want to increase the maximum bin size");
281 while (binBytes < bytes) {
285 return std::make_tuple(
bin, binBytes);
293 for (
auto iBlock = begin; iBlock != end; ++iBlock) {
295 alpaka::isComplete(*(iBlock->second.event))) {
299 block = iBlock->second;
303 if (
block.device() != alpaka::getDev(*(
block.event))) {
317 std::ostringstream
out;
319 <<
block.buffer->data() <<
" (" <<
block.bytes <<
" bytes) for queue " 320 <<
block.queue->m_spQueueImpl.get() <<
", event " <<
block.event->m_spEventImpl.get()
321 <<
" (previously associated with queue " << iBlock->second.queue->m_spQueueImpl.get() <<
" , event " 322 << iBlock->second.event->m_spEventImpl.get() <<
")." << std::endl;
338 return alpaka::allocBuf<std::byte, size_t>(
device_, bytes);
339 }
else if constexpr (std::is_same_v<Device, alpaka::DevCpu>) {
341 using Platform = alpaka::Platform<alpaka::Dev<Queue>>;
342 return alpaka::allocMappedBuf<Platform, std::byte, size_t>(
device_, platform<Platform>(), bytes);
345 static_assert(std::is_same_v<
Device, alpaka::Dev<Queue>>
or std::is_same_v<Device, alpaka::DevCpu>,
346 "The \"memory device\" type can either be the same as the \"synchronisation device\" type, or be " 354 }
catch (std::runtime_error
const&
e) {
357 std::ostringstream
out;
359 <<
" bytes for queue " <<
block.queue->m_spQueueImpl.get()
360 <<
", retrying after freeing cached allocations" << std::endl;
382 std::ostringstream
out;
384 <<
block.buffer->data() <<
" (" <<
block.bytes <<
" bytes associated with queue " 385 <<
block.queue->m_spQueueImpl.get() <<
", event " <<
block.event->m_spEventImpl.get() <<
"." << std::endl;
398 std::ostringstream
out;
438 #endif // HeterogeneousCore_AlpakaInterface_interface_CachingAllocator_h
static std::string to_string(const XMLCh *ch)
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
std::string getName(const G4String &)