Skip to content

Commit a2c05a2

Browse files
committed
Set allocationType in constructors.
Change-Id: I66738be1239acdaf282f813aed46066bc5023112 Signed-off-by: Piotr Fusik <[email protected]>
1 parent 980bf72 commit a2c05a2

File tree

9 files changed

+36
-60
lines changed

9 files changed

+36
-60
lines changed

runtime/memory_manager/memory_manager.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,6 @@ GraphicsAllocation *MemoryManager::allocateGraphicsMemoryInPreferredPool(const A
298298
if (!allocation && status == AllocationStatus::RetryInNonDevicePool) {
299299
allocation = allocateGraphicsMemory(allocationData);
300300
}
301-
if (allocation) {
302-
allocation->setAllocationType(properties.allocationType);
303-
}
304301
DebugManager.logAllocation(allocation);
305302
return allocation;
306303
}

runtime/os_interface/windows/wddm_memory_manager.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ GraphicsAllocation *WddmMemoryManager::allocate32BitGraphicsMemoryImpl(const All
192192
wddmAllocation->setDriverAllocatedCpuPtr(pSysMem);
193193
wddmAllocation->set32BitAllocation(true);
194194
wddmAllocation->setAllocationOffset(offset);
195-
wddmAllocation->setAllocationType(allocationData.type);
196195

197196
gmm = new Gmm(ptrAligned, sizeAligned, false);
198197
wddmAllocation->gmm = gmm;

unit_tests/aub_mem_dump/aub_alloc_dump_tests.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "unit_tests/fixtures/device_fixture.h"
1313
#include "unit_tests/fixtures/image_fixture.h"
1414
#include "unit_tests/helpers/debug_manager_state_restore.h"
15+
#include "unit_tests/mocks/mock_gmm.h"
1516
#include "unit_tests/mocks/mock_gmm_resource_info.h"
1617

1718
using namespace OCLRT;
@@ -93,8 +94,7 @@ HWTEST_F(AubAllocDumpTests, givenNonWritableBufferWhenDumpAllocationIsCalledAndD
9394
DebugManager.flags.AUBDumpBufferFormat.set("BIN");
9495

9596
auto memoryManager = pDevice->getMemoryManager();
96-
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
97-
gfxAllocation->setAllocationType(GraphicsAllocation::AllocationType::BUFFER);
97+
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER});
9898

9999
std::unique_ptr<AubFileStreamMock> mockAubFileStream(new AubFileStreamMock());
100100
AubAllocDump::dumpAllocation<FamilyType>(*gfxAllocation, mockAubFileStream.get(), 0);
@@ -109,8 +109,7 @@ HWTEST_F(AubAllocDumpTests, givenNonWritableImageWhenDumpAllocationIsCalledAndDu
109109
DebugManager.flags.AUBDumpBufferFormat.set("BMP");
110110

111111
auto memoryManager = pDevice->getMemoryManager();
112-
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
113-
gfxAllocation->setAllocationType(GraphicsAllocation::AllocationType::IMAGE);
112+
auto gfxAllocation = MockGmm::allocateImage2d(*memoryManager);
114113

115114
std::unique_ptr<AubFileStreamMock> mockAubFileStream(new AubFileStreamMock());
116115
AubAllocDump::dumpAllocation<FamilyType>(*gfxAllocation, mockAubFileStream.get(), 0);

unit_tests/command_stream/aub_command_stream_receiver_1_tests.cpp

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -698,16 +698,16 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenWriteMe
698698

699699
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
700700

701-
GraphicsAllocation::AllocationType onlyOneTimeAubWritableTypes[] = {
701+
const GraphicsAllocation::AllocationType onlyOneTimeAubWritableTypes[] = {
702702
GraphicsAllocation::AllocationType::BUFFER,
703703
GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY,
704704
GraphicsAllocation::AllocationType::BUFFER_COMPRESSED,
705705
GraphicsAllocation::AllocationType::IMAGE,
706706
GraphicsAllocation::AllocationType::TIMESTAMP_PACKET_TAG_BUFFER};
707707

708-
for (size_t i = 0; i < arrayCount(onlyOneTimeAubWritableTypes); i++) {
708+
for (auto allocationType : onlyOneTimeAubWritableTypes) {
709709
gfxAllocation->setAubWritable(true);
710-
gfxAllocation->setAllocationType(onlyOneTimeAubWritableTypes[i]);
710+
gfxAllocation->setAllocationType(allocationType);
711711
aubCsr->writeMemory(*gfxAllocation);
712712

713713
EXPECT_FALSE(gfxAllocation->isAubWritable());
@@ -721,13 +721,9 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenProcess
721721
memoryManager.reset(aubCsr->createMemoryManager(false, false));
722722
aubCsr->setupContext(*pDevice->getDefaultEngine().osContext);
723723

724-
auto gfxBufferAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
724+
auto gfxBufferAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER});
725725

726-
gfxBufferAllocation->setAllocationType(GraphicsAllocation::AllocationType::BUFFER);
727-
728-
auto gfxImageAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
729-
730-
gfxImageAllocation->setAllocationType(GraphicsAllocation::AllocationType::IMAGE);
726+
auto gfxImageAllocation = MockGmm::allocateImage2d(*memoryManager);
731727

732728
ResidencyContainer allocationsForResidency = {gfxBufferAllocation, gfxImageAllocation};
733729
aubCsr->processResidency(allocationsForResidency);
@@ -746,14 +742,10 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInSubCaptur
746742
memoryManager.reset(aubCsr->createMemoryManager(false, false));
747743
aubCsr->setupContext(*pDevice->getDefaultEngine().osContext);
748744

749-
auto gfxBufferAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
750-
751-
gfxBufferAllocation->setAllocationType(GraphicsAllocation::AllocationType::BUFFER);
745+
auto gfxBufferAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER});
752746
gfxBufferAllocation->setAubWritable(false);
753747

754-
auto gfxImageAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
755-
756-
gfxImageAllocation->setAllocationType(GraphicsAllocation::AllocationType::IMAGE);
748+
auto gfxImageAllocation = MockGmm::allocateImage2d(*memoryManager);
757749
gfxImageAllocation->setAubWritable(false);
758750

759751
aubCsr->dumpAubNonWritable = true;
@@ -775,14 +767,10 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenProcess
775767
memoryManager.reset(aubCsr->createMemoryManager(false, false));
776768
aubCsr->setupContext(*pDevice->getDefaultEngine().osContext);
777769

778-
auto gfxBufferAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
779-
780-
gfxBufferAllocation->setAllocationType(GraphicsAllocation::AllocationType::BUFFER);
770+
auto gfxBufferAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER});
781771
gfxBufferAllocation->setAubWritable(false);
782772

783-
auto gfxImageAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
784-
785-
gfxImageAllocation->setAllocationType(GraphicsAllocation::AllocationType::IMAGE);
773+
auto gfxImageAllocation = MockGmm::allocateImage2d(*memoryManager);
786774
gfxImageAllocation->setAubWritable(false);
787775

788776
aubCsr->dumpAubNonWritable = false;

unit_tests/command_stream/aub_command_stream_receiver_2_tests.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -892,9 +892,7 @@ HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationWritableWhenDumpA
892892
auto mockHardwareContext = static_cast<MockHardwareContext *>(aubCsr.hardwareContextController->hardwareContexts[0].get());
893893

894894
auto memoryManager = pDevice->getMemoryManager();
895-
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
896-
897-
gfxAllocation->setAllocationType(GraphicsAllocation::AllocationType::BUFFER);
895+
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER});
898896
gfxAllocation->setMemObjectsAllocationWithWritableFlags(true);
899897
EXPECT_TRUE(AubAllocDump::isWritableBuffer(*gfxAllocation));
900898

@@ -919,9 +917,8 @@ HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationWritableWhenDumpA
919917
auto mockHardwareContext = static_cast<MockHardwareContext *>(aubCsr.hardwareContextController->hardwareContexts[0].get());
920918

921919
auto memoryManager = pDevice->getMemoryManager();
922-
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
920+
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER});
923921

924-
gfxAllocation->setAllocationType(GraphicsAllocation::AllocationType::BUFFER);
925922
gfxAllocation->setMemObjectsAllocationWithWritableFlags(true);
926923
EXPECT_TRUE(AubAllocDump::isWritableBuffer(*gfxAllocation));
927924

@@ -947,9 +944,8 @@ HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationNonWritableWhenDu
947944
auto mockHardwareContext = static_cast<MockHardwareContext *>(aubCsr.hardwareContextController->hardwareContexts[0].get());
948945

949946
auto memoryManager = pDevice->getMemoryManager();
950-
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
947+
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER});
951948

952-
gfxAllocation->setAllocationType(GraphicsAllocation::AllocationType::BUFFER);
953949
gfxAllocation->setMemObjectsAllocationWithWritableFlags(false);
954950
EXPECT_FALSE(AubAllocDump::isWritableBuffer(*gfxAllocation));
955951

@@ -976,9 +972,8 @@ HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationNotDumpableWhenDu
976972
auto mockHardwareContext = static_cast<MockHardwareContext *>(aubCsr.hardwareContextController->hardwareContexts[0].get());
977973

978974
auto memoryManager = pDevice->getMemoryManager();
979-
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
975+
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER});
980976

981-
gfxAllocation->setAllocationType(GraphicsAllocation::AllocationType::BUFFER);
982977
gfxAllocation->setMemObjectsAllocationWithWritableFlags(true);
983978
gfxAllocation->setAllocDumpable(false);
984979

@@ -1006,9 +1001,8 @@ HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationDumpableWhenDumpA
10061001
auto mockHardwareContext = static_cast<MockHardwareContext *>(aubCsr.hardwareContextController->hardwareContexts[0].get());
10071002

10081003
auto memoryManager = pDevice->getMemoryManager();
1009-
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
1004+
auto gfxAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize, GraphicsAllocation::AllocationType::BUFFER});
10101005

1011-
gfxAllocation->setAllocationType(GraphicsAllocation::AllocationType::BUFFER);
10121006
gfxAllocation->setMemObjectsAllocationWithWritableFlags(true);
10131007
gfxAllocation->setAllocDumpable(true);
10141008

unit_tests/helpers/hw_helper_tests.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -386,11 +386,10 @@ HWTEST_F(HwHelperTest, givenCreatedSurfaceStateBufferWhenGmmAndAllocationCompres
386386
void *cpuAddr = reinterpret_cast<void *>(0x4000);
387387
uint64_t gpuAddr = 0x4000u;
388388
size_t allocSize = size;
389-
GraphicsAllocation allocation(GraphicsAllocation::AllocationType::UNKNOWN, cpuAddr, gpuAddr, 0u, allocSize, MemoryPool::MemoryNull, false);
389+
GraphicsAllocation allocation(GraphicsAllocation::AllocationType::BUFFER_COMPRESSED, cpuAddr, gpuAddr, 0u, allocSize, MemoryPool::MemoryNull, false);
390390
allocation.gmm = new Gmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize(), false);
391391
ASSERT_NE(nullptr, allocation.gmm);
392392
allocation.gmm->isRenderCompressed = true;
393-
allocation.setAllocationType(GraphicsAllocation::AllocationType::BUFFER_COMPRESSED);
394393
SURFACE_TYPE type = RENDER_SURFACE_STATE::SURFACE_TYPE_SURFTYPE_BUFFER;
395394
helper.setRenderSurfaceStateForBuffer(ee, stateBuffer, size, addr, 0, pitch, &allocation, 0, type, false);
396395
EXPECT_EQ(RENDER_SURFACE_STATE::COHERENCY_TYPE_GPU_COHERENT, state->getCoherencyType());
@@ -453,10 +452,9 @@ HWTEST_F(HwHelperTest, givenCreatedSurfaceStateBufferWhenGmmCompressionDisabledA
453452
void *cpuAddr = reinterpret_cast<void *>(0x4000);
454453
uint64_t gpuAddr = 0x4000u;
455454
size_t allocSize = size;
456-
GraphicsAllocation allocation(GraphicsAllocation::AllocationType::UNKNOWN, cpuAddr, gpuAddr, 0u, allocSize, MemoryPool::MemoryNull, false);
455+
GraphicsAllocation allocation(GraphicsAllocation::AllocationType::BUFFER_COMPRESSED, cpuAddr, gpuAddr, 0u, allocSize, MemoryPool::MemoryNull, false);
457456
allocation.gmm = new Gmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize(), false);
458457
ASSERT_NE(nullptr, allocation.gmm);
459-
allocation.setAllocationType(GraphicsAllocation::AllocationType::BUFFER_COMPRESSED);
460458
SURFACE_TYPE type = RENDER_SURFACE_STATE::SURFACE_TYPE_SURFTYPE_BUFFER;
461459
helper.setRenderSurfaceStateForBuffer(ee, stateBuffer, size, addr, 0, pitch, &allocation, 0, type, false);
462460
EXPECT_EQ(RENDER_SURFACE_STATE::COHERENCY_TYPE_IA_COHERENT, state->getCoherencyType());
@@ -486,11 +484,10 @@ HWTEST_F(HwHelperTest, givenCreatedSurfaceStateBufferWhenGmmAndAllocationCompres
486484
void *cpuAddr = reinterpret_cast<void *>(0x4000);
487485
uint64_t gpuAddr = 0x4000u;
488486
size_t allocSize = size;
489-
GraphicsAllocation allocation(GraphicsAllocation::AllocationType::UNKNOWN, cpuAddr, gpuAddr, 0u, allocSize, MemoryPool::MemoryNull, false);
487+
GraphicsAllocation allocation(GraphicsAllocation::AllocationType::BUFFER_COMPRESSED, cpuAddr, gpuAddr, 0u, allocSize, MemoryPool::MemoryNull, false);
490488
allocation.gmm = new Gmm(allocation.getUnderlyingBuffer(), allocation.getUnderlyingBufferSize(), false);
491489
ASSERT_NE(nullptr, allocation.gmm);
492490
allocation.gmm->isRenderCompressed = true;
493-
allocation.setAllocationType(GraphicsAllocation::AllocationType::BUFFER_COMPRESSED);
494491
SURFACE_TYPE type = RENDER_SURFACE_STATE::SURFACE_TYPE_SURFTYPE_BUFFER;
495492
helper.setRenderSurfaceStateForBuffer(ee, stateBuffer, size, addr, 0, pitch, &allocation, 0, type, true);
496493
EXPECT_EQ(RENDER_SURFACE_STATE::COHERENCY_TYPE_IA_COHERENT, state->getCoherencyType());

unit_tests/memory_manager/memory_manager_tests.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,16 +1618,14 @@ TEST(MemoryManagerTest, givenMemoryManagerWhenAllocationWasNotUnlockedThenItIsUn
16181618
}
16191619

16201620
TEST(HeapSelectorTest, given32bitInternalAllocationWhenSelectingHeapThenInternalHeapIsUsed) {
1621-
GraphicsAllocation allocation{GraphicsAllocation::AllocationType::UNKNOWN, nullptr, 0, 0, 0, MemoryPool::MemoryNull, false};
1621+
GraphicsAllocation allocation{GraphicsAllocation::AllocationType::KERNEL_ISA, nullptr, 0, 0, 0, MemoryPool::MemoryNull, false};
16221622
allocation.set32BitAllocation(true);
1623-
allocation.setAllocationType(GraphicsAllocation::AllocationType::KERNEL_ISA);
16241623
EXPECT_EQ(internalHeapIndex, MemoryManager::selectHeap(&allocation, nullptr, *platformDevices[0]));
16251624
}
16261625

16271626
TEST(HeapSelectorTest, givenNon32bitInternalAllocationWhenSelectingHeapThenInternalHeapIsUsed) {
1628-
GraphicsAllocation allocation{GraphicsAllocation::AllocationType::UNKNOWN, nullptr, 0, 0, 0, MemoryPool::MemoryNull, false};
1627+
GraphicsAllocation allocation{GraphicsAllocation::AllocationType::KERNEL_ISA, nullptr, 0, 0, 0, MemoryPool::MemoryNull, false};
16291628
allocation.set32BitAllocation(false);
1630-
allocation.setAllocationType(GraphicsAllocation::AllocationType::KERNEL_ISA);
16311629
EXPECT_EQ(internalHeapIndex, MemoryManager::selectHeap(&allocation, nullptr, *platformDevices[0]));
16321630
}
16331631

unit_tests/mocks/mock_gmm.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,14 @@ class MockGmm : public Gmm {
3737
}
3838
return imgInfo;
3939
}
40+
41+
static GraphicsAllocation *allocateImage2d(MemoryManager &memoryManager) {
42+
cl_image_desc imgDesc{};
43+
imgDesc.image_type = CL_MEM_OBJECT_IMAGE2D;
44+
imgDesc.image_width = 5;
45+
imgDesc.image_height = 5;
46+
auto imgInfo = MockGmm::initImgInfo(imgDesc, 0, nullptr);
47+
return memoryManager.allocateGraphicsMemoryWithProperties(AllocationProperties{&imgInfo, true});
48+
}
4049
};
4150
} // namespace OCLRT

0 commit comments

Comments
 (0)