Fix dependency resolve in level zero black box tests

Signed-off-by: Zbigniew Zdanowicz <zbigniew.zdanowicz@intel.com>
This commit is contained in:
Zbigniew Zdanowicz
2023-02-20 12:51:01 +00:00
committed by Compute-Runtime-Automation
parent ac5d719e25
commit b4544f6f78
10 changed files with 105 additions and 31 deletions

View File

@@ -97,8 +97,9 @@ ze_result_t EventPool::initialize(DriverHandle *driver, Context *context, uint32
this->isHostVisibleEventPoolAllocation = !(isEventPoolDeviceAllocationFlagSet()); this->isHostVisibleEventPoolAllocation = !(isEventPoolDeviceAllocationFlagSet());
auto neoDevice = devices[0]->getNEODevice();
if (this->isDeviceEventPoolAllocation) { if (this->isDeviceEventPoolAllocation) {
NEO::AllocationProperties allocationProperties{*rootDeviceIndices.begin(), this->eventPoolSize, allocationType, devices[0]->getNEODevice()->getDeviceBitfield()}; NEO::AllocationProperties allocationProperties{*rootDeviceIndices.begin(), this->eventPoolSize, allocationType, neoDevice->getDeviceBitfield()};
allocationProperties.alignment = eventAlignment; allocationProperties.alignment = eventAlignment;
auto memoryManager = driver->getMemoryManager(); auto memoryManager = driver->getMemoryManager();
@@ -111,7 +112,6 @@ ze_result_t EventPool::initialize(DriverHandle *driver, Context *context, uint32
this->isShareableEventMemory = (graphicsAllocation->peekInternalHandle(memoryManager, handle) == 0); this->isShareableEventMemory = (graphicsAllocation->peekInternalHandle(memoryManager, handle) == 0);
} }
} }
} else { } else {
NEO::AllocationProperties allocationProperties{*rootDeviceIndices.begin(), this->eventPoolSize, allocationType, systemMemoryBitfield}; NEO::AllocationProperties allocationProperties{*rootDeviceIndices.begin(), this->eventPoolSize, allocationType, systemMemoryBitfield};
allocationProperties.alignment = eventAlignment; allocationProperties.alignment = eventAlignment;
@@ -119,17 +119,18 @@ ze_result_t EventPool::initialize(DriverHandle *driver, Context *context, uint32
eventPoolPtr = driver->getMemoryManager()->createMultiGraphicsAllocationInSystemMemoryPool(rootDeviceIndices, eventPoolPtr = driver->getMemoryManager()->createMultiGraphicsAllocationInSystemMemoryPool(rootDeviceIndices,
allocationProperties, allocationProperties,
*eventPoolAllocations); *eventPoolAllocations);
if (eventPoolFlags & ZE_EVENT_POOL_FLAG_IPC) { if (eventPoolFlags & ZE_EVENT_POOL_FLAG_IPC) {
this->isShareableEventMemory = eventPoolAllocations->getDefaultGraphicsAllocation()->isShareableHostMemory; this->isShareableEventMemory = eventPoolAllocations->getDefaultGraphicsAllocation()->isShareableHostMemory;
} }
allocatedMemory = (nullptr != eventPoolPtr); allocatedMemory = (nullptr != eventPoolPtr);
} }
if (!allocatedMemory) { if (!allocatedMemory) {
return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY; return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY;
} }
if (neoDevice->getDefaultEngine().commandStreamReceiver->isTbxMode()) {
eventPoolAllocations->getDefaultGraphicsAllocation()->setWriteMemoryOnly(true);
}
return ZE_RESULT_SUCCESS; return ZE_RESULT_SUCCESS;
} }
@@ -289,6 +290,10 @@ ze_result_t EventPool::openEventPoolIpcHandle(const ze_ipc_event_pool_handle_t &
return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY; return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY;
} }
if (neoDevice->getDefaultEngine().commandStreamReceiver->isTbxMode()) {
alloc->setWriteMemoryOnly(true);
}
eventPool->context = context; eventPool->context = context;
eventPool->eventPoolAllocations = eventPool->eventPoolAllocations =
std::make_unique<NEO::MultiGraphicsAllocation>(static_cast<uint32_t>(context->rootDeviceIndices.size())); std::make_unique<NEO::MultiGraphicsAllocation>(static_cast<uint32_t>(context->rootDeviceIndices.size()));

View File

@@ -240,16 +240,6 @@ template <typename TagSizeT>
ze_result_t EventImp<TagSizeT>::hostEventSetValue(TagSizeT eventVal) { ze_result_t EventImp<TagSizeT>::hostEventSetValue(TagSizeT eventVal) {
UNRECOVERABLE_IF(hostAddress == nullptr); UNRECOVERABLE_IF(hostAddress == nullptr);
if (this->downloadAllocationRequired) {
auto eventAllocation = &this->getAllocation(device);
auto memoryIface = this->device->getNEODevice()->getRootDeviceEnvironment().memoryOperationsInterface.get();
if (NEO::MemoryOperationsStatus::SUCCESS != memoryIface->isResident(nullptr, *eventAllocation)) {
ArrayRef<NEO::GraphicsAllocation *> allocationArray(&eventAllocation, 1);
memoryIface->makeResident(nullptr, allocationArray);
}
}
if (isEventTimestampFlagSet()) { if (isEventTimestampFlagSet()) {
return hostEventSetValueTimestamps(eventVal); return hostEventSetValueTimestamps(eventVal);
} }
@@ -271,6 +261,16 @@ ze_result_t EventImp<TagSizeT>::hostEventSetValue(TagSizeT eventVal) {
setRemainingPackets(eventVal, packetHostAddr, packets); setRemainingPackets(eventVal, packetHostAddr, packets);
} }
if (this->downloadAllocationRequired) {
auto memoryIface = this->device->getNEODevice()->getRootDeviceEnvironment().memoryOperationsInterface.get();
auto eventAllocation = &this->getAllocation(device);
ArrayRef<NEO::GraphicsAllocation *> allocationArray(&eventAllocation, 1);
memoryIface->makeResident(nullptr, allocationArray);
constexpr uint32_t allBanks = std::numeric_limits<uint32_t>::max();
eventAllocation->setTbxWritable(true, allBanks);
}
return ZE_RESULT_SUCCESS; return ZE_RESULT_SUCCESS;
} }

View File

@@ -69,7 +69,9 @@ void testAppendMemoryCopy(ze_context_handle_t &context, ze_device_handle_t &devi
useSyncCmdQ ? nullptr : event, 0, nullptr)); useSyncCmdQ ? nullptr : event, 0, nullptr));
// Copy from device-allocated memory to stack // Copy from device-allocated memory to stack
SUCCESS_OR_TERMINATE(zeCommandListAppendMemoryCopy(cmdList, stackBuffer, zeBuffer, allocSize, SUCCESS_OR_TERMINATE(zeCommandListAppendMemoryCopy(cmdList, stackBuffer, zeBuffer, allocSize,
useSyncCmdQ ? nullptr : event2, 0, nullptr)); useSyncCmdQ ? nullptr : event2,
useSyncCmdQ ? 0 : 1,
useSyncCmdQ ? nullptr : &event));
if (!useSyncCmdQ) { if (!useSyncCmdQ) {
// If Async mode, use event for syncing copies // If Async mode, use event for syncing copies

View File

@@ -64,6 +64,7 @@ void testAppendMemoryCopy(ze_context_handle_t &context, ze_device_handle_t &devi
// Copy from heap to device-allocated memory // Copy from heap to device-allocated memory
SUCCESS_OR_TERMINATE(zeCommandListAppendMemoryCopy(cmdList, zeBuffer, heapBuffer, allocSize, SUCCESS_OR_TERMINATE(zeCommandListAppendMemoryCopy(cmdList, zeBuffer, heapBuffer, allocSize,
nullptr, 0, nullptr)); nullptr, 0, nullptr));
SUCCESS_OR_TERMINATE(zeCommandListAppendBarrier(cmdList, nullptr, 0, nullptr));
// Copy from device-allocated memory to stack // Copy from device-allocated memory to stack
SUCCESS_OR_TERMINATE(zeCommandListAppendMemoryCopy(cmdList, stackBuffer, zeBuffer, allocSize, SUCCESS_OR_TERMINATE(zeCommandListAppendMemoryCopy(cmdList, stackBuffer, zeBuffer, allocSize,
nullptr, 0, nullptr)); nullptr, 0, nullptr));

View File

@@ -2771,24 +2771,38 @@ HWTEST_F(EventTests, GivenCsrTbxModeWhenEventCreatedAndSignaledThenEventAllocati
auto &ultCsr = neoDevice->getUltCommandStreamReceiver<FamilyType>(); auto &ultCsr = neoDevice->getUltCommandStreamReceiver<FamilyType>();
ultCsr.commandStreamReceiverType = CommandStreamReceiverType::CSR_TBX; ultCsr.commandStreamReceiverType = CommandStreamReceiverType::CSR_TBX;
ze_result_t result = ZE_RESULT_SUCCESS;
eventPool = std::unique_ptr<L0::EventPool>(L0::EventPool::create(driverHandle.get(), context, 0, nullptr, &eventPoolDesc, result));
auto event = whiteboxCast(getHelper<L0GfxCoreHelper>().createEvent(eventPool.get(), &eventDesc, device)); auto event = whiteboxCast(getHelper<L0GfxCoreHelper>().createEvent(eventPool.get(), &eventDesc, device));
auto eventAllocation = &event->getAllocation(device);
EXPECT_TRUE(eventAllocation->getAubInfo().writeMemoryOnly);
auto eventAllocItor = std::find(mockMemIface->gfxAllocationsForMakeResident.begin(), auto eventAllocItor = std::find(mockMemIface->gfxAllocationsForMakeResident.begin(),
mockMemIface->gfxAllocationsForMakeResident.end(), mockMemIface->gfxAllocationsForMakeResident.end(),
&event->getAllocation(device)); eventAllocation);
EXPECT_NE(mockMemIface->gfxAllocationsForMakeResident.end(), eventAllocItor); EXPECT_EQ(mockMemIface->gfxAllocationsForMakeResident.end(), eventAllocItor);
EXPECT_EQ(1u, mockMemIface->isResidentCalledCount);
EXPECT_EQ(1, mockMemIface->makeResidentCalledCount); EXPECT_EQ(1, mockMemIface->makeResidentCalledCount);
constexpr uint32_t expectedBanks = std::numeric_limits<uint32_t>::max();
eventAllocation->setTbxWritable(false, expectedBanks);
auto status = event->hostSignal(); auto status = event->hostSignal();
EXPECT_EQ(ZE_RESULT_SUCCESS, status); EXPECT_EQ(ZE_RESULT_SUCCESS, status);
EXPECT_EQ(2, mockMemIface->makeResidentCalledCount);
EXPECT_EQ(2u, mockMemIface->isResidentCalledCount); EXPECT_TRUE(eventAllocation->isTbxWritable(expectedBanks));
EXPECT_EQ(1, mockMemIface->makeResidentCalledCount);
std::bitset<32> singleBitMask;
for (uint32_t i = 0; i < 32; i++) {
singleBitMask.reset();
singleBitMask.set(i, true);
uint32_t bit = static_cast<uint32_t>(singleBitMask.to_ulong());
EXPECT_TRUE(eventAllocation->isTbxWritable(bit));
}
event->reset(); event->reset();
EXPECT_EQ(3u, mockMemIface->isResidentCalledCount); EXPECT_EQ(3, mockMemIface->makeResidentCalledCount);
EXPECT_EQ(1, mockMemIface->makeResidentCalledCount);
size_t offset = event->getCompletionFieldOffset(); size_t offset = event->getCompletionFieldOffset();
void *completionAddress = ptrOffset(event->hostAddress, offset); void *completionAddress = ptrOffset(event->hostAddress, offset);

View File

@@ -42,6 +42,7 @@ struct AubInfo {
bool allocDumpable = false; bool allocDumpable = false;
bool bcsDumpOnly = false; bool bcsDumpOnly = false;
bool memObjectsAllocationWithWritableFlags = false; bool memObjectsAllocationWithWritableFlags = false;
bool writeMemoryOnly = false;
}; };
class GraphicsAllocation : public IDNode<GraphicsAllocation> { class GraphicsAllocation : public IDNode<GraphicsAllocation> {
@@ -129,6 +130,9 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation> {
aubInfo.allocDumpable = dumpable; aubInfo.allocDumpable = dumpable;
aubInfo.bcsDumpOnly = bcsDumpOnly; aubInfo.bcsDumpOnly = bcsDumpOnly;
} }
void setWriteMemoryOnly(bool writeMemoryOnly) {
aubInfo.writeMemoryOnly = writeMemoryOnly;
}
bool isAllocDumpable() const { return aubInfo.allocDumpable; } bool isAllocDumpable() const { return aubInfo.allocDumpable; }
bool isMemObjectsAllocationWithWritableFlags() const { return aubInfo.memObjectsAllocationWithWritableFlags; } bool isMemObjectsAllocationWithWritableFlags() const { return aubInfo.memObjectsAllocationWithWritableFlags; }
void setMemObjectsAllocationWithWritableFlags(bool newValue) { aubInfo.memObjectsAllocationWithWritableFlags = newValue; } void setMemObjectsAllocationWithWritableFlags(bool newValue) { aubInfo.memObjectsAllocationWithWritableFlags = newValue; }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2019-2022 Intel Corporation * Copyright (C) 2019-2023 Intel Corporation
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
* *
@@ -44,7 +44,9 @@ MemoryOperationsStatus AubMemoryOperationsHandler::makeResident(Device *device,
} }
aubManager->writeMemory2(params); aubManager->writeMemory2(params);
residentAllocations.push_back(allocation); if (!allocation->getAubInfo().writeMemoryOnly) {
residentAllocations.push_back(allocation);
}
} }
return MemoryOperationsStatus::SUCCESS; return MemoryOperationsStatus::SUCCESS;
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2019-2022 Intel Corporation * Copyright (C) 2019-2023 Intel Corporation
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
* *
@@ -44,7 +44,9 @@ class MockMemoryOperations : public MemoryOperationsHandler {
makeResidentCalledCount++; makeResidentCalledCount++;
if (captureGfxAllocationsForMakeResident) { if (captureGfxAllocationsForMakeResident) {
for (auto &gfxAllocation : gfxAllocations) { for (auto &gfxAllocation : gfxAllocations) {
gfxAllocationsForMakeResident.push_back(gfxAllocation); if (!gfxAllocation->getAubInfo().writeMemoryOnly) {
gfxAllocationsForMakeResident.push_back(gfxAllocation);
}
} }
} }
return MemoryOperationsStatus::SUCCESS; return MemoryOperationsStatus::SUCCESS;

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2019-2022 Intel Corporation * Copyright (C) 2019-2023 Intel Corporation
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
* *
@@ -25,6 +25,45 @@ TEST_F(AubMemoryOperationsHandlerTests, givenAubManagerWhenMakeResidentCalledThe
auto result = memoryOperationsInterface->makeResident(nullptr, ArrayRef<GraphicsAllocation *>(&allocPtr, 1)); auto result = memoryOperationsInterface->makeResident(nullptr, ArrayRef<GraphicsAllocation *>(&allocPtr, 1));
EXPECT_EQ(result, MemoryOperationsStatus::SUCCESS); EXPECT_EQ(result, MemoryOperationsStatus::SUCCESS);
EXPECT_TRUE(aubManager.writeMemory2Called); EXPECT_TRUE(aubManager.writeMemory2Called);
auto itor = std::find(memoryOperationsInterface->residentAllocations.begin(), memoryOperationsInterface->residentAllocations.end(), allocPtr);
EXPECT_NE(memoryOperationsInterface->residentAllocations.end(), itor);
EXPECT_EQ(1u, memoryOperationsInterface->residentAllocations.size());
aubManager.writeMemory2Called = false;
result = memoryOperationsInterface->makeResident(nullptr, ArrayRef<GraphicsAllocation *>(&allocPtr, 1));
EXPECT_EQ(result, MemoryOperationsStatus::SUCCESS);
EXPECT_TRUE(aubManager.writeMemory2Called);
itor = std::find(memoryOperationsInterface->residentAllocations.begin(), memoryOperationsInterface->residentAllocations.end(), allocPtr);
EXPECT_NE(memoryOperationsInterface->residentAllocations.end(), itor);
EXPECT_EQ(2u, memoryOperationsInterface->residentAllocations.size());
}
TEST_F(AubMemoryOperationsHandlerTests, givenAubManagerWhenMakeResidentCalledOnWriteOnlyAllocationThenTrueReturnedAndWriteCalled) {
MockAubManager aubManager;
getMemoryOperationsHandler()->setAubManager(&aubManager);
auto memoryOperationsInterface = getMemoryOperationsHandler();
allocPtr->setWriteMemoryOnly(true);
auto result = memoryOperationsInterface->makeResident(nullptr, ArrayRef<GraphicsAllocation *>(&allocPtr, 1));
EXPECT_EQ(result, MemoryOperationsStatus::SUCCESS);
EXPECT_TRUE(aubManager.writeMemory2Called);
auto itor = std::find(memoryOperationsInterface->residentAllocations.begin(), memoryOperationsInterface->residentAllocations.end(), allocPtr);
EXPECT_EQ(memoryOperationsInterface->residentAllocations.end(), itor);
EXPECT_EQ(0u, memoryOperationsInterface->residentAllocations.size());
aubManager.writeMemory2Called = false;
result = memoryOperationsInterface->makeResident(nullptr, ArrayRef<GraphicsAllocation *>(&allocPtr, 1));
EXPECT_EQ(result, MemoryOperationsStatus::SUCCESS);
EXPECT_TRUE(aubManager.writeMemory2Called);
itor = std::find(memoryOperationsInterface->residentAllocations.begin(), memoryOperationsInterface->residentAllocations.end(), allocPtr);
EXPECT_EQ(memoryOperationsInterface->residentAllocations.end(), itor);
EXPECT_EQ(0u, memoryOperationsInterface->residentAllocations.size());
} }
TEST_F(AubMemoryOperationsHandlerTests, givenAubManagerWhenMakeResidentCalledOnCompressedAllocationThenPassCorrectParams) { TEST_F(AubMemoryOperationsHandlerTests, givenAubManagerWhenMakeResidentCalledOnCompressedAllocationThenPassCorrectParams) {

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2019-2021 Intel Corporation * Copyright (C) 2019-2023 Intel Corporation
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
* *
@@ -17,21 +17,26 @@
using namespace NEO; using namespace NEO;
struct MockAubMemoryOperationsHandler : public AubMemoryOperationsHandler {
using AubMemoryOperationsHandler::AubMemoryOperationsHandler;
using AubMemoryOperationsHandler::residentAllocations;
};
class AubMemoryOperationsHandlerTests : public ::testing::Test { class AubMemoryOperationsHandlerTests : public ::testing::Test {
public: public:
void SetUp() override { void SetUp() override {
DebugManager.flags.SetCommandStreamReceiver.set(2); DebugManager.flags.SetCommandStreamReceiver.set(2);
residencyHandler = std::unique_ptr<AubMemoryOperationsHandler>(new AubMemoryOperationsHandler(nullptr)); residencyHandler = std::unique_ptr<MockAubMemoryOperationsHandler>(new MockAubMemoryOperationsHandler(nullptr));
allocPtr = &allocation; allocPtr = &allocation;
} }
AubMemoryOperationsHandler *getMemoryOperationsHandler() { MockAubMemoryOperationsHandler *getMemoryOperationsHandler() {
return residencyHandler.get(); return residencyHandler.get();
} }
MockGraphicsAllocation allocation; MockGraphicsAllocation allocation;
GraphicsAllocation *allocPtr; GraphicsAllocation *allocPtr;
DebugManagerStateRestore dbgRestore; DebugManagerStateRestore dbgRestore;
std::unique_ptr<AubMemoryOperationsHandler> residencyHandler; std::unique_ptr<MockAubMemoryOperationsHandler> residencyHandler;
}; };