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
|
/*
* Copyright (C) 2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "shared/source/utilities/buffer_pool_allocator.h"
#include "shared/source/utilities/pool_allocator_traits.h"
#include "shared/source/utilities/shared_pool_allocation.h"
#include "shared/source/utilities/stackvec.h"
#include <memory>
#include <mutex>
namespace NEO {
class Device;
class GraphicsAllocation;
template <PoolTraits Traits>
class GenericPool : public AbstractBuffersPool<GenericPool<Traits>, GraphicsAllocation> {
using BaseType = AbstractBuffersPool<GenericPool<Traits>, GraphicsAllocation>;
public:
GenericPool(Device *device, size_t poolSize);
GenericPool(const GenericPool &) = delete;
GenericPool &operator=(const GenericPool &) = delete;
GenericPool(GenericPool &&pool) noexcept;
GenericPool &operator=(GenericPool &&) = delete;
~GenericPool() override;
SharedPoolAllocation *allocate(size_t size);
const StackVec<GraphicsAllocation *, 1> &getAllocationsVector();
private:
Device *device;
StackVec<GraphicsAllocation *, 1> stackVec;
std::unique_ptr<std::mutex> mtx;
};
template <PoolTraits Traits>
class GenericPoolAllocator : public AbstractBuffersAllocator<GenericPool<Traits>, GraphicsAllocation> {
public:
explicit GenericPoolAllocator(Device *device);
SharedPoolAllocation *requestGraphicsAllocation(size_t size);
void freeSharedAllocation(SharedPoolAllocation *sharedPoolAllocation);
size_t getDefaultPoolSize() const { return Traits::defaultPoolSize; }
private:
SharedPoolAllocation *allocateFromPools(size_t size);
size_t alignToPoolSize(size_t size) const;
Device *device;
std::mutex allocatorMtx;
};
} // namespace NEO
|