mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-10 12:53:42 +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;
|
||||
};
|
||||
}
|
@ -567,12 +567,6 @@ TEST_F(MemoryAllocatorTest, getEventTsAllocator) {
|
||||
EXPECT_EQ(allocator2, allocator);
|
||||
}
|
||||
|
||||
TEST_F(MemoryAllocatorTest, givenMemoryManagerWhenTagEventTsAllocatorIsCreatedItHasUnlimitedTagCount) {
|
||||
TagAllocator<HwTimeStamps> *allocator = memoryManager->getEventTsAllocator();
|
||||
EXPECT_NE(nullptr, allocator);
|
||||
EXPECT_EQ(UnlimitedProfilingCount, allocator->peekMaxTagPoolCount());
|
||||
}
|
||||
|
||||
TEST_F(MemoryAllocatorTest, getEventPerfCountAllocator) {
|
||||
TagAllocator<HwPerfCounter> *allocator = memoryManager->getEventPerfCountAllocator();
|
||||
EXPECT_NE(nullptr, allocator);
|
||||
@ -580,12 +574,6 @@ TEST_F(MemoryAllocatorTest, getEventPerfCountAllocator) {
|
||||
EXPECT_EQ(allocator2, allocator);
|
||||
}
|
||||
|
||||
TEST_F(MemoryAllocatorTest, givenMemoryManagerWhenTagPerfCountAllocatorIsCreatedItHasUnlimitedTagCount) {
|
||||
TagAllocator<HwPerfCounter> *allocator = memoryManager->getEventPerfCountAllocator();
|
||||
EXPECT_NE(nullptr, allocator);
|
||||
EXPECT_EQ(UnlimitedPerfCounterCount, allocator->peekMaxTagPoolCount());
|
||||
}
|
||||
|
||||
TEST_F(MemoryAllocatorTest, givenMemoryManagerWhensetForce32BitAllocationsIsCalledWithTrueMutlipleTimesThenAllocatorIsReused) {
|
||||
memoryManager->setForce32BitAllocations(true);
|
||||
EXPECT_NE(nullptr, memoryManager->allocator32Bit.get());
|
||||
|
@ -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"),
|
||||
@ -36,10 +36,9 @@ struct timeStamps {
|
||||
uint64_t end;
|
||||
};
|
||||
|
||||
template <size_t TemplateMaxTagPoolCount = 1>
|
||||
class MockTagAllocator : public TagAllocator<timeStamps> {
|
||||
public:
|
||||
MockTagAllocator(MemoryManager *memMngr, size_t tagCount, size_t tagAlignment) : TagAllocator<timeStamps>(memMngr, tagCount, tagAlignment, TemplateMaxTagPoolCount) {
|
||||
MockTagAllocator(MemoryManager *memMngr, size_t tagCount, size_t tagAlignment) : TagAllocator<timeStamps>(memMngr, tagCount, tagAlignment) {
|
||||
}
|
||||
|
||||
GraphicsAllocation *getGraphicsAllocation(size_t id = 0) {
|
||||
@ -73,7 +72,7 @@ class MockTagAllocator : public TagAllocator<timeStamps> {
|
||||
|
||||
TEST_F(TagAllocatorTest, Initialize) {
|
||||
|
||||
MockTagAllocator<> tagAllocator(memoryManager, 100, 64);
|
||||
MockTagAllocator tagAllocator(memoryManager, 100, 64);
|
||||
|
||||
ASSERT_NE(nullptr, tagAllocator.getGraphicsAllocation());
|
||||
|
||||
@ -87,7 +86,7 @@ TEST_F(TagAllocatorTest, Initialize) {
|
||||
|
||||
TEST_F(TagAllocatorTest, GetReturnTagCheckFreeAndUsedLists) {
|
||||
|
||||
MockTagAllocator<> tagAllocator(memoryManager, 10, 16);
|
||||
MockTagAllocator tagAllocator(memoryManager, 10, 16);
|
||||
|
||||
ASSERT_NE(nullptr, tagAllocator.getGraphicsAllocation());
|
||||
ASSERT_NE(nullptr, tagAllocator.getFreeTagsHead());
|
||||
@ -118,7 +117,7 @@ TEST_F(TagAllocatorTest, GetReturnTagCheckFreeAndUsedLists) {
|
||||
TEST_F(TagAllocatorTest, TagAlignment) {
|
||||
|
||||
size_t alignment = 64;
|
||||
MockTagAllocator<> tagAllocator(memoryManager, 10, alignment);
|
||||
MockTagAllocator tagAllocator(memoryManager, 10, alignment);
|
||||
|
||||
ASSERT_NE(nullptr, tagAllocator.getFreeTagsHead());
|
||||
|
||||
@ -130,31 +129,35 @@ TEST_F(TagAllocatorTest, TagAlignment) {
|
||||
tagAllocator.returnTag(tagNode);
|
||||
}
|
||||
|
||||
TEST_F(TagAllocatorTest, GetAllTags) {
|
||||
TEST_F(TagAllocatorTest, givenTagAllocatorWhenAllNodesWereUsedThenCreateNewGraphicsAllocation) {
|
||||
|
||||
// Big alignment to force only 4 tags
|
||||
size_t alignment = 1024;
|
||||
MockTagAllocator<> tagAllocator(memoryManager, 4, alignment);
|
||||
MockTagAllocator tagAllocator(memoryManager, 4, alignment);
|
||||
|
||||
ASSERT_NE(nullptr, tagAllocator.getFreeTagsHead());
|
||||
|
||||
TagNode<timeStamps> *tagNodes[4];
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
for (size_t i = 0; i < 4; i++) {
|
||||
tagNodes[i] = tagAllocator.getTag();
|
||||
EXPECT_NE(nullptr, tagNodes[i]);
|
||||
}
|
||||
EXPECT_EQ(1u, tagAllocator.getGraphicsAllocationsCount());
|
||||
EXPECT_EQ(1u, tagAllocator.getTagPoolCount());
|
||||
|
||||
TagNode<timeStamps> *nullTag = tagAllocator.getTag();
|
||||
TagNode<timeStamps> *tagNode = tagAllocator.getTag();
|
||||
EXPECT_NE(nullptr, tagNode);
|
||||
|
||||
EXPECT_EQ(nullptr, nullTag);
|
||||
EXPECT_EQ(2u, tagAllocator.getGraphicsAllocationsCount());
|
||||
EXPECT_EQ(2u, tagAllocator.getTagPoolCount());
|
||||
}
|
||||
|
||||
TEST_F(TagAllocatorTest, GetTagsAndReturnInDifferentOrder) {
|
||||
|
||||
// Big alignment to force only 4 tags
|
||||
size_t alignment = 1024;
|
||||
MockTagAllocator<> tagAllocator(memoryManager, 4, alignment);
|
||||
MockTagAllocator tagAllocator(memoryManager, 4, alignment);
|
||||
|
||||
ASSERT_NE(nullptr, tagAllocator.getFreeTagsHead());
|
||||
|
||||
@ -164,9 +167,13 @@ TEST_F(TagAllocatorTest, GetTagsAndReturnInDifferentOrder) {
|
||||
tagNodes[i] = tagAllocator.getTag();
|
||||
EXPECT_NE(nullptr, tagNodes[i]);
|
||||
}
|
||||
EXPECT_EQ(1u, tagAllocator.getGraphicsAllocationsCount());
|
||||
EXPECT_EQ(1u, tagAllocator.getTagPoolCount());
|
||||
|
||||
TagNode<timeStamps> *nullTag = tagAllocator.getTag();
|
||||
EXPECT_EQ(nullptr, nullTag);
|
||||
TagNode<timeStamps> *tagNode2 = tagAllocator.getTag();
|
||||
EXPECT_NE(nullptr, tagNode2);
|
||||
EXPECT_EQ(2u, tagAllocator.getGraphicsAllocationsCount());
|
||||
EXPECT_EQ(2u, tagAllocator.getTagPoolCount());
|
||||
|
||||
IDList<TagNode<timeStamps>> &freeList = tagAllocator.getFreeTags();
|
||||
bool isFoundOnFreeList = freeList.peekContains(*tagNodes[0]);
|
||||
@ -195,23 +202,22 @@ TEST_F(TagAllocatorTest, GetTagsFromTwoPools) {
|
||||
|
||||
// Big alignment to force only 1 tag
|
||||
size_t alignment = 4096;
|
||||
MockTagAllocator<2> tagAllocator(memoryManager, 1, alignment);
|
||||
MockTagAllocator tagAllocator(memoryManager, 1, alignment);
|
||||
|
||||
ASSERT_NE(nullptr, tagAllocator.getFreeTagsHead());
|
||||
|
||||
TagNode<timeStamps> *tagNode1, *tagNode2;
|
||||
|
||||
tagNode1 = tagAllocator.getTag();
|
||||
EXPECT_NE(nullptr, tagNode1);
|
||||
ASSERT_NE(nullptr, tagNode1);
|
||||
|
||||
tagNode2 = tagAllocator.getTag();
|
||||
ASSERT_NE(nullptr, tagNode2);
|
||||
|
||||
EXPECT_EQ(2u, tagAllocator.getGraphicsAllocationsCount());
|
||||
EXPECT_EQ(2u, tagAllocator.getTagPoolCount());
|
||||
EXPECT_NE(tagNode1->getGraphicsAllocation(), tagNode2->getGraphicsAllocation());
|
||||
|
||||
TagNode<timeStamps> *nullTag = tagAllocator.getTag();
|
||||
EXPECT_EQ(nullptr, nullTag);
|
||||
|
||||
tagAllocator.returnTag(tagNode1);
|
||||
tagAllocator.returnTag(tagNode2);
|
||||
}
|
||||
@ -220,7 +226,7 @@ TEST_F(TagAllocatorTest, CleanupResources) {
|
||||
|
||||
// Big alignment to force only 1 tag
|
||||
size_t alignment = 4096;
|
||||
MockTagAllocator<2> tagAllocator(memoryManager, 1, alignment);
|
||||
MockTagAllocator tagAllocator(memoryManager, 1, alignment);
|
||||
|
||||
TagNode<timeStamps> *tagNode1, *tagNode2;
|
||||
|
||||
|
Reference in New Issue
Block a user