mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-05 09:09:04 +08:00
Implement local memory path for all devices in buffer
Related-To: NEO-4589 Signed-off-by: Krzysztof Gibala <krzysztof.gibala@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
ad747a5cbf
commit
3d9a180c12
@@ -5,14 +5,18 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "shared/source/helpers/aligned_memory.h"
|
||||
#include "shared/source/memory_manager/multi_graphics_allocation.h"
|
||||
|
||||
#include "opencl/test/unit_test/mocks/mock_memory_manager.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace NEO;
|
||||
|
||||
struct MockMultiGraphicsAllocation : public MultiGraphicsAllocation {
|
||||
using MultiGraphicsAllocation::graphicsAllocations;
|
||||
using MultiGraphicsAllocation::lastUsedRootDeviceIndex;
|
||||
using MultiGraphicsAllocation::MultiGraphicsAllocation;
|
||||
};
|
||||
|
||||
@@ -84,7 +88,7 @@ TEST(MultiGraphicsAllocationTest, WhenCreatingMultiGraphicsAllocationWithoutGrap
|
||||
EXPECT_EQ(nullptr, multiGraphicsAllocation.getDefaultGraphicsAllocation());
|
||||
}
|
||||
|
||||
TEST(MultiGraphicsAllocationTest, givenMultiGraphicsAllocationwhenRemovingGraphicsAllocationThenTheAllocationIsNoLongerAvailable) {
|
||||
TEST(MultiGraphicsAllocationTest, givenMultiGraphicsAllocationWhenRemovingGraphicsAllocationThenTheAllocationIsNoLongerAvailable) {
|
||||
uint32_t rootDeviceIndex = 1u;
|
||||
GraphicsAllocation graphicsAllocation(rootDeviceIndex,
|
||||
GraphicsAllocation::AllocationType::BUFFER,
|
||||
@@ -100,4 +104,73 @@ TEST(MultiGraphicsAllocationTest, givenMultiGraphicsAllocationwhenRemovingGraphi
|
||||
multiGraphicsAllocation.removeAllocation(rootDeviceIndex);
|
||||
|
||||
EXPECT_EQ(nullptr, multiGraphicsAllocation.getGraphicsAllocation(rootDeviceIndex));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(MultiGraphicsAllocationTest, givenMultiGraphicsAllocationWhenEnsureMemoryOnDeviceIsCalledThenDataIsProperlyTransferred) {
|
||||
constexpr auto bufferSize = 4u;
|
||||
|
||||
uint8_t hostBuffer[bufferSize] = {1u, 1u, 1u, 1u};
|
||||
uint8_t refBuffer[bufferSize] = {3u, 3u, 3u, 3u};
|
||||
|
||||
GraphicsAllocation graphicsAllocation1(1u, GraphicsAllocation::AllocationType::BUFFER, hostBuffer, bufferSize, 0, MemoryPool::LocalMemory, 0);
|
||||
GraphicsAllocation graphicsAllocation2(2u, GraphicsAllocation::AllocationType::BUFFER, refBuffer, bufferSize, 0, MemoryPool::LocalMemory, 0);
|
||||
|
||||
MockMultiGraphicsAllocation multiGraphicsAllocation(2u);
|
||||
multiGraphicsAllocation.addAllocation(&graphicsAllocation1);
|
||||
multiGraphicsAllocation.addAllocation(&graphicsAllocation2);
|
||||
|
||||
MockExecutionEnvironment mockExecutionEnvironment(defaultHwInfo.get());
|
||||
MockMemoryManager mockMemoryManager(mockExecutionEnvironment);
|
||||
|
||||
multiGraphicsAllocation.lastUsedRootDeviceIndex = 1u;
|
||||
multiGraphicsAllocation.ensureMemoryOnDevice(mockMemoryManager, 2u);
|
||||
|
||||
auto underlyingBuffer1 = multiGraphicsAllocation.getGraphicsAllocation(1u)->getUnderlyingBuffer();
|
||||
auto ptrUnderlyingBuffer1 = static_cast<uint8_t *>(underlyingBuffer1);
|
||||
|
||||
auto underlyingBuffer2 = multiGraphicsAllocation.getGraphicsAllocation(2u)->getUnderlyingBuffer();
|
||||
auto ptrUnderlyingBuffer2 = static_cast<uint8_t *>(underlyingBuffer2);
|
||||
|
||||
for (auto i = 0u; i < bufferSize; i++) {
|
||||
EXPECT_EQ(ptrUnderlyingBuffer1[i], ptrUnderlyingBuffer2[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(MultiGraphicsAllocationTest, givenMultiGraphicsAllocationWhenEnsureMemoryOnDeviceIsCalledThenLockAndUnlockAreProperlyCalled) {
|
||||
constexpr auto bufferSize = 4u;
|
||||
|
||||
uint8_t hostBuffer[bufferSize] = {1u, 1u, 1u, 1u};
|
||||
uint8_t refBuffer[bufferSize] = {3u, 3u, 3u, 3u};
|
||||
|
||||
MemoryAllocation allocation1(1u, GraphicsAllocation::AllocationType::BUFFER, hostBuffer, bufferSize, 0, MemoryPool::System4KBPages, 0);
|
||||
MemoryAllocation allocation2(2u, GraphicsAllocation::AllocationType::BUFFER, refBuffer, bufferSize, 0, MemoryPool::System4KBPages, 0);
|
||||
|
||||
MockMultiGraphicsAllocation multiGraphicsAllocation(2u);
|
||||
multiGraphicsAllocation.addAllocation(&allocation1);
|
||||
multiGraphicsAllocation.addAllocation(&allocation2);
|
||||
|
||||
MockExecutionEnvironment mockExecutionEnvironment(defaultHwInfo.get());
|
||||
MockMemoryManager mockMemoryManager(mockExecutionEnvironment);
|
||||
|
||||
multiGraphicsAllocation.ensureMemoryOnDevice(mockMemoryManager, 1u);
|
||||
EXPECT_EQ(mockMemoryManager.lockResourceCalled, 0u);
|
||||
EXPECT_EQ(mockMemoryManager.unlockResourceCalled, 0u);
|
||||
|
||||
multiGraphicsAllocation.ensureMemoryOnDevice(mockMemoryManager, 1u);
|
||||
EXPECT_EQ(mockMemoryManager.lockResourceCalled, 0u);
|
||||
EXPECT_EQ(mockMemoryManager.unlockResourceCalled, 0u);
|
||||
|
||||
multiGraphicsAllocation.ensureMemoryOnDevice(mockMemoryManager, 2u);
|
||||
EXPECT_EQ(mockMemoryManager.lockResourceCalled, 0u);
|
||||
EXPECT_EQ(mockMemoryManager.unlockResourceCalled, 0u);
|
||||
|
||||
multiGraphicsAllocation.ensureMemoryOnDevice(mockMemoryManager, 1u);
|
||||
EXPECT_EQ(mockMemoryManager.lockResourceCalled, 0u);
|
||||
EXPECT_EQ(mockMemoryManager.unlockResourceCalled, 0u);
|
||||
|
||||
(&allocation1)->overrideMemoryPool(MemoryPool::LocalMemory);
|
||||
(&allocation2)->overrideMemoryPool(MemoryPool::LocalMemory);
|
||||
multiGraphicsAllocation.ensureMemoryOnDevice(mockMemoryManager, 2u);
|
||||
EXPECT_EQ(mockMemoryManager.lockResourceCalled, 2u);
|
||||
EXPECT_EQ(mockMemoryManager.unlockResourceCalled, 2u);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user