fix: Disable async release of buffers with external host ptr

Related-To: NEO-10036

Signed-off-by: Lukasz Jobczyk <lukasz.jobczyk@intel.com>
This commit is contained in:
Lukasz Jobczyk
2024-03-27 10:32:50 +00:00
committed by Compute-Runtime-Automation
parent b722f3b579
commit 436579ca8c
2 changed files with 49 additions and 3 deletions

View File

@@ -82,7 +82,8 @@ MemObj::~MemObj() {
needWait |= multiGraphicsAllocation.getGraphicsAllocations().size() > 1u;
for (auto graphicsAllocation : multiGraphicsAllocation.getGraphicsAllocations()) {
auto rootDeviceIndex = graphicsAllocation ? graphicsAllocation->getRootDeviceIndex() : 0;
bool doAsyncDestructions = debugManager.flags.EnableAsyncDestroyAllocations.get();
bool doAsyncDestructions = debugManager.flags.EnableAsyncDestroyAllocations.get() && !this->memoryProperties.flags.useHostPtr;
if (graphicsAllocation && !associatedMemObject && !isHostPtrSVM && graphicsAllocation->peekReuseCount() == 0) {
memoryManager->removeAllocationFromHostPtrManager(graphicsAllocation);
if (!doAsyncDestructions) {

View File

@@ -55,7 +55,7 @@ class MyCsr : public UltCommandStreamReceiver<Family> {
void CL_CALLBACK emptyDestructorCallback(cl_mem memObj, void *userData) {
}
template <bool useMultiGraphicsAllocation = false>
template <bool useMultiGraphicsAllocation = false, bool useHostPtr = false>
class MemObjDestructionTest : public ::testing::TestWithParam<bool> {
public:
void SetUp() override {
@@ -65,7 +65,12 @@ class MemObjDestructionTest : public ::testing::TestWithParam<bool> {
device = std::make_unique<MockClDevice>(MockDevice::create<MockDevice>(executionEnvironment, 0));
context.reset(new MockContext(device.get()));
allocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{device->getRootDeviceIndex(), size});
if constexpr (useMultiGraphicsAllocation) {
if constexpr (useHostPtr) {
memObj = new MemObj(context.get(), CL_MEM_OBJECT_BUFFER,
ClMemoryPropertiesHelper::createMemoryProperties(CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR, 0, 0, &device->getDevice()),
CL_MEM_READ_WRITE, 0, size,
nullptr, nullptr, GraphicsAllocationHelper::toMultiGraphicsAllocation(allocation), true, false, false);
} else if constexpr (useMultiGraphicsAllocation) {
MultiGraphicsAllocation multiAllocation(1u);
multiAllocation.addAllocation(allocation);
memObj = new MemObj(context.get(), CL_MEM_OBJECT_BUFFER,
@@ -137,6 +142,18 @@ class MemObjMulitAllocationAsyncDestructionTest : public MemObjDestructionTest<t
DebugManagerStateRestore restorer;
};
class MemObjUseHostPtrAsyncDestructionTest : public MemObjDestructionTest<false, true> {
public:
void SetUp() override {
debugManager.flags.EnableAsyncDestroyAllocations.set(true);
MemObjDestructionTest::SetUp();
}
void TearDown() override {
MemObjDestructionTest::TearDown();
}
DebugManagerStateRestore restorer;
};
class MemObjSyncDestructionTest : public MemObjDestructionTest<> {
public:
void SetUp() override {
@@ -199,6 +216,34 @@ HWTEST_F(MemObjMulitAllocationAsyncDestructionTest, givenUsedMemObjWithAsyncDest
EXPECT_EQ(expectedTaskCount1, mockCsr1->waitForCompletionWithTimeoutParamsPassed[0].taskCountToWait);
}
HWTEST_F(MemObjUseHostPtrAsyncDestructionTest, givenUsedMemObjWithAsyncDestructionsEnabledThatUsesExternalHostPtrWhenItIsDestroyedThenDestructorWaitsOnTaskCount) {
auto rootDeviceIndex = device->getRootDeviceIndex();
auto mockCsr0 = new MyCsr<FamilyType>(*device->executionEnvironment, device->getDeviceBitfield());
auto mockCsr1 = new MyCsr<FamilyType>(*device->executionEnvironment, device->getDeviceBitfield());
device->resetCommandStreamReceiver(mockCsr0, 0);
device->resetCommandStreamReceiver(mockCsr1, 1);
*mockCsr0->getTagAddress() = 0;
*mockCsr1->getTagAddress() = 0;
mockCsr0->getTagAddressValue = taskCountReady;
mockCsr1->getTagAddressValue = taskCountReady;
auto osContextId0 = mockCsr0->getOsContext().getContextId();
auto osContextId1 = mockCsr1->getOsContext().getContextId();
memObj->getGraphicsAllocation(rootDeviceIndex)->updateTaskCount(taskCountReady, osContextId0);
memObj->getGraphicsAllocation(rootDeviceIndex)->updateTaskCount(taskCountReady, osContextId1);
auto expectedTaskCount0 = allocation->getTaskCount(osContextId0);
auto expectedTaskCount1 = allocation->getTaskCount(osContextId1);
delete memObj;
EXPECT_EQ(1u, mockCsr0->waitForCompletionWithTimeoutCalled);
EXPECT_EQ(TimeoutControls::maxTimeout, mockCsr0->waitForCompletionWithTimeoutParamsPassed[0].timeoutMs);
EXPECT_EQ(expectedTaskCount0, mockCsr0->waitForCompletionWithTimeoutParamsPassed[0].taskCountToWait);
EXPECT_EQ(1u, mockCsr1->waitForCompletionWithTimeoutCalled);
EXPECT_EQ(TimeoutControls::maxTimeout, mockCsr1->waitForCompletionWithTimeoutParamsPassed[0].timeoutMs);
EXPECT_EQ(expectedTaskCount1, mockCsr1->waitForCompletionWithTimeoutParamsPassed[0].taskCountToWait);
}
HWTEST_P(MemObjAsyncDestructionTest, givenUsedMemObjWithAsyncDestructionsEnabledThatHasDestructorCallbacksWhenItIsDestroyedThenDestructorWaitsOnTaskCount) {
bool hasCallbacks = GetParam();