feature: find cpu base address from all command buffers of container

Related-To: NEO-10381

Signed-off-by: Zbigniew Zdanowicz <zbigniew.zdanowicz@intel.com>
This commit is contained in:
Zbigniew Zdanowicz 2024-03-18 11:40:15 +00:00 committed by Compute-Runtime-Automation
parent 6b33d91140
commit d1041e2335
3 changed files with 63 additions and 0 deletions

View File

@ -591,4 +591,22 @@ size_t CommandContainer::getHeapSize(HeapType heapType) {
return HeapSize::getDefaultHeapSize(defaultHeapSize);
}
void *CommandContainer::findCpuBaseForCmdBufferAddress(void *cmdBufferAddress) {
uintptr_t cmdBufferAddressValue = reinterpret_cast<uintptr_t>(cmdBufferAddress);
uintptr_t cpuBaseValue = reinterpret_cast<uintptr_t>(commandStream->getCpuBase());
if ((cpuBaseValue <= cmdBufferAddressValue) &&
((cpuBaseValue + commandStream->getMaxAvailableSpace()) > cmdBufferAddressValue)) {
return reinterpret_cast<void *>(cpuBaseValue);
}
// last cmd buffer allocation is assisgned to commandStream, no need to check it
for (size_t i = 0; i < cmdBufferAllocations.size() - 1; i++) {
cpuBaseValue = reinterpret_cast<uintptr_t>(cmdBufferAllocations[i]->getUnderlyingBuffer());
if ((cpuBaseValue <= cmdBufferAddressValue) &&
((cpuBaseValue + getMaxUsableSpace()) > cmdBufferAddressValue)) {
return reinterpret_cast<void *>(cpuBaseValue);
}
}
return nullptr;
}
} // namespace NEO

View File

@ -202,6 +202,8 @@ class CommandContainer : public NonCopyableOrMovableClass {
}
void endAlignedPrimaryBuffer();
void *findCpuBaseForCmdBufferAddress(void *cmdBufferAddress);
protected:
size_t getAlignedCmdBufferSize() const;
size_t getMaxUsableSpace() const {

View File

@ -33,6 +33,7 @@ using CommandContainerTest = Test<CommandContainerFixture>;
class MyMockCommandContainer : public CommandContainer {
public:
using CommandContainer::allocationIndirectHeaps;
using CommandContainer::cmdBufferAllocations;
using CommandContainer::defaultSshSize;
using CommandContainer::dirtyHeaps;
using CommandContainer::getAlignedCmdBufferSize;
@ -1986,3 +1987,45 @@ TEST_F(CommandContainerTest, givenHeaplessCmdContainerWhenResetContainerThenNoHe
cmdContainer.reset();
EXPECT_EQ(0u, deallocationList.size());
}
TEST_F(CommandContainerTest, givenInitializedContainerWhenSearchedAddressIsWithinCommandStreamThenReturnCommandStreamCpuBase) {
MyMockCommandContainer cmdContainer;
auto status = cmdContainer.initialize(pDevice, nullptr, HeapSize::defaultHeapSize, false, false);
EXPECT_EQ(CommandContainer::ErrorCode::success, status);
void *cmdBuffer = ptrOffset(cmdContainer.getCommandStream()->getCpuBase(), 0x100);
void *cpuBase = cmdContainer.findCpuBaseForCmdBufferAddress(cmdBuffer);
EXPECT_EQ(cmdContainer.getCommandStream()->getCpuBase(), cpuBase);
}
TEST_F(CommandContainerTest, givenInitializedContainerWithTwoCommandBuffersWhenSearchedAddressIsWithinOldCommandBufferThenReturnOldCommandBufferCpuBase) {
MyMockCommandContainer cmdContainer;
auto status = cmdContainer.initialize(pDevice, nullptr, HeapSize::defaultHeapSize, false, false);
EXPECT_EQ(CommandContainer::ErrorCode::success, status);
void *expectedCpuBase = cmdContainer.getCommandStream()->getCpuBase();
void *cmdBuffer = ptrOffset(expectedCpuBase, 0x200);
cmdContainer.allocateNextCommandBuffer();
EXPECT_NE(expectedCpuBase, cmdContainer.getCommandStream()->getCpuBase());
void *cpuBase = cmdContainer.findCpuBaseForCmdBufferAddress(cmdBuffer);
EXPECT_EQ(expectedCpuBase, cpuBase);
}
TEST_F(CommandContainerTest, givenInitializedContainerWhenSearchedAddressIsOutsideCommandStreamThenReturnNullptr) {
MyMockCommandContainer cmdContainer;
auto status = cmdContainer.initialize(pDevice, nullptr, HeapSize::defaultHeapSize, false, false);
EXPECT_EQ(CommandContainer::ErrorCode::success, status);
cmdContainer.allocateNextCommandBuffer();
void *cmdBuffer = reinterpret_cast<void *>(0x1);
void *cpuBase = cmdContainer.findCpuBaseForCmdBufferAddress(cmdBuffer);
EXPECT_EQ(nullptr, cpuBase);
cmdBuffer = reinterpret_cast<void *>(std::numeric_limits<uintptr_t>::max());
cpuBase = cmdContainer.findCpuBaseForCmdBufferAddress(cmdBuffer);
EXPECT_EQ(nullptr, cpuBase);
}