Add MultiGraphicsAllocation class to store multiple graphics allocations
Related-To: NEO-4672 Change-Id: I01c758b0a9b80e3087011b74bbf04ec2bfc23b19 Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
parent
5b0a2ee09b
commit
1efa54edcf
|
@ -14,6 +14,7 @@ append_sources_from_properties(NEO_CORE_UNIT_TESTS_SOURCES
|
|||
NEO_CORE_INDIRECT_HEAP_TESTS
|
||||
NEO_CORE_ENCODERS_TESTS
|
||||
NEO_CORE_IMAGE_TESTS
|
||||
NEO_CORE_MEMORY_MANAGER_TESTS
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
|
|
|
@ -35,6 +35,8 @@ set(NEO_CORE_MEMORY_MANAGER
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/memory_operations_handler.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/memory_operations_status.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/memory_pool.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/multi_graphics_allocation.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/multi_graphics_allocation.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/residency.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/residency.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/residency_container.h
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright (C) 2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/source/memory_manager/multi_graphics_allocation.h"
|
||||
|
||||
namespace NEO {
|
||||
|
||||
MultiGraphicsAllocation::MultiGraphicsAllocation(uint32_t maxRootDeviceIndex) {
|
||||
graphicsAllocations.resize(maxRootDeviceIndex + 1);
|
||||
}
|
||||
|
||||
GraphicsAllocation *MultiGraphicsAllocation::getDefaultGraphicsAllocation() const {
|
||||
for (auto &allocation : graphicsAllocations) {
|
||||
if (allocation) {
|
||||
return allocation;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void MultiGraphicsAllocation::addAllocation(GraphicsAllocation *graphicsAllocation) {
|
||||
UNRECOVERABLE_IF(graphicsAllocation == nullptr);
|
||||
UNRECOVERABLE_IF(graphicsAllocations.size() < graphicsAllocation->getRootDeviceIndex() + 1);
|
||||
graphicsAllocations[graphicsAllocation->getRootDeviceIndex()] = graphicsAllocation;
|
||||
}
|
||||
|
||||
GraphicsAllocation *MultiGraphicsAllocation::getGraphicsAllocation(uint32_t rootDeviceIndex) const {
|
||||
return graphicsAllocations[rootDeviceIndex];
|
||||
}
|
||||
|
||||
GraphicsAllocation::AllocationType MultiGraphicsAllocation::getAllocationType() const {
|
||||
return getDefaultGraphicsAllocation()->getAllocationType();
|
||||
}
|
||||
|
||||
bool MultiGraphicsAllocation::isCoherent() const {
|
||||
return getDefaultGraphicsAllocation()->isCoherent();
|
||||
}
|
||||
|
||||
} // namespace NEO
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (C) 2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "shared/source/helpers/non_copyable_or_moveable.h"
|
||||
#include "shared/source/memory_manager/graphics_allocation.h"
|
||||
|
||||
namespace NEO {
|
||||
|
||||
class MultiGraphicsAllocation : NonCopyableOrMovableClass {
|
||||
public:
|
||||
MultiGraphicsAllocation(uint32_t maxRootDeviceIndex);
|
||||
|
||||
GraphicsAllocation *getDefaultGraphicsAllocation() const;
|
||||
|
||||
void addAllocation(GraphicsAllocation *graphicsAllocation);
|
||||
|
||||
GraphicsAllocation *getGraphicsAllocation(uint32_t rootDeviceIndex) const;
|
||||
|
||||
GraphicsAllocation::AllocationType getAllocationType() const;
|
||||
|
||||
bool isCoherent() const;
|
||||
|
||||
protected:
|
||||
std::vector<GraphicsAllocation *> graphicsAllocations;
|
||||
};
|
||||
|
||||
} // namespace NEO
|
|
@ -0,0 +1,12 @@
|
|||
#
|
||||
# Copyright (C) 2020 Intel Corporation
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
set(NEO_CORE_MEMORY_MANAGER_TESTS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/multi_graphics_allocation_tests.cpp
|
||||
)
|
||||
|
||||
set_property(GLOBAL PROPERTY NEO_CORE_MEMORY_MANAGER_TESTS ${NEO_CORE_MEMORY_MANAGER_TESTS})
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Copyright (C) 2020 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/source/memory_manager/multi_graphics_allocation.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace NEO;
|
||||
|
||||
struct MockMultiGraphicsAllocation : public MultiGraphicsAllocation {
|
||||
using MultiGraphicsAllocation::graphicsAllocations;
|
||||
using MultiGraphicsAllocation::MultiGraphicsAllocation;
|
||||
};
|
||||
|
||||
TEST(MultiGraphicsAllocationTest, whenCreatingMultiGraphicsAllocationThenTheAllocationIsObtainableAsADefault) {
|
||||
GraphicsAllocation graphicsAllocation(1, // rootDeviceIndex
|
||||
GraphicsAllocation::AllocationType::BUFFER,
|
||||
nullptr, 0, 0, MemoryPool::System4KBPages);
|
||||
|
||||
MockMultiGraphicsAllocation multiGraphicsAllocation(1);
|
||||
EXPECT_EQ(2u, multiGraphicsAllocation.graphicsAllocations.size());
|
||||
|
||||
multiGraphicsAllocation.addAllocation(&graphicsAllocation);
|
||||
|
||||
EXPECT_EQ(&graphicsAllocation, multiGraphicsAllocation.getDefaultGraphicsAllocation());
|
||||
|
||||
EXPECT_EQ(&graphicsAllocation, multiGraphicsAllocation.getGraphicsAllocation(graphicsAllocation.getRootDeviceIndex()));
|
||||
EXPECT_EQ(nullptr, multiGraphicsAllocation.getGraphicsAllocation(0));
|
||||
}
|
||||
|
||||
TEST(MultiGraphicsAllocationTest, givenMultiGraphicsAllocationWhenAddingMultipleGraphicsAllocationsThenTheyAreObtainableByRootDeviceIndex) {
|
||||
GraphicsAllocation graphicsAllocation0(0, // rootDeviceIndex
|
||||
GraphicsAllocation::AllocationType::BUFFER,
|
||||
nullptr, 0, 0, MemoryPool::System4KBPages);
|
||||
GraphicsAllocation graphicsAllocation1(1, // rootDeviceIndex
|
||||
GraphicsAllocation::AllocationType::BUFFER,
|
||||
nullptr, 0, 0, MemoryPool::System4KBPages);
|
||||
|
||||
MockMultiGraphicsAllocation multiGraphicsAllocation(1);
|
||||
|
||||
EXPECT_EQ(2u, multiGraphicsAllocation.graphicsAllocations.size());
|
||||
multiGraphicsAllocation.addAllocation(&graphicsAllocation0);
|
||||
multiGraphicsAllocation.addAllocation(&graphicsAllocation1);
|
||||
|
||||
EXPECT_EQ(&graphicsAllocation0, multiGraphicsAllocation.getGraphicsAllocation(graphicsAllocation0.getRootDeviceIndex()));
|
||||
EXPECT_EQ(&graphicsAllocation1, multiGraphicsAllocation.getGraphicsAllocation(graphicsAllocation1.getRootDeviceIndex()));
|
||||
}
|
||||
|
||||
TEST(MultiGraphicsAllocationTest, givenMultiGraphicsAllocationWhenGettingAllocationTypeThenReturnAllocationTypeFromDefaultAllocation) {
|
||||
auto expectedAllocationType = GraphicsAllocation::AllocationType::BUFFER;
|
||||
GraphicsAllocation graphicsAllocation(1, // rootDeviceIndex
|
||||
expectedAllocationType,
|
||||
nullptr, 0, 0, MemoryPool::System4KBPages);
|
||||
|
||||
MockMultiGraphicsAllocation multiGraphicsAllocation(1);
|
||||
multiGraphicsAllocation.addAllocation(&graphicsAllocation);
|
||||
|
||||
EXPECT_EQ(multiGraphicsAllocation.getDefaultGraphicsAllocation()->getAllocationType(), multiGraphicsAllocation.getAllocationType());
|
||||
EXPECT_EQ(expectedAllocationType, multiGraphicsAllocation.getAllocationType());
|
||||
}
|
||||
|
||||
TEST(MultiGraphicsAllocationTest, givenMultiGraphicsAllocationWhenGettingCoherencyStatusThenReturnCoherencyStatusFromDefaultAllocation) {
|
||||
auto expectedAllocationType = GraphicsAllocation::AllocationType::BUFFER;
|
||||
GraphicsAllocation graphicsAllocation(1, // rootDeviceIndex
|
||||
expectedAllocationType,
|
||||
nullptr, 0, 0, MemoryPool::System4KBPages);
|
||||
|
||||
MockMultiGraphicsAllocation multiGraphicsAllocation(1);
|
||||
multiGraphicsAllocation.addAllocation(&graphicsAllocation);
|
||||
|
||||
graphicsAllocation.setCoherent(true);
|
||||
EXPECT_TRUE(multiGraphicsAllocation.isCoherent());
|
||||
|
||||
graphicsAllocation.setCoherent(false);
|
||||
EXPECT_FALSE(multiGraphicsAllocation.isCoherent());
|
||||
}
|
||||
|
||||
TEST(MultiGraphicsAllocationTest, WhenCreatingMultiGraphicsAllocationWithoutGraphicsAllocationThenNoDefaultAllocationIsReturned) {
|
||||
MockMultiGraphicsAllocation multiGraphicsAllocation(1);
|
||||
EXPECT_EQ(nullptr, multiGraphicsAllocation.getDefaultGraphicsAllocation());
|
||||
}
|
Loading…
Reference in New Issue