Skip to content

Commit a6c6290

Browse files
Move TSP creation to HwHelper
Signed-off-by: Bartosz Dunajski <[email protected]>
1 parent 1414247 commit a6c6290

File tree

8 files changed

+61
-64
lines changed

8 files changed

+61
-64
lines changed

opencl/test/unit_test/command_stream/command_stream_receiver_tests.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -667,15 +667,6 @@ TEST_F(CommandStreamReceiverTest, whenGettingEventPerfCountAllocatorThenSameTagA
667667
EXPECT_EQ(allocator2, allocator);
668668
}
669669

670-
HWTEST_F(CommandStreamReceiverTest, givenCsrWhenAskingForTimestampPacketAlignmentThenReturnFourCachelines) {
671-
auto &csr = pDevice->getUltCommandStreamReceiver<FamilyType>();
672-
EXPECT_EQ(nullptr, csr.timestampPacketAllocator.get());
673-
674-
constexpr auto expectedAlignment = MemoryConstants::cacheLineSize * 4;
675-
676-
EXPECT_EQ(expectedAlignment, csr.getTimestampPacketAllocatorAlignment());
677-
}
678-
679670
HWTEST_F(CommandStreamReceiverTest, givenUltCommandStreamReceiverWhenAddAubCommentIsCalledThenCallAddAubCommentOnCsr) {
680671
auto &csr = pDevice->getUltCommandStreamReceiver<FamilyType>();
681672
csr.addAubComment("message");

opencl/test/unit_test/helpers/hw_helper_tests.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ TEST_F(HwHelperTest, WhenGettingHelperThenValidHelperReturned) {
7373
EXPECT_NE(nullptr, &helper);
7474
}
7575

76+
HWTEST_F(HwHelperTest, givenHwHelperWhenAskingForTimestampPacketAlignmentThenReturnFourCachelines) {
77+
auto &helper = HwHelper::get(renderCoreFamily);
78+
79+
constexpr auto expectedAlignment = MemoryConstants::cacheLineSize * 4;
80+
81+
EXPECT_EQ(expectedAlignment, helper.getTimestampPacketAllocatorAlignment());
82+
}
83+
7684
HWTEST_F(HwHelperTest, SetRenderSurfaceStateForBufferIsCalledThenSetL1CachePolicyIsCalled) {
7785
using RENDER_SURFACE_STATE = typename FamilyType::RENDER_SURFACE_STATE;
7886
using SURFACE_TYPE = typename RENDER_SURFACE_STATE::SURFACE_TYPE;

opencl/test/unit_test/helpers/timestamp_packet_tests.cpp

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -406,27 +406,17 @@ HWTEST_F(TimestampPacketTests, givenDebugFlagSetWhenCreatingAllocatorThenUseCorr
406406
}
407407

408408
HWTEST_F(TimestampPacketTests, givenTagAlignmentWhenCreatingAllocatorThenGpuAddressIsAligned) {
409-
class MyCsr : public CommandStreamReceiverHw<FamilyType> {
410-
public:
411-
using CommandStreamReceiverHw<FamilyType>::CommandStreamReceiverHw;
412-
size_t getTimestampPacketAllocatorAlignment() const override {
413-
return alignment;
414-
}
415-
416-
size_t alignment = 4096;
417-
};
418-
OsContext &osContext = *executionEnvironment->memoryManager->getRegisteredEngines()[0].osContext;
409+
auto csr = executionEnvironment->memoryManager->getRegisteredEngines()[0].commandStreamReceiver;
419410

420-
MyCsr csr(*executionEnvironment, 0, osContext.getDeviceBitfield());
421-
csr.setupContext(osContext);
411+
auto &hwHelper = HwHelper::get(device->getHardwareInfo().platform.eRenderCoreFamily);
422412

423-
auto allocator = csr.getTimestampPacketAllocator();
413+
auto allocator = csr->getTimestampPacketAllocator();
424414

425415
auto tag1 = allocator->getTag();
426416
auto tag2 = allocator->getTag();
427417

428-
EXPECT_TRUE(isAligned(tag1->getGpuAddress(), csr.alignment));
429-
EXPECT_TRUE(isAligned(tag2->getGpuAddress(), csr.alignment));
418+
EXPECT_TRUE(isAligned(tag1->getGpuAddress(), hwHelper.getTimestampPacketAllocatorAlignment()));
419+
EXPECT_TRUE(isAligned(tag2->getGpuAddress(), hwHelper.getTimestampPacketAllocatorAlignment()));
430420
}
431421

432422
HWTEST_F(TimestampPacketTests, givenDebugFlagSetWhenCreatingTimestampPacketAllocatorThenDisableReusingAndLimitPoolSize) {

opencl/test/unit_test/libult/ult_command_stream_receiver.h

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

shared/source/command_stream/command_stream_receiver_hw.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,6 @@ class CommandStreamReceiverHw : public CommandStreamReceiver {
160160
bool checkPlatformSupportsNewResourceImplicitFlush() const;
161161
bool checkPlatformSupportsGpuIdleImplicitFlush() const;
162162

163-
MOCKABLE_VIRTUAL size_t getTimestampPacketAllocatorAlignment() const;
164-
165-
template <typename SizeT>
166-
std::unique_ptr<TagAllocatorBase> createTimestampPacketAllocator();
167-
168163
HeapDirtyState dshState;
169164
HeapDirtyState iohState;
170165
HeapDirtyState sshState;

shared/source/command_stream/command_stream_receiver_hw_base.inl

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,45 +1375,15 @@ size_t CommandStreamReceiverHw<GfxFamily>::getCmdSizeForPerDssBackedBuffer(const
13751375
return 0;
13761376
}
13771377

1378-
template <typename GfxFamily>
1379-
template <typename TagSizeT>
1380-
std::unique_ptr<TagAllocatorBase> CommandStreamReceiverHw<GfxFamily>::createTimestampPacketAllocator() {
1381-
// dont release nodes in aub/tbx mode, to avoid removing semaphores optimization or reusing returned tags
1382-
bool doNotReleaseNodes = (getType() > CommandStreamReceiverType::CSR_HW) ||
1383-
DebugManager.flags.DisableTimestampPacketOptimizations.get();
1384-
1385-
using TimestampPacketsT = TimestampPackets<TagSizeT>;
1386-
1387-
std::vector<uint32_t> rootDeviceIndices = {rootDeviceIndex};
1388-
1389-
auto allocator = new TagAllocator<TimestampPacketsT>(
1390-
rootDeviceIndices, getMemoryManager(), getPreferredTagPoolSize(), getTimestampPacketAllocatorAlignment(),
1391-
sizeof(TimestampPacketsT), doNotReleaseNodes, osContext->getDeviceBitfield());
1392-
1393-
return std::unique_ptr<TagAllocatorBase>(allocator);
1394-
}
1395-
13961378
template <typename GfxFamily>
13971379
TagAllocatorBase *CommandStreamReceiverHw<GfxFamily>::getTimestampPacketAllocator() {
13981380
if (timestampPacketAllocator.get() == nullptr) {
1399-
if (DebugManager.flags.OverrideTimestampPacketSize.get() != -1) {
1400-
if (DebugManager.flags.OverrideTimestampPacketSize.get() == 4) {
1401-
timestampPacketAllocator = createTimestampPacketAllocator<uint32_t>();
1402-
} else if (DebugManager.flags.OverrideTimestampPacketSize.get() == 8) {
1403-
timestampPacketAllocator = createTimestampPacketAllocator<uint64_t>();
1404-
} else {
1405-
UNRECOVERABLE_IF(true);
1406-
}
1407-
} else {
1408-
timestampPacketAllocator = createTimestampPacketAllocator<typename GfxFamily::TimestampPacketType>();
1409-
}
1381+
auto &hwHelper = HwHelper::get(peekHwInfo().platform.eRenderCoreFamily);
1382+
const std::vector<uint32_t> rootDeviceIndices = {rootDeviceIndex};
1383+
1384+
timestampPacketAllocator = hwHelper.createTimestampPacketAllocator(rootDeviceIndices, getMemoryManager(), getPreferredTagPoolSize(), getType(), osContext->getDeviceBitfield());
14101385
}
14111386
return timestampPacketAllocator.get();
14121387
}
14131388

1414-
template <typename GfxFamily>
1415-
size_t CommandStreamReceiverHw<GfxFamily>::getTimestampPacketAllocatorAlignment() const {
1416-
return MemoryConstants::cacheLineSize * 4;
1417-
}
1418-
14191389
} // namespace NEO

shared/source/helpers/hw_helper.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "shared/source/commands/bxml_generator_glue.h"
1313
#include "shared/source/helpers/aux_translation.h"
1414
#include "shared/source/helpers/engine_node_helper.h"
15+
#include "shared/source/helpers/options.h"
1516
#include "shared/source/utilities/stackvec.h"
1617

1718
#include "aub_mem_dump.h"
@@ -26,6 +27,7 @@
2627
namespace NEO {
2728
class GmmHelper;
2829
class GraphicsAllocation;
30+
class TagAllocatorBase;
2931
struct AllocationData;
3032
struct AllocationProperties;
3133
struct EngineControl;
@@ -147,6 +149,10 @@ class HwHelper {
147149
virtual uint32_t getPlanarYuvMaxHeight() const = 0;
148150
virtual bool isBlitterForImagesSupported(const HardwareInfo &hwInfo) const = 0;
149151
virtual size_t getPreemptionAllocationAlignment() const = 0;
152+
virtual std::unique_ptr<TagAllocatorBase> createTimestampPacketAllocator(const std::vector<uint32_t> &rootDeviceIndices, MemoryManager *memoryManager,
153+
size_t initialTagCount, CommandStreamReceiverType csrType,
154+
DeviceBitfield deviceBitfield) const = 0;
155+
virtual size_t getTimestampPacketAllocatorAlignment() const = 0;
150156

151157
static uint32_t getSubDevicesCount(const HardwareInfo *pHwInfo);
152158
static uint32_t getEnginesCount(const HardwareInfo &hwInfo);
@@ -370,6 +376,11 @@ class HwHelperHw : public HwHelper {
370376

371377
size_t getPreemptionAllocationAlignment() const override;
372378

379+
std::unique_ptr<TagAllocatorBase> createTimestampPacketAllocator(const std::vector<uint32_t> &rootDeviceIndices, MemoryManager *memoryManager,
380+
size_t initialTagCount, CommandStreamReceiverType csrType,
381+
DeviceBitfield deviceBitfield) const override;
382+
size_t getTimestampPacketAllocatorAlignment() const override;
383+
373384
protected:
374385
LocalMemoryAccessMode getDefaultLocalMemoryAccessMode(const HardwareInfo &hwInfo) const override;
375386

shared/source/helpers/hw_helper_base.inl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
#include "shared/source/helpers/hw_helper.h"
1515
#include "shared/source/helpers/hw_info.h"
1616
#include "shared/source/helpers/preamble.h"
17+
#include "shared/source/helpers/timestamp_packet.h"
1718
#include "shared/source/memory_manager/allocation_properties.h"
1819
#include "shared/source/memory_manager/graphics_allocation.h"
1920
#include "shared/source/os_interface/os_interface.h"
21+
#include "shared/source/utilities/tag_allocator.h"
2022

2123
#include "aub_mem_dump.h"
2224
#include "pipe_control_args.h"
@@ -460,6 +462,37 @@ bool HwHelperHw<GfxFamily>::additionalKernelExecInfoSupported(const HardwareInfo
460462
return false;
461463
}
462464

465+
template <typename GfxFamily>
466+
std::unique_ptr<TagAllocatorBase> HwHelperHw<GfxFamily>::createTimestampPacketAllocator(const std::vector<uint32_t> &rootDeviceIndices, MemoryManager *memoryManager,
467+
size_t initialTagCount, CommandStreamReceiverType csrType, DeviceBitfield deviceBitfield) const {
468+
bool doNotReleaseNodes = (csrType > CommandStreamReceiverType::CSR_HW) ||
469+
DebugManager.flags.DisableTimestampPacketOptimizations.get();
470+
471+
auto tagAlignment = getTimestampPacketAllocatorAlignment();
472+
473+
if (DebugManager.flags.OverrideTimestampPacketSize.get() != -1) {
474+
if (DebugManager.flags.OverrideTimestampPacketSize.get() == 4) {
475+
using TimestampPackets32T = TimestampPackets<uint32_t>;
476+
return std::make_unique<TagAllocator<TimestampPackets32T>>(rootDeviceIndices, memoryManager, initialTagCount, tagAlignment, sizeof(TimestampPackets32T), doNotReleaseNodes, deviceBitfield);
477+
} else if (DebugManager.flags.OverrideTimestampPacketSize.get() == 8) {
478+
using TimestampPackets64T = TimestampPackets<uint64_t>;
479+
return std::make_unique<TagAllocator<TimestampPackets64T>>(rootDeviceIndices, memoryManager, initialTagCount, tagAlignment, sizeof(TimestampPackets64T), doNotReleaseNodes, deviceBitfield);
480+
} else {
481+
UNRECOVERABLE_IF(true);
482+
}
483+
}
484+
485+
using TimestampPacketType = typename GfxFamily::TimestampPacketType;
486+
using TimestampPacketsT = TimestampPackets<TimestampPacketType>;
487+
488+
return std::make_unique<TagAllocator<TimestampPacketsT>>(rootDeviceIndices, memoryManager, initialTagCount, tagAlignment, sizeof(TimestampPacketsT), doNotReleaseNodes, deviceBitfield);
489+
}
490+
491+
template <typename GfxFamily>
492+
size_t HwHelperHw<GfxFamily>::getTimestampPacketAllocatorAlignment() const {
493+
return MemoryConstants::cacheLineSize * 4;
494+
}
495+
463496
template <typename GfxFamily>
464497
LocalMemoryAccessMode HwHelperHw<GfxFamily>::getLocalMemoryAccessMode(const HardwareInfo &hwInfo) const {
465498
switch (static_cast<LocalMemoryAccessMode>(DebugManager.flags.ForceLocalMemoryAccessMode.get())) {

0 commit comments

Comments
 (0)