mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-01 12:33:12 +08:00
Revert "feature: add optional onChunkFree callback to AbstractBuffersPool"
This reverts commit b7ecf99abb.
Signed-off-by: Compute-Runtime-Validation <compute-runtime-validation@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
8ed2cb2bfe
commit
9c7950cd22
@@ -7,7 +7,6 @@
|
||||
|
||||
#pragma once
|
||||
#include "shared/source/helpers/constants.h"
|
||||
#include "shared/source/helpers/non_copyable_or_moveable.h"
|
||||
#include "shared/source/utilities/stackvec.h"
|
||||
|
||||
#include <functional>
|
||||
@@ -32,7 +31,7 @@ struct SmallBuffersParams {
|
||||
};
|
||||
|
||||
template <typename PoolT, typename BufferType, typename BufferParentType = BufferType>
|
||||
struct AbstractBuffersPool : public SmallBuffersParams<PoolT>, public NonCopyableClass {
|
||||
struct AbstractBuffersPool : public SmallBuffersParams<PoolT> {
|
||||
// The prototype of a function allocating the `mainStorage` is not specified.
|
||||
// That would be an unnecessary limitation here - it is completely up to derived class implementation.
|
||||
// Perhaps the allocating function needs to leverage `HeapAllocator::allocate()` and also
|
||||
@@ -44,9 +43,8 @@ struct AbstractBuffersPool : public SmallBuffersParams<PoolT>, public NonCopyabl
|
||||
using Params::smallBufferThreshold;
|
||||
using Params::startingOffset;
|
||||
using AllocsVecCRef = const StackVec<NEO::GraphicsAllocation *, 1> &;
|
||||
using OnChunkFreeCallback = void (PoolT::*)(uint64_t offset, size_t size);
|
||||
|
||||
AbstractBuffersPool(MemoryManager *memoryManager, OnChunkFreeCallback onChunkFreeCallback);
|
||||
AbstractBuffersPool(MemoryManager *memoryManager);
|
||||
AbstractBuffersPool(AbstractBuffersPool<PoolT, BufferType, BufferParentType> &&bufferPool);
|
||||
void tryFreeFromPoolBuffer(BufferParentType *possiblePoolBuffer, size_t offset, size_t size);
|
||||
bool isPoolBuffer(const BufferParentType *buffer) const;
|
||||
@@ -62,7 +60,6 @@ struct AbstractBuffersPool : public SmallBuffersParams<PoolT>, public NonCopyabl
|
||||
std::unique_ptr<BufferType> mainStorage;
|
||||
std::unique_ptr<HeapAllocator> chunkAllocator;
|
||||
std::vector<std::pair<uint64_t, size_t>> chunksToFree;
|
||||
OnChunkFreeCallback onChunkFreeCallback = nullptr;
|
||||
};
|
||||
|
||||
template <typename BuffersPoolType, typename BufferType, typename BufferParentType = BufferType>
|
||||
@@ -84,11 +81,8 @@ class AbstractBuffersAllocator : public SmallBuffersParams<BuffersPoolType> {
|
||||
|
||||
protected:
|
||||
inline bool isSizeWithinThreshold(size_t size) const { return smallBufferThreshold >= size; }
|
||||
void tryFreeFromPoolBuffer(BufferParentType *possiblePoolBuffer, size_t offset, size_t size, std::vector<BuffersPoolType> &bufferPoolsVec);
|
||||
void drain();
|
||||
void drain(std::vector<BuffersPoolType> &bufferPoolsVec);
|
||||
void addNewBufferPool(BuffersPoolType &&bufferPool);
|
||||
void addNewBufferPool(BuffersPoolType &&bufferPool, std::vector<BuffersPoolType> &bufferPoolsVec);
|
||||
|
||||
std::mutex mutex;
|
||||
std::vector<BuffersPoolType> bufferPools;
|
||||
|
||||
@@ -14,8 +14,7 @@
|
||||
namespace NEO {
|
||||
|
||||
template <typename PoolT, typename BufferType, typename BufferParentType>
|
||||
AbstractBuffersPool<PoolT, BufferType, BufferParentType>::AbstractBuffersPool(MemoryManager *memoryManager, OnChunkFreeCallback onChunkFreeCb)
|
||||
: memoryManager{memoryManager}, onChunkFreeCallback{onChunkFreeCb} {
|
||||
AbstractBuffersPool<PoolT, BufferType, BufferParentType>::AbstractBuffersPool(MemoryManager *mm) : memoryManager{mm} {
|
||||
static_assert(std::is_base_of_v<BufferParentType, BufferType>);
|
||||
}
|
||||
|
||||
@@ -23,13 +22,12 @@ template <typename PoolT, typename BufferType, typename BufferParentType>
|
||||
AbstractBuffersPool<PoolT, BufferType, BufferParentType>::AbstractBuffersPool(AbstractBuffersPool<PoolT, BufferType, BufferParentType> &&bufferPool)
|
||||
: memoryManager{bufferPool.memoryManager},
|
||||
mainStorage{std::move(bufferPool.mainStorage)},
|
||||
chunkAllocator{std::move(bufferPool.chunkAllocator)},
|
||||
onChunkFreeCallback{bufferPool.onChunkFreeCallback} {}
|
||||
chunkAllocator{std::move(bufferPool.chunkAllocator)} {}
|
||||
|
||||
template <typename PoolT, typename BufferType, typename BufferParentType>
|
||||
void AbstractBuffersPool<PoolT, BufferType, BufferParentType>::tryFreeFromPoolBuffer(BufferParentType *possiblePoolBuffer, size_t offset, size_t size) {
|
||||
if (this->isPoolBuffer(possiblePoolBuffer)) {
|
||||
this->chunksToFree.push_back({offset, size});
|
||||
this->chunksToFree.push_back({offset + startingOffset, size});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,9 +48,6 @@ void AbstractBuffersPool<PoolT, BufferType, BufferParentType>::drain() {
|
||||
}
|
||||
for (auto &chunk : this->chunksToFree) {
|
||||
this->chunkAllocator->free(chunk.first, chunk.second);
|
||||
if (static_cast<PoolT *>(this)->onChunkFreeCallback) {
|
||||
(static_cast<PoolT *>(this)->*onChunkFreeCallback)(chunk.first, chunk.second);
|
||||
}
|
||||
}
|
||||
this->chunksToFree.clear();
|
||||
}
|
||||
@@ -71,38 +66,23 @@ bool AbstractBuffersAllocator<BuffersPoolType, BufferType, BufferParentType>::is
|
||||
|
||||
template <typename BuffersPoolType, typename BufferType, typename BufferParentType>
|
||||
void AbstractBuffersAllocator<BuffersPoolType, BufferType, BufferParentType>::tryFreeFromPoolBuffer(BufferParentType *possiblePoolBuffer, size_t offset, size_t size) {
|
||||
this->tryFreeFromPoolBuffer(possiblePoolBuffer, offset, size, this->bufferPools);
|
||||
}
|
||||
|
||||
template <typename BuffersPoolType, typename BufferType, typename BufferParentType>
|
||||
void AbstractBuffersAllocator<BuffersPoolType, BufferType, BufferParentType>::tryFreeFromPoolBuffer(BufferParentType *possiblePoolBuffer, size_t offset, size_t size, std::vector<BuffersPoolType> &bufferPoolsVec) {
|
||||
auto lock = std::unique_lock<std::mutex>(this->mutex);
|
||||
for (auto &bufferPool : bufferPoolsVec) {
|
||||
for (auto &bufferPool : this->bufferPools) {
|
||||
bufferPool.tryFreeFromPoolBuffer(possiblePoolBuffer, offset, size); // NOLINT(clang-analyzer-cplusplus.NewDelete)
|
||||
}
|
||||
}
|
||||
|
||||
template <typename BuffersPoolType, typename BufferType, typename BufferParentType>
|
||||
void AbstractBuffersAllocator<BuffersPoolType, BufferType, BufferParentType>::drain() {
|
||||
this->drain(this->bufferPools);
|
||||
}
|
||||
|
||||
template <typename BuffersPoolType, typename BufferType, typename BufferParentType>
|
||||
void AbstractBuffersAllocator<BuffersPoolType, BufferType, BufferParentType>::drain(std::vector<BuffersPoolType> &bufferPoolsVec) {
|
||||
for (auto &bufferPool : bufferPoolsVec) {
|
||||
for (auto &bufferPool : this->bufferPools) {
|
||||
bufferPool.drain();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename BuffersPoolType, typename BufferType, typename BufferParentType>
|
||||
void AbstractBuffersAllocator<BuffersPoolType, BufferType, BufferParentType>::addNewBufferPool(BuffersPoolType &&bufferPool) {
|
||||
this->addNewBufferPool(std::move(bufferPool), this->bufferPools);
|
||||
}
|
||||
|
||||
template <typename BuffersPoolType, typename BufferType, typename BufferParentType>
|
||||
void AbstractBuffersAllocator<BuffersPoolType, BufferType, BufferParentType>::addNewBufferPool(BuffersPoolType &&bufferPool, std::vector<BuffersPoolType> &bufferPoolsVec) {
|
||||
if (bufferPool.mainStorage) {
|
||||
bufferPoolsVec.push_back(std::move(bufferPool));
|
||||
this->bufferPools.push_back(std::move(bufferPool));
|
||||
}
|
||||
}
|
||||
} // namespace NEO
|
||||
Reference in New Issue
Block a user