Correct residency of private scratch allocation

Related-To: NEO-3190

Change-Id: Ia18e2d2ce5e30901f55e7a050a3e453fb4969ada
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2019-07-15 09:12:53 +02:00
committed by sys_ocldev
parent 2c0c0ace88
commit a72109d209
3 changed files with 105 additions and 3 deletions

View File

@@ -442,7 +442,7 @@ HWTEST_P(EnqueueKernelWithScratch, GivenKernelRequiringScratchWhenItIsEnqueuedWi
EXPECT_TRUE(mockCsr->isMadeResident(graphicsAllocation));
// Enqueue With ScratchSize bigger then previous
// Enqueue With ScratchSize bigger than previous
scratchSize = 8196;
mediaVFEstate.PerThreadScratchSpace = scratchSize;

View File

@@ -15,6 +15,7 @@
#include "test.h"
#include "unit_tests/fixtures/ult_command_stream_receiver_fixture.h"
#include "unit_tests/helpers/debug_manager_state_restore.h"
#include "unit_tests/mocks/mock_allocation_properties.h"
#include "unit_tests/mocks/mock_buffer.h"
#include "unit_tests/mocks/mock_command_queue.h"
#include "unit_tests/mocks/mock_csr.h"
@@ -443,6 +444,102 @@ HWTEST_F(CommandStreamReceiverFlushTaskTests, handleTagAndScratchAllocationsResi
EXPECT_TRUE(commandStreamReceiver->isMadeNonResident(scratchAllocation));
}
struct MockScratchController : public ScratchSpaceController {
using ScratchSpaceController::privateScratchAllocation;
using ScratchSpaceController::scratchAllocation;
using ScratchSpaceController::ScratchSpaceController;
void setRequiredScratchSpace(void *sshBaseAddress,
uint32_t requiredPerThreadScratchSize,
uint32_t requiredPerThreadPrivateScratchSize,
uint32_t currentTaskCount,
uint32_t deviceIdx,
bool &stateBaseAddressDirty,
bool &vfeStateDirty) override {
if (requiredPerThreadScratchSize > scratchSizeBytes) {
scratchSizeBytes = requiredPerThreadScratchSize;
scratchAllocation = getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{requiredPerThreadScratchSize});
}
if (requiredPerThreadPrivateScratchSize > privateScratchSizeBytes) {
privateScratchSizeBytes = requiredPerThreadPrivateScratchSize;
privateScratchAllocation = getMemoryManager()->allocateGraphicsMemoryWithProperties(MockAllocationProperties{requiredPerThreadPrivateScratchSize});
}
}
uint64_t calculateNewGSH() override { return 0u; };
uint64_t getScratchPatchAddress() override { return 0u; };
void reserveHeap(IndirectHeap::Type heapType, IndirectHeap *&indirectHeap) override{};
};
HWTEST_F(CommandStreamReceiverFlushTaskTests, whenScratchIsRequiredForFirstFlushAndPrivateScratchForSecondFlushThenHandleResidencyProperly) {
auto commandStreamReceiver = new MockCsrHw<FamilyType>(*pDevice->executionEnvironment);
auto scratchController = new MockScratchController(*pDevice->executionEnvironment, *commandStreamReceiver->getInternalAllocationStorage());
commandStreamReceiver->scratchSpaceController.reset(scratchController);
pDevice->resetCommandStreamReceiver(commandStreamReceiver);
commandStreamReceiver->setRequiredScratchSizes(1024, 0);
flushTask(*commandStreamReceiver);
EXPECT_NE(nullptr, scratchController->scratchAllocation);
EXPECT_EQ(nullptr, scratchController->privateScratchAllocation);
auto scratchAllocation = scratchController->scratchAllocation;
EXPECT_TRUE(commandStreamReceiver->isMadeResident(scratchAllocation));
EXPECT_TRUE(commandStreamReceiver->isMadeNonResident(scratchAllocation));
commandStreamReceiver->madeResidentGfxAllocations.clear(); // this is only history - we can clean this
commandStreamReceiver->madeNonResidentGfxAllocations.clear();
commandStreamReceiver->setRequiredScratchSizes(0, 1024);
flushTask(*commandStreamReceiver); // 2nd flush
EXPECT_NE(nullptr, scratchController->scratchAllocation);
EXPECT_NE(nullptr, scratchController->privateScratchAllocation);
auto privateScratchAllocation = scratchController->privateScratchAllocation;
EXPECT_TRUE(commandStreamReceiver->isMadeResident(scratchAllocation));
EXPECT_TRUE(commandStreamReceiver->isMadeNonResident(scratchAllocation));
EXPECT_TRUE(commandStreamReceiver->isMadeResident(privateScratchAllocation));
EXPECT_TRUE(commandStreamReceiver->isMadeNonResident(privateScratchAllocation));
}
HWTEST_F(CommandStreamReceiverFlushTaskTests, whenPrivateScratchIsRequiredForFirstFlushAndCommonScratchForSecondFlushThenHandleResidencyProperly) {
auto commandStreamReceiver = new MockCsrHw<FamilyType>(*pDevice->executionEnvironment);
auto scratchController = new MockScratchController(*pDevice->executionEnvironment, *commandStreamReceiver->getInternalAllocationStorage());
commandStreamReceiver->scratchSpaceController.reset(scratchController);
pDevice->resetCommandStreamReceiver(commandStreamReceiver);
commandStreamReceiver->setRequiredScratchSizes(0, 1024);
flushTask(*commandStreamReceiver);
EXPECT_EQ(nullptr, scratchController->scratchAllocation);
EXPECT_NE(nullptr, scratchController->privateScratchAllocation);
auto privateScratchAllocation = scratchController->privateScratchAllocation;
EXPECT_TRUE(commandStreamReceiver->isMadeResident(privateScratchAllocation));
EXPECT_TRUE(commandStreamReceiver->isMadeNonResident(privateScratchAllocation));
commandStreamReceiver->madeResidentGfxAllocations.clear(); // this is only history - we can clean this
commandStreamReceiver->madeNonResidentGfxAllocations.clear();
commandStreamReceiver->setRequiredScratchSizes(1024, 0);
flushTask(*commandStreamReceiver); // 2nd flush
EXPECT_NE(nullptr, scratchController->scratchAllocation);
EXPECT_NE(nullptr, scratchController->privateScratchAllocation);
auto scratchAllocation = scratchController->scratchAllocation;
EXPECT_TRUE(commandStreamReceiver->isMadeResident(scratchAllocation));
EXPECT_TRUE(commandStreamReceiver->isMadeNonResident(scratchAllocation));
EXPECT_TRUE(commandStreamReceiver->isMadeResident(privateScratchAllocation));
EXPECT_TRUE(commandStreamReceiver->isMadeNonResident(privateScratchAllocation));
}
HWCMDTEST_F(IGFX_GEN8_CORE, CommandStreamReceiverFlushTaskTests, givenTwoConsecutiveNDRangeKernelsStateBaseAddressIsProgrammedOnceAndScratchAddressInMediaVFEStateIsProgrammedTwiceBothWithCorrectAddress) {
typedef typename FamilyType::PARSE PARSE;
typedef typename PARSE::MEDIA_VFE_STATE MEDIA_VFE_STATE;