mirror of
https://github.com/intel/compute-runtime.git
synced 2025-11-10 05:49:51 +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
@@ -191,7 +191,7 @@ TEST_F(DrmBufferObjectTest, givenResidentBOWhenPrintExecutionBufferIsSetToTrueTh
|
||||
|
||||
std::string output = testing::internal::GetCapturedStdout();
|
||||
auto idx = output.find("drm_i915_gem_execbuffer2 {");
|
||||
size_t expectedValue = 0;
|
||||
size_t expectedValue = 29;
|
||||
EXPECT_EQ(expectedValue, idx);
|
||||
|
||||
idx = output.find("Buffer Object = { handle: BO-");
|
||||
@@ -228,7 +228,7 @@ TEST_F(DrmBufferObjectTest, whenPrintExecutionBufferIsSetToTrueThenMessageFoundI
|
||||
|
||||
std::string output = testing::internal::GetCapturedStdout();
|
||||
auto idx = output.find("drm_i915_gem_execbuffer2 {");
|
||||
size_t expectedValue = 0;
|
||||
size_t expectedValue = 29;
|
||||
EXPECT_EQ(expectedValue, idx);
|
||||
}
|
||||
|
||||
|
||||
@@ -106,7 +106,8 @@ bool DirectSubmissionHw<GfxFamily, Dispatcher>::allocateResources() {
|
||||
template <typename GfxFamily, typename Dispatcher>
|
||||
bool DirectSubmissionHw<GfxFamily, Dispatcher>::makeResourcesResident(DirectSubmissionAllocations &allocations) {
|
||||
auto memoryInterface = this->device.getRootDeviceEnvironment().memoryOperationsInterface.get();
|
||||
auto ret = memoryInterface->makeResident(&device, ArrayRef<GraphicsAllocation *>(allocations)) == MemoryOperationsStatus::SUCCESS;
|
||||
|
||||
auto ret = memoryInterface->makeResidentWithinOsContext(&this->osContext, ArrayRef<GraphicsAllocation *>(allocations), false) == MemoryOperationsStatus::SUCCESS;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2020 Intel Corporation
|
||||
* Copyright (C) 2019-2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -14,6 +14,7 @@
|
||||
namespace NEO {
|
||||
class Device;
|
||||
class GraphicsAllocation;
|
||||
class OsContext;
|
||||
|
||||
class MemoryOperationsHandler {
|
||||
public:
|
||||
@@ -23,5 +24,8 @@ class MemoryOperationsHandler {
|
||||
virtual MemoryOperationsStatus makeResident(Device *device, ArrayRef<GraphicsAllocation *> gfxAllocations) = 0;
|
||||
virtual MemoryOperationsStatus evict(Device *device, GraphicsAllocation &gfxAllocation) = 0;
|
||||
virtual MemoryOperationsStatus isResident(Device *device, GraphicsAllocation &gfxAllocation) = 0;
|
||||
|
||||
virtual MemoryOperationsStatus makeResidentWithinOsContext(OsContext *osContext, ArrayRef<GraphicsAllocation *> gfxAllocations, bool evictable) = 0;
|
||||
virtual MemoryOperationsStatus evictWithinOsContext(OsContext *osContext, GraphicsAllocation &gfxAllocation) = 0;
|
||||
};
|
||||
} // namespace NEO
|
||||
|
||||
@@ -56,6 +56,14 @@ MemoryOperationsStatus AubMemoryOperationsHandler::evict(Device *device, Graphic
|
||||
}
|
||||
}
|
||||
|
||||
MemoryOperationsStatus AubMemoryOperationsHandler::makeResidentWithinOsContext(OsContext *osContext, ArrayRef<GraphicsAllocation *> gfxAllocations, bool evictable) {
|
||||
return makeResident(nullptr, gfxAllocations);
|
||||
}
|
||||
|
||||
MemoryOperationsStatus AubMemoryOperationsHandler::evictWithinOsContext(OsContext *osContext, GraphicsAllocation &gfxAllocation) {
|
||||
return evict(nullptr, gfxAllocation);
|
||||
}
|
||||
|
||||
MemoryOperationsStatus AubMemoryOperationsHandler::isResident(Device *device, GraphicsAllocation &gfxAllocation) {
|
||||
auto lock = acquireLock(resourcesLock);
|
||||
auto itor = std::find(residentAllocations.begin(), residentAllocations.end(), &gfxAllocation);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2020 Intel Corporation
|
||||
* Copyright (C) 2019-2021 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -24,6 +24,10 @@ class AubMemoryOperationsHandler : public MemoryOperationsHandler {
|
||||
MemoryOperationsStatus makeResident(Device *device, ArrayRef<GraphicsAllocation *> gfxAllocations) override;
|
||||
MemoryOperationsStatus evict(Device *device, GraphicsAllocation &gfxAllocation) override;
|
||||
MemoryOperationsStatus isResident(Device *device, GraphicsAllocation &gfxAllocation) override;
|
||||
|
||||
MemoryOperationsStatus makeResidentWithinOsContext(OsContext *osContext, ArrayRef<GraphicsAllocation *> gfxAllocations, bool evictable) override;
|
||||
MemoryOperationsStatus evictWithinOsContext(OsContext *osContext, GraphicsAllocation &gfxAllocation) override;
|
||||
|
||||
void setAubManager(aub_stream::AubManager *aubManager);
|
||||
|
||||
protected:
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "shared/source/os_interface/linux/drm_memory_manager.h"
|
||||
#include "shared/source/os_interface/linux/drm_memory_operations_handler.h"
|
||||
#include "shared/source/os_interface/linux/drm_neo.h"
|
||||
#include "shared/source/os_interface/linux/os_context_linux.h"
|
||||
#include "shared/source/os_interface/linux/os_time_linux.h"
|
||||
#include "shared/source/os_interface/os_context.h"
|
||||
#include "shared/source/utilities/stackvec.h"
|
||||
@@ -141,6 +142,9 @@ int BufferObject::exec(uint32_t used, size_t startOffset, unsigned int flags, bo
|
||||
execbuf.rsvd1 = drmContextId;
|
||||
|
||||
if (DebugManager.flags.PrintExecutionBuffer.get()) {
|
||||
PRINT_DEBUG_STRING(DebugManager.flags.PrintExecutionBuffer.get(), stdout, "Exec called with drmVmId = %u\n",
|
||||
static_cast<const OsContextLinux *>(osContext)->getDrmVmIds().size() ? static_cast<const OsContextLinux *>(osContext)->getDrmVmIds()[vmHandleId] : 0);
|
||||
|
||||
printExecutionBuffer(execbuf, residencyCount, execObjectsStorage, residency);
|
||||
}
|
||||
|
||||
@@ -171,7 +175,10 @@ int BufferObject::bind(OsContext *osContext, uint32_t vmHandleId) {
|
||||
if (!this->bindInfo[contextId][vmHandleId]) {
|
||||
retVal = this->drm->bindBufferObject(osContext, vmHandleId, this);
|
||||
auto err = this->drm->getErrno();
|
||||
PRINT_DEBUG_STRING(DebugManager.flags.PrintBOBindingResult.get(), stderr, "bind BO-%d to VM %u, range: %llx - %llx, size: %lld, result: %d, errno: %d(%s)\n", this->handle, vmHandleId, this->gpuAddress, ptrOffset(this->gpuAddress, this->size), this->size, retVal, err, strerror(err));
|
||||
|
||||
PRINT_DEBUG_STRING(DebugManager.flags.PrintBOBindingResult.get(), stderr, "bind BO-%d to VM %u, drmVmId = %u, range: %llx - %llx, size: %lld, result: %d, errno: %d(%s)\n",
|
||||
this->handle, vmHandleId, static_cast<const OsContextLinux *>(osContext)->getDrmVmIds().size() ? static_cast<const OsContextLinux *>(osContext)->getDrmVmIds()[vmHandleId] : 0, this->gpuAddress, ptrOffset(this->gpuAddress, this->size), this->size, retVal, err, strerror(err));
|
||||
|
||||
if (!retVal) {
|
||||
this->bindInfo[contextId][vmHandleId] = true;
|
||||
}
|
||||
@@ -185,7 +192,10 @@ int BufferObject::unbind(OsContext *osContext, uint32_t vmHandleId) {
|
||||
if (this->bindInfo[contextId][vmHandleId]) {
|
||||
retVal = this->drm->unbindBufferObject(osContext, vmHandleId, this);
|
||||
auto err = this->drm->getErrno();
|
||||
PRINT_DEBUG_STRING(DebugManager.flags.PrintBOBindingResult.get(), stderr, "unbind BO-%d from VM %u, range: %llx - %llx, size: %lld, result: %d, errno: %d(%s)\n", this->handle, vmHandleId, this->gpuAddress, ptrOffset(this->gpuAddress, this->size), this->size, retVal, err, strerror(err));
|
||||
|
||||
PRINT_DEBUG_STRING(DebugManager.flags.PrintBOBindingResult.get(), stderr, "unbind BO-%d from VM %u, drmVmId = %u, range: %llx - %llx, size: %lld, result: %d, errno: %d(%s)\n",
|
||||
this->handle, vmHandleId, static_cast<const OsContextLinux *>(osContext)->getDrmVmIds().size() ? static_cast<const OsContextLinux *>(osContext)->getDrmVmIds()[vmHandleId] : 0, this->gpuAddress, ptrOffset(this->gpuAddress, this->size), this->size, retVal, err, strerror(err));
|
||||
|
||||
if (!retVal) {
|
||||
this->bindInfo[contextId][vmHandleId] = false;
|
||||
}
|
||||
|
||||
@@ -20,8 +20,6 @@ class DrmMemoryOperationsHandler : public MemoryOperationsHandler {
|
||||
DrmMemoryOperationsHandler() = default;
|
||||
~DrmMemoryOperationsHandler() override = default;
|
||||
|
||||
virtual MemoryOperationsStatus makeResidentWithinOsContext(OsContext *osContext, ArrayRef<GraphicsAllocation *> gfxAllocations, bool evictable) = 0;
|
||||
virtual MemoryOperationsStatus evictWithinOsContext(OsContext *osContext, GraphicsAllocation &gfxAllocation) = 0;
|
||||
virtual void mergeWithResidencyContainer(OsContext *osContext, ResidencyContainer &residencyContainer) = 0;
|
||||
virtual std::unique_lock<std::mutex> lockHandlerIfUsed() = 0;
|
||||
|
||||
|
||||
@@ -24,6 +24,13 @@ class WddmMemoryOperationsHandler : public MemoryOperationsHandler {
|
||||
MemoryOperationsStatus evict(Device *device, GraphicsAllocation &gfxAllocation) override;
|
||||
MemoryOperationsStatus isResident(Device *device, GraphicsAllocation &gfxAllocation) override;
|
||||
|
||||
MemoryOperationsStatus makeResidentWithinOsContext(OsContext *osContext, ArrayRef<GraphicsAllocation *> gfxAllocations, bool evictable) override {
|
||||
return makeResident(nullptr, gfxAllocations);
|
||||
}
|
||||
MemoryOperationsStatus evictWithinOsContext(OsContext *osContext, GraphicsAllocation &gfxAllocation) override {
|
||||
return evict(nullptr, gfxAllocation);
|
||||
}
|
||||
|
||||
protected:
|
||||
Wddm *wddm;
|
||||
std::unique_ptr<WddmResidentAllocationsContainer> residentAllocations;
|
||||
|
||||
@@ -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