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());
218 alpaka::enqueue(*(
block.queue), *(
block.event));
221 std::ostringstream
out;
222 out <<
"CachingAllocator::free() error from alpaka::enqueue(): " <<
e.what() <<
"\n";
224 << ptr <<
" from associated queue " <<
block.queue->m_spQueueImpl.get() <<
", event " 227 <<
" live blocks (" <<
cachedBytes_.
live <<
" bytes) outstanding." << std::endl;
238 std::ostringstream
out;
240 << ptr <<
" from associated queue " <<
block.queue->m_spQueueImpl.get() <<
" , event " 241 <<
block.event->m_spEventImpl.get() <<
" .\n\t\t " <<
cachedBlocks_.size() <<
" available blocks cached (" 243 <<
" bytes) outstanding." << std::endl;
249 std::ostringstream
out;
251 << ptr <<
" from associated queue " <<
block.queue->m_spQueueImpl.get() <<
", event " 252 <<
block.event->m_spEventImpl.get() <<
" .\n\t\t " <<
cachedBlocks_.size() <<
" available blocks cached (" 254 <<
" bytes) outstanding." << std::endl;
277 size_t totalMemory = alpaka::getMemBytes(
device_);
283 if (memoryFraction > 0 and memoryFraction <
size) {
284 size = memoryFraction;
290 std::tuple<unsigned int, size_t>
findBin(
size_t bytes)
const {
295 throw std::runtime_error(
"Requested allocation size " +
std::to_string(bytes) +
296 " bytes is too large for the caching detail with maximum bin " +
298 " bytes. You might want to increase the maximum bin size");
302 while (binBytes < bytes) {
306 return std::make_tuple(
bin, binBytes);
314 for (
auto iBlock = begin; iBlock != end; ++iBlock) {
316 alpaka::isComplete(*(iBlock->second.event))) {
320 block = iBlock->second;
324 if (
block.device() != alpaka::getDev(*(
block.event))) {
338 std::ostringstream
out;
340 <<
block.buffer->data() <<
" (" <<
block.bytes <<
" bytes) for queue " 341 <<
block.queue->m_spQueueImpl.get() <<
", event " <<
block.event->m_spEventImpl.get()
342 <<
" (previously associated with queue " << iBlock->second.queue->m_spQueueImpl.get() <<
" , event " 343 << iBlock->second.event->m_spEventImpl.get() <<
")." << std::endl;
359 return alpaka::allocBuf<std::byte, size_t>(
device_, bytes);
360 }
else if constexpr (std::is_same_v<Device, alpaka::DevCpu>) {
362 using Platform = alpaka::Platform<alpaka::Dev<Queue>>;
363 return alpaka::allocMappedBuf<Platform, std::byte, size_t>(
device_, platform<Platform>(), bytes);
366 static_assert(std::is_same_v<
Device, alpaka::Dev<Queue>>
or std::is_same_v<Device, alpaka::DevCpu>,
367 "The \"memory device\" type can either be the same as the \"synchronisation device\" type, or be " 375 }
catch (std::runtime_error
const&
e) {
378 std::ostringstream
out;
380 <<
" bytes for queue " <<
block.queue->m_spQueueImpl.get()
381 <<
", retrying after freeing cached allocations" << std::endl;
403 std::ostringstream
out;
405 <<
block.buffer->data() <<
" (" <<
block.bytes <<
" bytes associated with queue " 406 <<
block.queue->m_spQueueImpl.get() <<
", event " <<
block.event->m_spEventImpl.get() <<
"." << std::endl;
419 std::ostringstream
out;
459 #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 &)