1 #ifndef HeterogeneousCore_AlpakaInterface_interface_CachingAllocator_h 2 #define HeterogeneousCore_AlpakaInterface_interface_CachingAllocator_h 14 #include <type_traits> 16 #include <alpaka/alpaka.hpp> 28 unsigned int power = 1;
43 }
else if (
value >= (1 << 30) and
value % (1 << 30) == 0) {
45 }
else if (
value >= (1 << 20) and
value % (1 << 20) == 0) {
47 }
else if (
value >= (1 << 10) and
value % (1 << 10) == 0) {
85 template <
typename TDev,
typename TQueue>
88 #ifdef ALPAKA_ACC_GPU_CUDA_ENABLED 89 friend class alpaka_cuda_async::AlpakaService;
91 #ifdef ALPAKA_ACC_GPU_HIP_ENABLED 92 friend class alpaka_rocm_async::AlpakaService;
94 #ifdef ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED 95 friend class alpaka_serial_sync::AlpakaService;
97 #ifdef ALPAKA_ACC_CPU_B_TBB_T_SEQ_ENABLED 98 friend class alpaka_tbb_async::AlpakaService;
104 using Buffer = alpaka::Buf<Device, std::byte, alpaka::DimInt<1u>,
size_t>;
107 static_assert(alpaka::isDevice<Device>,
"TDev should be an alpaka Device type.");
108 static_assert(alpaka::isQueue<Queue>,
"TQueue should be an alpaka Queue type.");
109 static_assert(std::is_same_v<
Device, alpaka::Dev<Queue>>
or std::is_same_v<Device, alpaka::DevCpu>,
110 "The \"memory device\" type can either be the same as the \"synchronisation device\" type, or be the " 130 bool reuseSameQueueAllocations,
143 std::ostringstream
out;
144 out <<
"CachingAllocator settings\n" 146 <<
" min bin " <<
minBin_ <<
"\n" 147 <<
" max bin " <<
maxBin_ <<
"\n" 148 <<
" resulting bins:\n";
180 block.requested = bytes;
188 return block.buffer->data();
197 std::stringstream
ss;
198 ss <<
"Trying to free a non-live block at " << ptr;
199 throw std::runtime_error(
ss.str());
217 alpaka::enqueue(*(
block.queue), *(
block.event));
220 std::ostringstream
out;
221 out <<
"CachingAllocator::free() error from alpaka::enqueue(): " <<
e.what() <<
"\n";
223 << ptr <<
" from associated queue " <<
block.queue->m_spQueueImpl.get() <<
", event " 226 <<
" live blocks (" <<
cachedBytes_.
live <<
" bytes) outstanding." << std::endl;
237 std::ostringstream
out;
239 << ptr <<
" from associated queue " <<
block.queue->m_spQueueImpl.get() <<
" , event " 240 <<
block.event->m_spEventImpl.get() <<
" .\n\t\t " <<
cachedBlocks_.size() <<
" available blocks cached (" 242 <<
" bytes) outstanding." << std::endl;
248 std::ostringstream
out;
250 << ptr <<
" from associated queue " <<
block.queue->m_spQueueImpl.get() <<
", event " 251 <<
block.event->m_spEventImpl.get() <<
" .\n\t\t " <<
cachedBlocks_.size() <<
" available blocks cached (" 253 <<
" bytes) outstanding." << std::endl;
276 size_t totalMemory = alpaka::getMemBytes(
device_);
282 if (memoryFraction > 0 and memoryFraction <
size) {
283 size = memoryFraction;
289 std::tuple<unsigned int, size_t>
findBin(
size_t bytes)
const {
294 throw std::runtime_error(
"Requested allocation size " +
std::to_string(bytes) +
295 " bytes is too large for the caching detail with maximum bin " +
297 " bytes. You might want to increase the maximum bin size");
301 while (binBytes < bytes) {
305 return std::make_tuple(
bin, binBytes);
313 for (
auto iBlock = begin; iBlock != end; ++iBlock) {
315 alpaka::isComplete(*(iBlock->second.event))) {
319 block = iBlock->second;
323 if (
block.device() != alpaka::getDev(*(
block.event))) {
337 std::ostringstream
out;
339 <<
block.buffer->data() <<
" (" <<
block.bytes <<
" bytes) for queue " 340 <<
block.queue->m_spQueueImpl.get() <<
", event " <<
block.event->m_spEventImpl.get()
341 <<
" (previously associated with queue " << iBlock->second.queue->m_spQueueImpl.get() <<
" , event " 342 << iBlock->second.event->m_spEventImpl.get() <<
")." << std::endl;
358 return alpaka::allocBuf<std::byte, size_t>(
device_, bytes);
359 }
else if constexpr (std::is_same_v<Device, alpaka::DevCpu>) {
361 using Platform = alpaka::Platform<alpaka::Dev<Queue>>;
362 return alpaka::allocMappedBuf<Platform, std::byte, size_t>(
device_, platform<Platform>(), bytes);
365 static_assert(std::is_same_v<
Device, alpaka::Dev<Queue>>
or std::is_same_v<Device, alpaka::DevCpu>,
366 "The \"memory device\" type can either be the same as the \"synchronisation device\" type, or be " 374 }
catch (std::runtime_error
const&
e) {
377 std::ostringstream
out;
379 <<
" bytes for queue " <<
block.queue->m_spQueueImpl.get()
380 <<
", retrying after freeing cached allocations" << std::endl;
402 std::ostringstream
out;
404 <<
block.buffer->data() <<
" (" <<
block.bytes <<
" bytes associated with queue " 405 <<
block.queue->m_spQueueImpl.get() <<
", event " <<
block.event->m_spEventImpl.get() <<
"." << std::endl;
418 std::ostringstream
out;
458 #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 &)