1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
/*
* Copyright (C) 2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "shared/source/helpers/constants.h"
#include "shared/source/helpers/non_copyable_or_moveable.h"
#include "shared/source/utilities/buffer_pool_allocator.h"
#include "shared/source/utilities/shared_pool_allocation.h"
#include "shared/source/utilities/stackvec.h"
#include <mutex>
namespace NEO {
class GraphicsAllocation;
class Device;
using SharedTimestampAllocation = SharedPoolAllocation;
class TimestampPool : public AbstractBuffersPool<TimestampPool, GraphicsAllocation> {
using BaseType = AbstractBuffersPool<TimestampPool, GraphicsAllocation>;
public:
TimestampPool(Device *device, size_t poolSize);
TimestampPool(const TimestampPool &) = delete;
TimestampPool &operator=(const TimestampPool &) = delete;
TimestampPool(TimestampPool &&pool) noexcept;
TimestampPool &operator=(TimestampPool &&) = delete;
~TimestampPool() override;
SharedTimestampAllocation *allocate(size_t size);
const StackVec<GraphicsAllocation *, 1> &getAllocationsVector();
private:
Device *device;
StackVec<GraphicsAllocation *, 1> stackVec;
std::unique_ptr<std::mutex> mtx;
};
class TimestampPoolAllocator : public AbstractBuffersAllocator<TimestampPool, GraphicsAllocation> {
public:
TimestampPoolAllocator(Device *device);
bool isEnabled() const;
SharedTimestampAllocation *requestGraphicsAllocationForTimestamp(size_t size);
void freeSharedTimestampAllocation(SharedTimestampAllocation *sharedTimestampAllocation);
size_t getDefaultPoolSize() const { return defaultPoolSize; }
private:
SharedTimestampAllocation *allocateFromPools(size_t size);
size_t alignToPoolSize(size_t size) const;
const size_t maxAllocationSize = 2 * MemoryConstants::megaByte;
const size_t defaultPoolSize = 4 * MemoryConstants::megaByte;
const size_t poolAlignment = MemoryConstants::pageSize2M;
Device *device;
std::mutex allocatorMtx;
};
static_assert(NEO::NonCopyable<TimestampPool>);
} // namespace NEO
|