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:
parent
6b33d91140
commit
d1041e2335
|
@ -591,4 +591,22 @@ size_t CommandContainer::getHeapSize(HeapType heapType) {
|
||||||
return HeapSize::getDefaultHeapSize(defaultHeapSize);
|
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
|
} // namespace NEO
|
||||||
|
|
|
@ -202,6 +202,8 @@ class CommandContainer : public NonCopyableOrMovableClass {
|
||||||
}
|
}
|
||||||
void endAlignedPrimaryBuffer();
|
void endAlignedPrimaryBuffer();
|
||||||
|
|
||||||
|
void *findCpuBaseForCmdBufferAddress(void *cmdBufferAddress);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
size_t getAlignedCmdBufferSize() const;
|
size_t getAlignedCmdBufferSize() const;
|
||||||
size_t getMaxUsableSpace() const {
|
size_t getMaxUsableSpace() const {
|
||||||
|
|
|
@ -33,6 +33,7 @@ using CommandContainerTest = Test<CommandContainerFixture>;
|
||||||
class MyMockCommandContainer : public CommandContainer {
|
class MyMockCommandContainer : public CommandContainer {
|
||||||
public:
|
public:
|
||||||
using CommandContainer::allocationIndirectHeaps;
|
using CommandContainer::allocationIndirectHeaps;
|
||||||
|
using CommandContainer::cmdBufferAllocations;
|
||||||
using CommandContainer::defaultSshSize;
|
using CommandContainer::defaultSshSize;
|
||||||
using CommandContainer::dirtyHeaps;
|
using CommandContainer::dirtyHeaps;
|
||||||
using CommandContainer::getAlignedCmdBufferSize;
|
using CommandContainer::getAlignedCmdBufferSize;
|
||||||
|
@ -1986,3 +1987,45 @@ TEST_F(CommandContainerTest, givenHeaplessCmdContainerWhenResetContainerThenNoHe
|
||||||
cmdContainer.reset();
|
cmdContainer.reset();
|
||||||
EXPECT_EQ(0u, deallocationList.size());
|
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);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue