Skip to content

Commit da9d039

Browse files
New method to return TimestampPacket alignment
Signed-off-by: Bartosz Dunajski <[email protected]>
1 parent e93dc9c commit da9d039

File tree

5 files changed

+36
-18
lines changed

5 files changed

+36
-18
lines changed

opencl/test/unit_test/command_stream/command_stream_receiver_tests.cpp

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -640,27 +640,13 @@ TEST_F(CommandStreamReceiverTest, whenGettingEventPerfCountAllocatorThenSameTagA
640640
EXPECT_EQ(allocator2, allocator);
641641
}
642642

643-
HWTEST_F(CommandStreamReceiverTest, givenTimestampPacketAllocatorWhenAskingForTagThenReturnValidObject) {
643+
HWTEST_F(CommandStreamReceiverTest, givenCsrWhenAskingForTimestampPacketAlignmentThenReturnFourCachelines) {
644644
auto &csr = pDevice->getUltCommandStreamReceiver<FamilyType>();
645645
EXPECT_EQ(nullptr, csr.timestampPacketAllocator.get());
646646

647-
auto allocator = static_cast<TagAllocator<TimestampPackets<uint32_t>> *>(csr.getTimestampPacketAllocator());
648-
EXPECT_NE(nullptr, csr.timestampPacketAllocator.get());
649-
EXPECT_EQ(allocator, csr.timestampPacketAllocator.get());
647+
constexpr auto expectedAlignment = MemoryConstants::cacheLineSize * 4;
650648

651-
auto allocator2 = static_cast<TagAllocator<TimestampPackets<uint32_t>> *>(csr.getTimestampPacketAllocator());
652-
EXPECT_EQ(allocator, allocator2);
653-
654-
auto node1 = allocator->getTag();
655-
auto node2 = allocator->getTag();
656-
EXPECT_NE(nullptr, node1);
657-
EXPECT_NE(nullptr, node2);
658-
EXPECT_NE(node1, node2);
659-
660-
constexpr auto tagAlignment = MemoryConstants::cacheLineSize * 4;
661-
662-
EXPECT_TRUE(isAligned(node1->getGpuAddress(), tagAlignment));
663-
EXPECT_TRUE(isAligned(node2->getGpuAddress(), tagAlignment));
649+
EXPECT_EQ(expectedAlignment, csr.getTimestampPacketAllocatorAlignment());
664650
}
665651

666652
HWTEST_F(CommandStreamReceiverTest, givenUltCommandStreamReceiverWhenAddAubCommentIsCalledThenCallAddAubCommentOnCsr) {

opencl/test/unit_test/helpers/timestamp_packet_tests.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,30 @@ HWTEST_F(TimestampPacketTests, givenCommandStreamReceiverHwWhenObtainingPreferre
358358
EXPECT_EQ(2048u, csr.getPreferredTagPoolSize());
359359
}
360360

361+
HWTEST_F(TimestampPacketTests, givenTagAlignmentWhenCreatingAllocatorThenGpuAddressIsAligned) {
362+
class MyCsr : public CommandStreamReceiverHw<FamilyType> {
363+
public:
364+
using CommandStreamReceiverHw<FamilyType>::CommandStreamReceiverHw;
365+
size_t getTimestampPacketAllocatorAlignment() const override {
366+
return alignment;
367+
}
368+
369+
size_t alignment = 4096;
370+
};
371+
OsContext &osContext = *executionEnvironment->memoryManager->getRegisteredEngines()[0].osContext;
372+
373+
MyCsr csr(*executionEnvironment, 0, osContext.getDeviceBitfield());
374+
csr.setupContext(osContext);
375+
376+
auto allocator = csr.getTimestampPacketAllocator();
377+
378+
auto tag1 = allocator->getTag();
379+
auto tag2 = allocator->getTag();
380+
381+
EXPECT_TRUE(isAligned(tag1->getGpuAddress(), csr.alignment));
382+
EXPECT_TRUE(isAligned(tag2->getGpuAddress(), csr.alignment));
383+
}
384+
361385
HWTEST_F(TimestampPacketTests, givenDebugFlagSetWhenCreatingTimestampPacketAllocatorThenDisableReusingAndLimitPoolSize) {
362386
DebugManagerStateRestore restore;
363387
DebugManager.flags.DisableTimestampPacketOptimizations.set(true);

opencl/test/unit_test/libult/ult_command_stream_receiver.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class UltCommandStreamReceiver : public CommandStreamReceiverHw<GfxFamily>, publ
3737
using BaseClass::getCmdSizeForPrologue;
3838
using BaseClass::getScratchPatchAddress;
3939
using BaseClass::getScratchSpaceController;
40+
using BaseClass::getTimestampPacketAllocatorAlignment;
4041
using BaseClass::indirectHeap;
4142
using BaseClass::iohState;
4243
using BaseClass::isBlitterDirectSubmissionEnabled;

shared/source/command_stream/command_stream_receiver_hw.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ class CommandStreamReceiverHw : public CommandStreamReceiver {
155155
bool checkPlatformSupportsNewResourceImplicitFlush() const;
156156
bool checkPlatformSupportsGpuIdleImplicitFlush() const;
157157

158+
MOCKABLE_VIRTUAL size_t getTimestampPacketAllocatorAlignment() const;
159+
158160
HeapDirtyState dshState;
159161
HeapDirtyState iohState;
160162
HeapDirtyState sshState;

shared/source/command_stream/command_stream_receiver_hw_base.inl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1282,10 +1282,15 @@ TagAllocatorBase *CommandStreamReceiverHw<GfxFamily>::getTimestampPacketAllocato
12821282
using TimestampPacketsT = TimestampPackets<typename GfxFamily::TimestampPacketType>;
12831283

12841284
timestampPacketAllocator = std::make_unique<TagAllocator<TimestampPacketsT>>(
1285-
rootDeviceIndex, getMemoryManager(), getPreferredTagPoolSize(), MemoryConstants::cacheLineSize * 4,
1285+
rootDeviceIndex, getMemoryManager(), getPreferredTagPoolSize(), getTimestampPacketAllocatorAlignment(),
12861286
sizeof(TimestampPacketsT), doNotReleaseNodes, osContext->getDeviceBitfield());
12871287
}
12881288
return timestampPacketAllocator.get();
12891289
}
12901290

1291+
template <typename GfxFamily>
1292+
size_t CommandStreamReceiverHw<GfxFamily>::getTimestampPacketAllocatorAlignment() const {
1293+
return MemoryConstants::cacheLineSize * 4;
1294+
}
1295+
12911296
} // namespace NEO

0 commit comments

Comments
 (0)