Skip to content

Commit 15f3353

Browse files
Pass additional allocation parameters to aub_stream
Signed-off-by: Bartosz Dunajski <[email protected]>
1 parent e3e8171 commit 15f3353

File tree

5 files changed

+54
-19
lines changed

5 files changed

+54
-19
lines changed

opencl/source/command_stream/definitions/command_stream_receiver_simulated_hw.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ class CommandStreamReceiverSimulatedHw : public CommandStreamReceiverSimulatedCo
6060
aub_stream::AllocationParams allocationParams(gpuAddress, cpuAddress, size, this->getMemoryBank(&graphicsAllocation),
6161
hint, graphicsAllocation.getUsedPageSize());
6262

63+
auto gmm = graphicsAllocation.getDefaultGmm();
64+
65+
allocationParams.additionalParams.compressionEnabled = gmm ? gmm->isRenderCompressed : false;
66+
6367
this->aubManager->writeMemory2(allocationParams);
6468
}
6569

opencl/test/unit_test/command_stream/aub_command_stream_receiver_1_tests.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,7 @@ HWTEST_F(AubCsrTest, WhenWriteWithAubManagerIsCalledThenAubManagerIsInvokedWithC
12721272
EXPECT_TRUE(aubManager.writeMemory2Called);
12731273
EXPECT_EQ(AubMemDump::DataTypeHintValues::TraceBatchBuffer, aubManager.hintToWriteMemory);
12741274

1275-
aubManager.writeMemoryCalled = false;
1275+
aubManager.writeMemory2Called = false;
12761276

12771277
auto allocation2 = executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{rootDeviceIndex, true, MemoryConstants::pageSize, GraphicsAllocation::AllocationType::LINEAR_STREAM});
12781278

@@ -1353,9 +1353,7 @@ TEST_F(HardwareContextContainerTests, givenMultipleHwContextWhenSingleMethodIsCa
13531353
EXPECT_FALSE(mockHwContext1->expectMemoryCalled);
13541354
EXPECT_FALSE(mockHwContext0->submitCalled);
13551355
EXPECT_FALSE(mockHwContext1->submitCalled);
1356-
EXPECT_FALSE(mockHwContext0->writeMemoryCalled);
13571356
EXPECT_FALSE(mockHwContext0->writeMemory2Called);
1358-
EXPECT_FALSE(mockHwContext1->writeMemoryCalled);
13591357
EXPECT_FALSE(mockHwContext1->writeMemory2Called);
13601358

13611359
aub_stream::AllocationParams params(1, reinterpret_cast<const void *>(0x123), 2, 3u, 4, 5);
@@ -1374,9 +1372,7 @@ TEST_F(HardwareContextContainerTests, givenMultipleHwContextWhenSingleMethodIsCa
13741372
EXPECT_TRUE(mockHwContext1->expectMemoryCalled);
13751373
EXPECT_TRUE(mockHwContext0->submitCalled);
13761374
EXPECT_TRUE(mockHwContext1->submitCalled);
1377-
EXPECT_FALSE(mockHwContext0->writeMemoryCalled);
13781375
EXPECT_TRUE(mockHwContext0->writeMemory2Called);
1379-
EXPECT_FALSE(mockHwContext1->writeMemoryCalled);
13801376
EXPECT_TRUE(mockHwContext1->writeMemory2Called);
13811377
EXPECT_EQ(1u, mockHwContext0->memoryBanksPassed);
13821378
EXPECT_EQ(2u, mockHwContext1->memoryBanksPassed);

opencl/test/unit_test/mocks/mock_aub_manager.h

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#pragma once
99

10+
#include "shared/source/helpers/debug_helpers.h"
11+
1012
#include "third_party/aub_stream/headers/allocation_params.h"
1113
#include "third_party/aub_stream/headers/aub_manager.h"
1214
#include "third_party/aub_stream/headers/aubstream.h"
@@ -23,26 +25,29 @@ struct MockHardwareContext : public aub_stream::HardwareContext {
2325
void writeAndSubmitBatchBuffer(uint64_t gfxAddress, const void *batchBuffer, size_t size, uint32_t memoryBank, size_t pageSize) override { writeAndSubmitCalled = true; }
2426
void submitBatchBuffer(uint64_t gfxAddress, bool overrideRingHead) override { submitCalled = true; }
2527
void writeMemory(uint64_t gfxAddress, const void *memory, size_t size, uint32_t memoryBanks, int hint, size_t pageSize) override {
26-
writeMemoryCalled = true;
27-
writeMemoryPageSizePassed = pageSize;
28-
memoryBanksPassed = memoryBanks;
28+
UNRECOVERABLE_IF(true); // shouldnt be used
2929
}
3030
void writeMemory2(aub_stream::AllocationParams allocationParams) override {
3131
writeMemory2Called = true;
3232
writeMemoryPageSizePassed = allocationParams.pageSize;
3333
memoryBanksPassed = allocationParams.memoryBanks;
34+
35+
if (storeAllocationParams) {
36+
storedAllocationParams.push_back(allocationParams);
37+
}
3438
}
3539
void freeMemory(uint64_t gfxAddress, size_t size) override { freeMemoryCalled = true; }
3640
void expectMemory(uint64_t gfxAddress, const void *memory, size_t size, uint32_t compareOperation) override { expectMemoryCalled = true; }
3741
void readMemory(uint64_t gfxAddress, void *memory, size_t size, uint32_t memoryBank, size_t pageSize) override { readMemoryCalled = true; }
3842
void dumpBufferBIN(uint64_t gfxAddress, size_t size) override { dumpBufferBINCalled = true; }
3943
void dumpSurface(const SurfaceInfo &surfaceInfo) override { dumpSurfaceCalled = true; }
4044

45+
std::vector<aub_stream::AllocationParams> storedAllocationParams;
46+
bool storeAllocationParams = false;
4147
bool initializeCalled = false;
4248
bool pollForCompletionCalled = false;
4349
bool writeAndSubmitCalled = false;
4450
bool submitCalled = false;
45-
bool writeMemoryCalled = false;
4651
bool writeMemory2Called = false;
4752
bool freeMemoryCalled = false;
4853
bool expectMemoryCalled = false;
@@ -105,15 +110,17 @@ class MockAubManager : public aub_stream::AubManager {
105110
}
106111

107112
void writeMemory(uint64_t gfxAddress, const void *memory, size_t size, uint32_t memoryBanks, int hint, size_t pageSize) override {
108-
writeMemoryCalled = true;
109-
hintToWriteMemory = hint;
110-
writeMemoryPageSizePassed = pageSize;
113+
UNRECOVERABLE_IF(true); // shouldnt be used
111114
}
112115

113116
void writeMemory2(aub_stream::AllocationParams allocationParams) override {
114117
writeMemory2Called = true;
115118
hintToWriteMemory = allocationParams.hint;
116119
writeMemoryPageSizePassed = allocationParams.pageSize;
120+
121+
if (storeAllocationParams) {
122+
storedAllocationParams.push_back(allocationParams);
123+
}
117124
}
118125

119126
void writePageTableEntries(uint64_t gfxAddress, size_t size, uint32_t memoryBanks, int hint,
@@ -129,6 +136,7 @@ class MockAubManager : public aub_stream::AubManager {
129136
freeMemoryCalled = true;
130137
}
131138

139+
std::vector<aub_stream::AllocationParams> storedAllocationParams;
132140
uint32_t openCalledCnt = 0;
133141
std::string fileName = "";
134142
bool closeCalled = false;
@@ -137,11 +145,11 @@ class MockAubManager : public aub_stream::AubManager {
137145
bool isPaused = false;
138146
bool addCommentCalled = false;
139147
std::string receivedComment = "";
140-
bool writeMemoryCalled = false;
141148
bool writeMemory2Called = false;
142149
bool writePageTableEntriesCalled = false;
143150
bool writePhysicalMemoryPagesCalled = false;
144151
bool freeMemoryCalled = false;
152+
bool storeAllocationParams = false;
145153
uint32_t contextFlags = 0;
146154
int hintToWriteMemory = 0;
147155
size_t writeMemoryPageSizePassed = 0;

shared/source/os_interface/aub_memory_operations_handler.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "shared/source/os_interface/aub_memory_operations_handler.h"
99

1010
#include "shared/source/aub_mem_dump/aub_mem_dump.h"
11+
#include "shared/source/gmm_helper/gmm.h"
1112
#include "shared/source/memory_manager/graphics_allocation.h"
1213

1314
#include "third_party/aub_stream/headers/allocation_params.h"
@@ -27,12 +28,18 @@ MemoryOperationsStatus AubMemoryOperationsHandler::makeResident(Device *device,
2728
auto lock = acquireLock(resourcesLock);
2829
int hint = AubMemDump::DataTypeHintValues::TraceNotype;
2930
for (const auto &allocation : gfxAllocations) {
30-
aubManager->writeMemory2({allocation->getGpuAddress(),
31-
allocation->getUnderlyingBuffer(),
32-
allocation->getUnderlyingBufferSize(),
33-
allocation->storageInfo.getMemoryBanks(),
34-
hint,
35-
allocation->getUsedPageSize()});
31+
aub_stream::AllocationParams params(allocation->getGpuAddress(),
32+
allocation->getUnderlyingBuffer(),
33+
allocation->getUnderlyingBufferSize(),
34+
allocation->storageInfo.getMemoryBanks(),
35+
hint,
36+
allocation->getUsedPageSize());
37+
38+
auto gmm = allocation->getDefaultGmm();
39+
40+
params.additionalParams.compressionEnabled = gmm ? gmm->isRenderCompressed : false;
41+
42+
aubManager->writeMemory2(params);
3643
residentAllocations.push_back(allocation);
3744
}
3845
return MemoryOperationsStatus::SUCCESS;

shared/test/unit_test/os_interface/aub_memory_operations_handler_tests.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "shared/source/aub_mem_dump/aub_mem_dump.h"
1111

1212
#include "opencl/test/unit_test/mocks/mock_aub_manager.h"
13+
#include "opencl/test/unit_test/mocks/mock_gmm.h"
1314

1415
TEST_F(AubMemoryOperationsHandlerTests, givenNullPtrAsAubManagerWhenMakeResidentCalledThenFalseReturned) {
1516
getMemoryOperationsHandler()->setAubManager(nullptr);
@@ -27,6 +28,25 @@ TEST_F(AubMemoryOperationsHandlerTests, givenAubManagerWhenMakeResidentCalledThe
2728
EXPECT_TRUE(aubManager.writeMemory2Called);
2829
}
2930

31+
TEST_F(AubMemoryOperationsHandlerTests, givenAubManagerWhenMakeResidentCalledOnCompressedAllocationThenPassCorrectParams) {
32+
MockAubManager aubManager;
33+
aubManager.storeAllocationParams = true;
34+
35+
getMemoryOperationsHandler()->setAubManager(&aubManager);
36+
auto memoryOperationsInterface = getMemoryOperationsHandler();
37+
38+
MockGmm gmm;
39+
gmm.isRenderCompressed = true;
40+
allocPtr->setDefaultGmm(&gmm);
41+
42+
auto result = memoryOperationsInterface->makeResident(nullptr, ArrayRef<GraphicsAllocation *>(&allocPtr, 1));
43+
EXPECT_EQ(result, MemoryOperationsStatus::SUCCESS);
44+
45+
EXPECT_TRUE(aubManager.writeMemory2Called);
46+
EXPECT_EQ(1u, aubManager.storedAllocationParams.size());
47+
EXPECT_TRUE(aubManager.storedAllocationParams[0].additionalParams.compressionEnabled);
48+
}
49+
3050
TEST_F(AubMemoryOperationsHandlerTests, givenAllocationWhenMakeResidentCalledThenTraceNotypeHintReturned) {
3151
MockAubManager aubManager;
3252
getMemoryOperationsHandler()->setAubManager(&aubManager);

0 commit comments

Comments
 (0)