mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00
refactor HwTS and HWPerf tag allocators
- use full type specification and remove casts in MemoryManager - remove TagAllocatorBase not used any more - make TagAllocator to be profiling/instrumentation agnostic - unify UnlimitedTagCount and make part of TagAllocator Change-Id: I7b5b1ed83aa5e1f0839f611db0530d7e062a3c25 Signed-off-by: Artur Harasimiuk <artur.harasimiuk@intel.com>
This commit is contained in:

committed by
sys_ocldev

parent
09401632b7
commit
ef5bd7ec5b
@ -37,6 +37,8 @@
|
||||
#include <algorithm>
|
||||
|
||||
namespace OCLRT {
|
||||
constexpr size_t ProfilingTagCount = 512;
|
||||
constexpr size_t PerfCounterTagCount = 512;
|
||||
|
||||
struct ReusableAllocationRequirements {
|
||||
size_t requiredMinimalSize;
|
||||
@ -265,16 +267,16 @@ void MemoryManager::freeAllocationsList(uint32_t waitTaskCount, AllocationsList
|
||||
|
||||
TagAllocator<HwTimeStamps> *MemoryManager::getEventTsAllocator() {
|
||||
if (profilingTimeStampAllocator.get() == nullptr) {
|
||||
profilingTimeStampAllocator = std::unique_ptr<TagAllocatorBase>(new TagAllocator<HwTimeStamps>(this, ProfilingTagCount, 64, UnlimitedProfilingCount));
|
||||
profilingTimeStampAllocator.reset(new TagAllocator<HwTimeStamps>(this, ProfilingTagCount, MemoryConstants::cacheLineSize));
|
||||
}
|
||||
return reinterpret_cast<TagAllocator<HwTimeStamps> *>(profilingTimeStampAllocator.get());
|
||||
return profilingTimeStampAllocator.get();
|
||||
}
|
||||
|
||||
TagAllocator<HwPerfCounter> *MemoryManager::getEventPerfCountAllocator() {
|
||||
if (perfCounterAllocator.get() == nullptr) {
|
||||
perfCounterAllocator = std::unique_ptr<TagAllocatorBase>(new TagAllocator<HwPerfCounter>(this, PerfCounterTagCount, 64, UnlimitedPerfCounterCount));
|
||||
perfCounterAllocator.reset(new TagAllocator<HwPerfCounter>(this, PerfCounterTagCount, MemoryConstants::cacheLineSize));
|
||||
}
|
||||
return reinterpret_cast<TagAllocator<HwPerfCounter> *>(perfCounterAllocator.get());
|
||||
return perfCounterAllocator.get();
|
||||
}
|
||||
|
||||
void MemoryManager::pushAllocationForResidency(GraphicsAllocation *gfxAllocation) {
|
||||
|
@ -26,7 +26,6 @@
|
||||
#include "runtime/memory_manager/graphics_allocation.h"
|
||||
#include "runtime/os_interface/32bit_memory.h"
|
||||
#include "runtime/helpers/aligned_memory.h"
|
||||
#include "runtime/utilities/tag_allocator_base.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
@ -240,8 +239,8 @@ class MemoryManager {
|
||||
|
||||
protected:
|
||||
std::recursive_mutex mtx;
|
||||
std::unique_ptr<TagAllocatorBase> profilingTimeStampAllocator;
|
||||
std::unique_ptr<TagAllocatorBase> perfCounterAllocator;
|
||||
std::unique_ptr<TagAllocator<HwTimeStamps>> profilingTimeStampAllocator;
|
||||
std::unique_ptr<TagAllocator<HwPerfCounter>> perfCounterAllocator;
|
||||
bool force32bitAllocations = false;
|
||||
bool virtualPaddingAvailable = false;
|
||||
GraphicsAllocation *paddingAllocation = nullptr;
|
||||
|
@ -40,7 +40,6 @@ set(RUNTIME_SRCS_UTILITIES_BASE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/spinlock.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/stackvec.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tag_allocator.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tag_allocator_base.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/timer_util.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/vec.h
|
||||
)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Intel Corporation
|
||||
* Copyright (c) 2017 - 2018, Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
@ -25,7 +25,6 @@
|
||||
#include "runtime/helpers/debug_helpers.h"
|
||||
#include "runtime/memory_manager/memory_manager.h"
|
||||
#include "runtime/utilities/idlist.h"
|
||||
#include "runtime/utilities/tag_allocator_base.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <mutex>
|
||||
@ -51,29 +50,21 @@ struct TagNode : public IDNode<TagNode<TagType>> {
|
||||
};
|
||||
|
||||
template <typename TagType>
|
||||
class TagAllocator : public TagAllocatorBase {
|
||||
class TagAllocator {
|
||||
public:
|
||||
using NodeType = TagNode<TagType>;
|
||||
|
||||
TagAllocator(MemoryManager *memMngr, size_t tagCount, size_t tagAlignment, size_t maxTagPoolCount) : memoryManager(memMngr),
|
||||
maxTagPoolCount(maxTagPoolCount),
|
||||
tagCount(tagCount),
|
||||
tagAlignment(tagAlignment) {
|
||||
if (maxTagPoolCount) {
|
||||
gfxAllocations.reserve(maxTagPoolCount);
|
||||
tagPoolMemory.reserve(maxTagPoolCount);
|
||||
} else {
|
||||
gfxAllocations.reserve(PrefferedProfilingTagPoolCount);
|
||||
tagPoolMemory.reserve(PrefferedProfilingTagPoolCount);
|
||||
}
|
||||
TagAllocator(MemoryManager *memMngr, size_t tagCount, size_t tagAlignment) : memoryManager(memMngr),
|
||||
tagCount(tagCount),
|
||||
tagAlignment(tagAlignment) {
|
||||
populateFreeTags();
|
||||
}
|
||||
|
||||
~TagAllocator() override {
|
||||
MOCKABLE_VIRTUAL ~TagAllocator() {
|
||||
cleanUpResources();
|
||||
}
|
||||
|
||||
void cleanUpResources() override {
|
||||
void cleanUpResources() {
|
||||
size_t size = gfxAllocations.size();
|
||||
|
||||
for (uint32_t i = 0; i < size; ++i) {
|
||||
@ -94,8 +85,7 @@ class TagAllocator : public TagAllocatorBase {
|
||||
populateFreeTags();
|
||||
node = freeTags.removeFrontOne().release();
|
||||
}
|
||||
if (node)
|
||||
usedTags.pushFrontOne(*node);
|
||||
usedTags.pushFrontOne(*node);
|
||||
return node;
|
||||
}
|
||||
|
||||
@ -105,8 +95,6 @@ class TagAllocator : public TagAllocatorBase {
|
||||
((void)(usedNode));
|
||||
freeTags.pushFrontOne(*node);
|
||||
}
|
||||
size_t peekMaxTagPoolCount() { return maxTagPoolCount; }
|
||||
|
||||
protected:
|
||||
IDList<NodeType> freeTags;
|
||||
IDList<NodeType> usedTags;
|
||||
@ -114,7 +102,6 @@ class TagAllocator : public TagAllocatorBase {
|
||||
std::vector<NodeType *> tagPoolMemory;
|
||||
|
||||
MemoryManager *memoryManager;
|
||||
const size_t maxTagPoolCount;
|
||||
size_t tagCount;
|
||||
size_t tagAlignment;
|
||||
|
||||
@ -128,28 +115,25 @@ class TagAllocator : public TagAllocatorBase {
|
||||
|
||||
std::unique_lock<std::mutex> lock(allocationsMutex);
|
||||
|
||||
size_t tagPoolCount = gfxAllocations.size();
|
||||
if (tagPoolCount < maxTagPoolCount || maxTagPoolCount == 0) {
|
||||
GraphicsAllocation *graphicsAllocation = memoryManager->allocateGraphicsMemory(allocationSizeRequired);
|
||||
gfxAllocations.push_back(graphicsAllocation);
|
||||
GraphicsAllocation *graphicsAllocation = memoryManager->allocateGraphicsMemory(allocationSizeRequired);
|
||||
gfxAllocations.push_back(graphicsAllocation);
|
||||
|
||||
uintptr_t Size = graphicsAllocation->getUnderlyingBufferSize();
|
||||
uintptr_t Start = reinterpret_cast<uintptr_t>(graphicsAllocation->getUnderlyingBuffer());
|
||||
uintptr_t End = Start + Size;
|
||||
size_t nodeCount = Size / tagSize;
|
||||
uintptr_t Size = graphicsAllocation->getUnderlyingBufferSize();
|
||||
uintptr_t Start = reinterpret_cast<uintptr_t>(graphicsAllocation->getUnderlyingBuffer());
|
||||
uintptr_t End = Start + Size;
|
||||
size_t nodeCount = Size / tagSize;
|
||||
|
||||
NodeType *nodesMemory = new NodeType[nodeCount];
|
||||
NodeType *nodesMemory = new NodeType[nodeCount];
|
||||
|
||||
for (size_t i = 0; i < nodeCount; ++i) {
|
||||
nodesMemory[i].gfxAllocation = graphicsAllocation;
|
||||
nodesMemory[i].tag = reinterpret_cast<TagType *>(Start);
|
||||
freeTags.pushTailOne(nodesMemory[i]);
|
||||
Start += tagSize;
|
||||
}
|
||||
DEBUG_BREAK_IF(Start > End);
|
||||
((void)(End));
|
||||
tagPoolMemory.push_back(nodesMemory);
|
||||
for (size_t i = 0; i < nodeCount; ++i) {
|
||||
nodesMemory[i].gfxAllocation = graphicsAllocation;
|
||||
nodesMemory[i].tag = reinterpret_cast<TagType *>(Start);
|
||||
freeTags.pushTailOne(nodesMemory[i]);
|
||||
Start += tagSize;
|
||||
}
|
||||
DEBUG_BREAK_IF(Start > End);
|
||||
((void)(End));
|
||||
tagPoolMemory.push_back(nodesMemory);
|
||||
}
|
||||
};
|
||||
} // namespace OCLRT
|
||||
|
@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace OCLRT {
|
||||
constexpr size_t UnlimitedProfilingCount = 0;
|
||||
constexpr size_t ProfilingTagCount = 512;
|
||||
constexpr size_t PrefferedProfilingTagPoolCount = 10;
|
||||
|
||||
constexpr size_t UnlimitedPerfCounterCount = 0;
|
||||
constexpr size_t PerfCounterTagCount = 512;
|
||||
|
||||
class TagAllocatorBase {
|
||||
public:
|
||||
virtual ~TagAllocatorBase(){};
|
||||
virtual void cleanUpResources() = 0;
|
||||
|
||||
protected:
|
||||
TagAllocatorBase() = default;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user