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,
87 typename = std::enable_if_t<cms::alpakatools::is_device_v<TDev> and cms::alpakatools::is_queue_v<TQueue>>>
90 #ifdef ALPAKA_ACC_GPU_CUDA_ENABLED 91 friend class alpaka_cuda_async::AlpakaService;
93 #ifdef ALPAKA_ACC_GPU_HIP_ENABLED 94 friend class alpaka_hip_async::AlpakaService;
96 #ifdef ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED 97 friend class alpaka_serial_sync::AlpakaService;
99 #ifdef ALPAKA_ACC_CPU_B_TBB_T_SEQ_ENABLED 100 friend class alpaka_tbb_async::AlpakaService;
106 using Buffer = alpaka::Buf<Device, std::byte, alpaka::DimInt<1u>,
size_t>;
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());
209 alpaka::enqueue(*(
block.queue), *(
block.event));
216 std::ostringstream
out;
218 << ptr <<
" from associated queue " <<
block.queue->m_spQueueImpl.get() <<
" , event " 219 <<
block.event->m_spEventImpl.get() <<
" .\n\t\t " <<
cachedBlocks_.size() <<
" available blocks cached (" 221 <<
" bytes) outstanding." << std::endl;
227 std::ostringstream
out;
229 << ptr <<
" from associated queue " <<
block.queue->m_spQueueImpl.get() <<
", event " 230 <<
block.event->m_spEventImpl.get() <<
" .\n\t\t " <<
cachedBlocks_.size() <<
" available blocks cached (" 232 <<
" bytes) outstanding." << std::endl;
255 size_t totalMemory = alpaka::getMemBytes(
device_);
261 if (memoryFraction > 0 and memoryFraction <
size) {
262 size = memoryFraction;
268 std::tuple<unsigned int, size_t>
findBin(
size_t bytes)
const {
273 throw std::runtime_error(
"Requested allocation size " +
std::to_string(bytes) +
274 " bytes is too large for the caching detail with maximum bin " +
276 " bytes. You might want to increase the maximum bin size");
280 while (binBytes < bytes) {
284 return std::make_tuple(
bin, binBytes);
292 for (
auto iBlock = begin; iBlock != end; ++iBlock) {
294 alpaka::isComplete(*(iBlock->second.event))) {
298 block = iBlock->second;
302 if (
block.device() != alpaka::getDev(*(
block.event))) {
316 std::ostringstream
out;
318 <<
block.buffer->data() <<
" (" <<
block.bytes <<
" bytes) for queue " 319 <<
block.queue->m_spQueueImpl.get() <<
", event " <<
block.event->m_spEventImpl.get()
320 <<
" (previously associated with queue " << iBlock->second.queue->m_spQueueImpl.get() <<
" , event " 321 << iBlock->second.event->m_spEventImpl.get() <<
")." << std::endl;
335 if constexpr (std::is_same_v<
Device, alpaka::Dev<Queue>>) {
337 return alpaka::allocBuf<std::byte, size_t>(
device_, bytes);
338 }
else if constexpr (std::is_same_v<Device, alpaka::DevCpu>) {
340 return alpaka::allocMappedBuf<alpaka::Pltf<alpaka::Dev<Queue>>, std::byte,
size_t>(
device_, bytes);
343 static_assert(std::is_same_v<
Device, alpaka::Dev<Queue>>
or std::is_same_v<Device, alpaka::DevCpu>,
344 "The \"memory device\" type can either be the same as the \"synchronisation device\" type, or be " 352 }
catch (std::runtime_error
const&
e) {
355 std::ostringstream
out;
357 <<
" bytes for queue " <<
block.queue->m_spQueueImpl.get()
358 <<
", retrying after freeing cached allocations" << std::endl;
380 std::ostringstream
out;
382 <<
block.buffer->data() <<
" (" <<
block.bytes <<
" bytes associated with queue " 383 <<
block.queue->m_spQueueImpl.get() <<
", event " <<
block.event->m_spEventImpl.get() <<
"." << std::endl;
396 std::ostringstream
out;
436 #endif // HeterogeneousCore_AlpakaInterface_interface_CachingAllocator_h
std::string to_string(const V &value)
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 &)