Extend LinearStream with gpuBase

- added methods to set and query gpu base address

Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
This commit is contained in:
Mateusz Hoppe
2022-03-29 14:11:50 +00:00
committed by Compute-Runtime-Automation
parent 68351249d1
commit 681c09d314
4 changed files with 37 additions and 0 deletions

View File

@@ -275,6 +275,7 @@ ze_result_t CommandQueueHw<gfxCoreFamily>::executeCommandLists(
size_t padding = alignedSize - linearStreamSizeEstimate;
reserveLinearStreamSize(alignedSize);
NEO::LinearStream child(commandStream->getSpace(alignedSize), alignedSize);
child.setGpuBase(ptrOffset(commandStream->getGpuBase(), commandStream->getUsed()));
const auto globalFenceAllocation = csr->getGlobalFenceAllocation();
if (globalFenceAllocation) {

View File

@@ -39,4 +39,12 @@ LinearStream::LinearStream(void *buffer, size_t bufferSize, CommandContainer *cm
this->cmdContainer = cmdContainer;
this->batchBufferEndSize = batchBufferEndSize;
}
uint64_t LinearStream::getGpuBase() const {
if (graphicsAllocation) {
return graphicsAllocation->getGpuAddress();
}
return gpuBase;
}
} // namespace NEO

View File

@@ -32,6 +32,10 @@ class LinearStream {
size_t getMaxAvailableSpace() const;
size_t getAvailableSpace() const;
size_t getUsed() const;
uint64_t getGpuBase() const;
void setGpuBase(uint64_t);
void overrideMaxSize(size_t newMaxSize);
void replaceBuffer(void *buffer, size_t bufferSize);
GraphicsAllocation *getGraphicsAllocation() const;
@@ -50,12 +54,17 @@ class LinearStream {
GraphicsAllocation *graphicsAllocation;
CommandContainer *cmdContainer = nullptr;
size_t batchBufferEndSize = 0;
uint64_t gpuBase = 0;
};
inline void *LinearStream::getCpuBase() const {
return buffer;
}
inline void LinearStream::setGpuBase(uint64_t gpuAddress) {
gpuBase = gpuAddress;
}
inline void *LinearStream::getSpace(size_t size) {
if (cmdContainer != nullptr && getAvailableSpace() < batchBufferEndSize + size) {
UNRECOVERABLE_IF(sizeUsed + batchBufferEndSize > maxAvailableSpace);

View File

@@ -29,6 +29,25 @@ TEST(LinearStreamCtorTest, whenProvidedAllArgumentsThenExpectSameValuesSet) {
EXPECT_EQ(gfxAllocation, linearStream.getGraphicsAllocation());
}
TEST(LinearStreamSimpleTest, givenLinearStreamWithoutGraphicsAllocationWhenGettingGpuBaseThenValueSetAsGpuBaseIsReturned) {
uint32_t pCmdBuffer[1024]{};
LinearStream linearStream(pCmdBuffer, 1000);
EXPECT_EQ(0u, linearStream.getGpuBase());
linearStream.setGpuBase(0x1234000);
EXPECT_EQ(0x1234000u, linearStream.getGpuBase());
}
TEST(LinearStreamSimpleTest, givenLinearStreamWithGraphicsAllocationWhenGettingGpuBaseThenGpuAddressFromGraphicsAllocationIsReturned) {
MockGraphicsAllocation gfxAllocation;
gfxAllocation.setCpuPtrAndGpuAddress(nullptr, 0x5555000);
uint32_t pCmdBuffer[1024]{};
LinearStream linearStream(&gfxAllocation, pCmdBuffer, 1000);
EXPECT_EQ(0x5555000u, linearStream.getGpuBase());
}
TEST_F(LinearStreamTest, GivenSizeZeroWhenGettingSpaceUsedThenNonNullPointerIsReturned) {
EXPECT_NE(nullptr, linearStream.getSpace(0));
}