Skip to content

Commit 4703417

Browse files
Use correct virtual addresses in TBX CSR makeCoherent method
- cpu virtual address was used instead of gpu va - this caused incorrect behaviour of TBX server when special heap allocator assigning GPU addresses was used Change-Id: I2328cf2441be797311fd6a3c7b331b0fff79d4fc
1 parent b56289a commit 4703417

File tree

6 files changed

+28
-7
lines changed

6 files changed

+28
-7
lines changed

runtime/command_queue/command_queue.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ volatile uint32_t *CommandQueue::getHwTagAddress() const {
142142
DEBUG_BREAK_IF(!this->device);
143143
auto &commandStreamReceiver = device->getCommandStreamReceiver();
144144
auto tag_address = commandStreamReceiver.getTagAddress();
145-
commandStreamReceiver.makeCoherent((void *)tag_address, sizeof(tag_address));
145+
auto allocation = commandStreamReceiver.getTagAllocation();
146+
UNRECOVERABLE_IF(allocation == nullptr);
147+
commandStreamReceiver.makeCoherent(*allocation);
146148
return tag_address;
147149
}
148150

runtime/command_stream/command_stream_receiver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void CommandStreamReceiver::processEviction() {
6666

6767
void CommandStreamReceiver::makeNonResident(GraphicsAllocation &gfxAllocation) {
6868
if (gfxAllocation.residencyTaskCount != ObjectNotResident) {
69-
makeCoherent(gfxAllocation.getUnderlyingBuffer(), gfxAllocation.getUnderlyingBufferSize());
69+
makeCoherent(gfxAllocation);
7070
getMemoryManager()->pushAllocationForEviction(&gfxAllocation);
7171
}
7272

runtime/command_stream/command_stream_receiver.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class CommandStreamReceiver {
6565

6666
virtual void flushBatchedSubmissions() = 0;
6767

68-
virtual void makeCoherent(void *address, size_t length){};
68+
virtual void makeCoherent(GraphicsAllocation &gfxAllocation){};
6969
virtual void makeResident(GraphicsAllocation &gfxAllocation);
7070
virtual void makeNonResident(GraphicsAllocation &gfxAllocation);
7171
void makeSurfacePackNonResident(ResidencyContainer *allocationsForResidency);
@@ -86,6 +86,9 @@ class CommandStreamReceiver {
8686
OSInterface *getOSInterface() { return osInterface.get(); };
8787

8888
MOCKABLE_VIRTUAL void setTagAllocation(GraphicsAllocation *allocation);
89+
GraphicsAllocation *getTagAllocation() const {
90+
return tagAllocation;
91+
}
8992
volatile uint32_t *getTagAddress() const { return tagAddress; }
9093

9194
virtual bool waitForFlushStamp(FlushStamp &flushStampToWait) { return true; };

runtime/command_stream/tbx_command_stream_receiver_hw.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class TbxCommandStreamReceiverHw : public CommandStreamReceiverHw<GfxFamily> {
4646

4747
public:
4848
FlushStamp flush(BatchBuffer &batchBuffer, EngineType engineType, ResidencyContainer *allocationsForResidency) override;
49-
void makeCoherent(void *address, size_t length) override;
49+
void makeCoherent(GraphicsAllocation &gfxAllocation) override;
5050

5151
void processResidency(ResidencyContainer *allocationsForResidency) override;
5252
bool writeMemory(GraphicsAllocation &gfxAllocation);

runtime/command_stream/tbx_command_stream_receiver_hw.inl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,14 +361,18 @@ void TbxCommandStreamReceiverHw<GfxFamily>::processResidency(ResidencyContainer
361361
}
362362

363363
template <typename GfxFamily>
364-
void TbxCommandStreamReceiverHw<GfxFamily>::makeCoherent(void *address, size_t length) {
364+
void TbxCommandStreamReceiverHw<GfxFamily>::makeCoherent(GraphicsAllocation &gfxAllocation) {
365+
auto cpuAddress = gfxAllocation.getUnderlyingBuffer();
366+
auto gpuAddress = gfxAllocation.getGpuAddress();
367+
auto length = gfxAllocation.getUnderlyingBufferSize();
368+
365369
if (length) {
366370
PageWalker walker = [&](uint64_t physAddress, size_t size, size_t offset) {
367371
DEBUG_BREAK_IF(offset > length);
368-
stream.readMemory(physAddress, ptrOffset(address, offset), size);
372+
stream.readMemory(physAddress, ptrOffset(cpuAddress, offset), size);
369373
};
370374

371-
ppgtt.pageWalk(reinterpret_cast<uintptr_t>(address), length, 0, walker);
375+
ppgtt.pageWalk(static_cast<uintptr_t>(gpuAddress), length, 0, walker);
372376
}
373377
}
374378
} // namespace OCLRT

unit_tests/command_stream/command_stream_receiver_tests.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,3 +257,15 @@ HWTEST_F(CommandStreamReceiverTest, givenDefaultCommandStreamReceiverThenDefault
257257
auto &csr = pDevice->getUltCommandStreamReceiver<FamilyType>();
258258
EXPECT_EQ(CommandStreamReceiver::DispatchMode::ImmediateDispatch, csr.dispatchMode);
259259
}
260+
261+
TEST(CommandStreamReceiverSimpleTest, givenCSRWithoutTagAllocationWhenGetTagAllocationIsCalledThenNullptrIsReturned) {
262+
MockCommandStreamReceiver csr;
263+
EXPECT_EQ(nullptr, csr.getTagAllocation());
264+
}
265+
266+
TEST(CommandStreamReceiverSimpleTest, givenCSRWithTagAllocationSetWhenGetTagAllocationIsCalledThenCorrectAllocationIsReturned) {
267+
MockCommandStreamReceiver csr;
268+
GraphicsAllocation allocation(reinterpret_cast<void *>(0x1000), 0x1000);
269+
csr.setTagAllocation(&allocation);
270+
EXPECT_EQ(&allocation, csr.getTagAllocation());
271+
}

0 commit comments

Comments
 (0)