mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-10 07:08:04 +08:00
Fix DirectSubmission residency handling
- allocations should be resident within OsContext Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
e9f56e7d96
commit
f2eb7f3aea
@@ -9,7 +9,7 @@
|
||||
#include "shared/source/direct_submission/direct_submission_hw.h"
|
||||
#include "shared/source/direct_submission/direct_submission_hw_diagnostic_mode.h"
|
||||
#include "shared/source/memory_manager/graphics_allocation.h"
|
||||
|
||||
#include "shared/test/common/mocks/mock_memory_operations_handler.h"
|
||||
namespace NEO {
|
||||
|
||||
template <typename GfxFamily, typename Dispatcher>
|
||||
@@ -73,6 +73,9 @@ struct MockDirectSubmissionHw : public DirectSubmissionHw<GfxFamily, Dispatcher>
|
||||
}
|
||||
|
||||
bool makeResourcesResident(DirectSubmissionAllocations &allocations) override {
|
||||
if (callBaseResident) {
|
||||
return BaseClass::makeResourcesResident(allocations);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -122,5 +125,6 @@ struct MockDirectSubmissionHw : public DirectSubmissionHw<GfxFamily, Dispatcher>
|
||||
bool allocateOsResourcesReturn = true;
|
||||
bool submitReturn = true;
|
||||
bool handleResidencyReturn = true;
|
||||
bool callBaseResident = false;
|
||||
};
|
||||
} // namespace NEO
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#pragma once
|
||||
#include "shared/source/memory_manager/memory_operations_handler.h"
|
||||
#include "shared/source/os_interface/os_context.h"
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
@@ -20,6 +21,8 @@ class MockMemoryOperationsHandler : public MemoryOperationsHandler {
|
||||
MemoryOperationsStatus makeResident(Device *device, ArrayRef<GraphicsAllocation *> gfxAllocations) override { return MemoryOperationsStatus::UNSUPPORTED; }
|
||||
MemoryOperationsStatus evict(Device *device, GraphicsAllocation &gfxAllocation) override { return MemoryOperationsStatus::UNSUPPORTED; }
|
||||
MemoryOperationsStatus isResident(Device *device, GraphicsAllocation &gfxAllocation) override { return MemoryOperationsStatus::UNSUPPORTED; }
|
||||
MemoryOperationsStatus makeResidentWithinOsContext(OsContext *osContext, ArrayRef<GraphicsAllocation *> gfxAllocations, bool evictable) override { return MemoryOperationsStatus::UNSUPPORTED; }
|
||||
MemoryOperationsStatus evictWithinOsContext(OsContext *osContext, GraphicsAllocation &gfxAllocation) override { return MemoryOperationsStatus::UNSUPPORTED; }
|
||||
};
|
||||
|
||||
class MockMemoryOperationsHandlerTests : public MemoryOperationsHandler {
|
||||
@@ -31,6 +34,10 @@ class MockMemoryOperationsHandlerTests : public MemoryOperationsHandler {
|
||||
(Device * device, GraphicsAllocation &gfxAllocation), (override));
|
||||
MOCK_METHOD(MemoryOperationsStatus, isResident,
|
||||
(Device * device, GraphicsAllocation &gfxAllocation), (override));
|
||||
MOCK_METHOD(MemoryOperationsStatus, makeResidentWithinOsContext,
|
||||
(OsContext * osContext, ArrayRef<GraphicsAllocation *> gfxAllocations, bool evictable), (override));
|
||||
MOCK_METHOD(MemoryOperationsStatus, evictWithinOsContext,
|
||||
(OsContext * osContext, GraphicsAllocation &gfxAllocation), (override));
|
||||
};
|
||||
|
||||
class MockMemoryOperations : public MemoryOperationsHandler {
|
||||
@@ -49,8 +56,21 @@ class MockMemoryOperations : public MemoryOperationsHandler {
|
||||
return MemoryOperationsStatus::SUCCESS;
|
||||
}
|
||||
|
||||
MemoryOperationsStatus makeResidentWithinOsContext(OsContext *osContext, ArrayRef<GraphicsAllocation *> gfxAllocations, bool evictable) override {
|
||||
makeResidentCalledCount++;
|
||||
if (osContext) {
|
||||
makeResidentContextId = osContext->getContextId();
|
||||
}
|
||||
return MemoryOperationsStatus::SUCCESS;
|
||||
}
|
||||
MemoryOperationsStatus evictWithinOsContext(OsContext *osContext, GraphicsAllocation &gfxAllocation) override {
|
||||
evictCalledCount++;
|
||||
return MemoryOperationsStatus::SUCCESS;
|
||||
}
|
||||
|
||||
int makeResidentCalledCount = 0;
|
||||
int evictCalledCount = 0;
|
||||
uint32_t makeResidentContextId = std::numeric_limits<uint32_t>::max();
|
||||
};
|
||||
|
||||
} // namespace NEO
|
||||
|
||||
@@ -94,6 +94,41 @@ HWTEST_F(DirectSubmissionTest, givenBlitterDirectSubmissionWhenStopThenRingIsNot
|
||||
csr.blitterDirectSubmission.release();
|
||||
}
|
||||
|
||||
HWTEST_F(DirectSubmissionTest, givenDirectSubmissionWhenMakingResourcesResidentThenCorrectContextIsUsed) {
|
||||
|
||||
auto &csr = pDevice->getUltCommandStreamReceiver<FamilyType>();
|
||||
|
||||
auto mockMemoryOperations = std::make_unique<MockMemoryOperations>();
|
||||
|
||||
pDevice->getRootDeviceEnvironmentRef().memoryOperationsInterface.reset(mockMemoryOperations.get());
|
||||
|
||||
std::unique_ptr<OsContext> osContext2(OsContext::create(pDevice->getExecutionEnvironment()->rootDeviceEnvironments[0]->osInterface.get(), 2,
|
||||
EngineDescriptorHelper::getDefaultDescriptor({aub_stream::ENGINE_RCS, EngineUsage::Regular},
|
||||
PreemptionMode::ThreadGroup, pDevice->getDeviceBitfield())));
|
||||
|
||||
MockDirectSubmissionHw<FamilyType, RenderDispatcher<FamilyType>> directSubmission(*pDevice, *osContext2.get());
|
||||
|
||||
csr.directSubmission.reset(&directSubmission);
|
||||
csr.setupContext(*osContext2.get());
|
||||
|
||||
bool ret = directSubmission.initialize(true);
|
||||
EXPECT_TRUE(ret);
|
||||
EXPECT_NE(0x0u, directSubmission.ringCommandStream.getUsed());
|
||||
GraphicsAllocation *alloc = directSubmission.ringCommandStream.getGraphicsAllocation();
|
||||
|
||||
directSubmission.callBaseResident = true;
|
||||
|
||||
DirectSubmissionAllocations allocs;
|
||||
allocs.push_back(alloc);
|
||||
|
||||
directSubmission.makeResourcesResident(allocs);
|
||||
|
||||
EXPECT_EQ(2u, mockMemoryOperations->makeResidentContextId);
|
||||
|
||||
pDevice->getRootDeviceEnvironmentRef().memoryOperationsInterface.release();
|
||||
csr.directSubmission.release();
|
||||
}
|
||||
|
||||
HWTEST_F(DirectSubmissionTest, givenDirectSubmissionInitializedWhenRingIsStartedThenExpectAllocationsCreatedAndCommandsDispatched) {
|
||||
MockDirectSubmissionHw<FamilyType, RenderDispatcher<FamilyType>> directSubmission(*pDevice,
|
||||
*osContext.get());
|
||||
|
||||
Reference in New Issue
Block a user