2018-08-24 08:48:59 +02:00
/*
2023-01-02 09:56:45 +00:00
* Copyright ( C ) 2018 - 2023 Intel Corporation
2018-08-24 08:48:59 +02:00
*
2018-09-18 09:11:08 +02:00
* SPDX - License - Identifier : MIT
2018-08-24 08:48:59 +02:00
*
*/
# pragma once
2020-02-23 22:44:01 +01:00
# include "shared/source/command_container/command_encoder.h"
# include "shared/source/command_stream/csr_deps.h"
2023-06-22 11:22:26 +00:00
# include "shared/source/debug_settings/debug_settings_manager.h"
2023-01-20 03:04:15 +00:00
# include "shared/source/execution_environment/root_device_environment.h"
2020-02-23 22:44:01 +01:00
# include "shared/source/helpers/aux_translation.h"
2023-02-01 16:23:01 +00:00
# include "shared/source/helpers/gfx_core_helper.h"
2020-02-23 22:44:01 +01:00
# include "shared/source/helpers/non_copyable_or_moveable.h"
2021-12-22 14:11:05 +00:00
# include "shared/source/helpers/pipe_control_args.h"
2021-03-22 15:14:49 +00:00
# include "shared/source/helpers/string.h"
2023-05-30 09:12:10 +00:00
# include "shared/source/helpers/timestamp_packet_constants.h"
2023-01-20 13:01:19 +00:00
# include "shared/source/helpers/timestamp_packet_container.h"
2020-02-23 22:44:01 +01:00
# include "shared/source/utilities/tag_allocator.h"
2018-10-02 14:37:30 -07:00
2019-02-27 11:39:32 +01:00
# include <cstdint>
2018-08-24 08:48:59 +02:00
2019-03-26 11:59:46 +01:00
namespace NEO {
2018-10-05 12:51:57 -07:00
class CommandStreamReceiver ;
class LinearStream ;
2018-10-02 14:37:30 -07:00
2018-09-25 15:44:43 -07:00
# pragma pack(1)
2023-09-25 07:45:36 +00:00
template < typename TSize , uint32_t packetCount >
2021-03-24 18:21:13 +00:00
class TimestampPackets : public TagTypeBase {
2021-03-26 16:12:19 +00:00
public :
2022-02-04 13:59:01 +00:00
static constexpr AllocationType getAllocationType ( ) {
return AllocationType : : TIMESTAMP_PACKET_TAG_BUFFER ;
2019-02-08 10:27:48 +01:00
}
2021-03-24 18:21:13 +00:00
static constexpr TagNodeType getTagNodeType ( ) { return TagNodeType : : TimestampPacket ; }
2021-03-26 16:12:19 +00:00
static constexpr size_t getSinglePacketSize ( ) { return sizeof ( Packet ) ; }
2021-03-24 18:21:13 +00:00
2018-09-25 15:44:43 -07:00
void initialize ( ) {
2019-04-17 13:29:50 +02:00
for ( auto & packet : packets ) {
2023-05-30 09:12:10 +00:00
packet . contextStart = TimestampPacketConstants : : initValue ;
packet . globalStart = TimestampPacketConstants : : initValue ;
packet . contextEnd = TimestampPacketConstants : : initValue ;
packet . globalEnd = TimestampPacketConstants : : initValue ;
2019-04-17 13:29:50 +02:00
}
2018-09-25 15:44:43 -07:00
}
2021-03-22 15:14:49 +00:00
void assignDataToAllTimestamps ( uint32_t packetIndex , void * source ) {
memcpy_s ( & packets [ packetIndex ] , sizeof ( Packet ) , source , sizeof ( Packet ) ) ;
}
2021-03-26 16:12:19 +00:00
static constexpr size_t getGlobalStartOffset ( ) { return offsetof ( Packet , globalStart ) ; }
static constexpr size_t getContextStartOffset ( ) { return offsetof ( Packet , contextStart ) ; }
static constexpr size_t getContextEndOffset ( ) { return offsetof ( Packet , contextEnd ) ; }
static constexpr size_t getGlobalEndOffset ( ) { return offsetof ( Packet , globalEnd ) ; }
2021-03-22 15:14:49 +00:00
uint64_t getContextStartValue ( uint32_t packetIndex ) const { return static_cast < uint64_t > ( packets [ packetIndex ] . contextStart ) ; }
uint64_t getGlobalStartValue ( uint32_t packetIndex ) const { return static_cast < uint64_t > ( packets [ packetIndex ] . globalStart ) ; }
uint64_t getContextEndValue ( uint32_t packetIndex ) const { return static_cast < uint64_t > ( packets [ packetIndex ] . contextEnd ) ; }
uint64_t getGlobalEndValue ( uint32_t packetIndex ) const { return static_cast < uint64_t > ( packets [ packetIndex ] . globalEnd ) ; }
2021-12-01 16:37:46 +00:00
void const * getContextEndAddress ( uint32_t packetIndex ) const { return static_cast < void const * > ( & packets [ packetIndex ] . contextEnd ) ; }
2022-03-17 18:44:34 +00:00
void const * getContextStartAddress ( uint32_t packetIndex ) const { return static_cast < void const * > ( & packets [ packetIndex ] . contextStart ) ; }
2021-12-01 16:37:46 +00:00
2021-03-22 15:14:49 +00:00
protected :
2023-05-30 09:12:10 +00:00
struct alignas ( 1 ) Packet {
TSize contextStart = TimestampPacketConstants : : initValue ;
TSize globalStart = TimestampPacketConstants : : initValue ;
TSize contextEnd = TimestampPacketConstants : : initValue ;
TSize globalEnd = TimestampPacketConstants : : initValue ;
} ;
2023-09-25 07:45:36 +00:00
Packet packets [ packetCount ] ;
2018-09-25 15:44:43 -07:00
} ;
# pragma pack()
2023-09-25 07:45:36 +00:00
static_assert ( ( ( 4 * TimestampPacketConstants : : preferredPacketCount ) * sizeof ( uint32_t ) ) = = sizeof ( TimestampPackets < uint32_t , TimestampPacketConstants : : preferredPacketCount > ) ,
2018-09-25 15:44:43 -07:00
" This structure is consumed by GPU and has to follow specific restrictions for padding and size " ) ;
2018-11-14 15:29:10 +01:00
struct TimestampPacketHelper {
2021-03-24 18:21:13 +00:00
static uint64_t getContextEndGpuAddress ( const TagNodeBase & timestampPacketNode ) {
return timestampPacketNode . getGpuAddress ( ) + timestampPacketNode . getContextEndOffset ( ) ;
2021-03-22 15:14:49 +00:00
}
2021-03-24 18:21:13 +00:00
static uint64_t getContextStartGpuAddress ( const TagNodeBase & timestampPacketNode ) {
return timestampPacketNode . getGpuAddress ( ) + timestampPacketNode . getContextStartOffset ( ) ;
2021-03-22 15:14:49 +00:00
}
2021-03-24 18:21:13 +00:00
static uint64_t getGlobalEndGpuAddress ( const TagNodeBase & timestampPacketNode ) {
return timestampPacketNode . getGpuAddress ( ) + timestampPacketNode . getGlobalEndOffset ( ) ;
2021-03-22 15:14:49 +00:00
}
2021-03-24 18:21:13 +00:00
static uint64_t getGlobalStartGpuAddress ( const TagNodeBase & timestampPacketNode ) {
return timestampPacketNode . getGpuAddress ( ) + timestampPacketNode . getGlobalStartOffset ( ) ;
2020-05-19 16:20:41 +02:00
}
2018-09-25 15:44:43 -07:00
template < typename GfxFamily >
2021-06-23 10:34:31 +00:00
static void programSemaphore ( LinearStream & cmdStream , TagNodeBase & timestampPacketNode ) {
2020-01-08 17:42:14 +01:00
using COMPARE_OPERATION = typename GfxFamily : : MI_SEMAPHORE_WAIT : : COMPARE_OPERATION ;
2020-01-24 14:58:15 +01:00
2023-11-30 08:32:25 +00:00
if ( debugManager . flags . PrintTimestampPacketUsage . get ( ) = = 1 ) {
2023-06-23 10:20:16 +00:00
printf ( " \n PID: %u, TSP used for Semaphore: 0x% " PRIX64 " , cmdBuffer pos: 0x% " PRIX64 , SysCalls : : getProcessId ( ) , timestampPacketNode . getGpuAddress ( ) , cmdStream . getCurrentGpuAddressPosition ( ) ) ;
2023-06-22 11:22:26 +00:00
}
2020-05-19 16:20:41 +02:00
auto compareAddress = getContextEndGpuAddress ( timestampPacketNode ) ;
2018-09-25 15:44:43 -07:00
2021-03-24 18:21:13 +00:00
for ( uint32_t packetId = 0 ; packetId < timestampPacketNode . getPacketsUsed ( ) ; packetId + + ) {
uint64_t compareOffset = packetId * timestampPacketNode . getSinglePacketSize ( ) ;
2023-09-12 11:42:40 +00:00
EncodeSemaphore < GfxFamily > : : addMiSemaphoreWaitCommand ( cmdStream , compareAddress + compareOffset , TimestampPacketConstants : : initValue , COMPARE_OPERATION : : COMPARE_OPERATION_SAD_NOT_EQUAL_SDD , false , false , false ) ;
2019-11-06 17:18:47 +01:00
}
2018-09-25 15:44:43 -07:00
}
2018-10-02 14:37:30 -07:00
2019-01-25 10:20:32 +01:00
template < typename GfxFamily >
2023-03-09 18:29:45 +00:00
static void programConditionalBbStartForRelaxedOrdering ( LinearStream & cmdStream , TagNodeBase & timestampPacketNode ) {
auto compareAddress = getContextEndGpuAddress ( timestampPacketNode ) ;
for ( uint32_t packetId = 0 ; packetId < timestampPacketNode . getPacketsUsed ( ) ; packetId + + ) {
uint64_t compareOffset = packetId * timestampPacketNode . getSinglePacketSize ( ) ;
2023-05-30 09:12:10 +00:00
EncodeBatchBufferStartOrEnd < GfxFamily > : : programConditionalDataMemBatchBufferStart ( cmdStream , 0 , compareAddress + compareOffset , TimestampPacketConstants : : initValue ,
2023-09-11 17:20:00 +00:00
NEO : : CompareOperation : : Equal , true , false ) ;
2023-03-09 18:29:45 +00:00
}
}
template < typename GfxFamily >
static void programCsrDependenciesForTimestampPacketContainer ( LinearStream & cmdStream , const CsrDependencies & csrDependencies , bool relaxedOrderingEnabled ) {
2021-03-11 13:48:04 +00:00
for ( auto timestampPacketContainer : csrDependencies . timestampPacketContainer ) {
2019-01-25 10:20:32 +01:00
for ( auto & node : timestampPacketContainer - > peekNodes ( ) ) {
2023-03-09 18:29:45 +00:00
if ( relaxedOrderingEnabled ) {
TimestampPacketHelper : : programConditionalBbStartForRelaxedOrdering < GfxFamily > ( cmdStream , * node ) ;
} else {
TimestampPacketHelper : : programSemaphore < GfxFamily > ( cmdStream , * node ) ;
}
2019-01-25 10:20:32 +01:00
}
}
}
2018-10-02 14:37:30 -07:00
2023-03-23 12:05:20 +00:00
template < typename GfxFamily >
static void nonStallingContextEndNodeSignal ( LinearStream & cmdStream , const TagNodeBase & timestampPacketNode , bool multiTileOperation ) {
uint64_t contextEndAddress = getContextEndGpuAddress ( timestampPacketNode ) ;
NEO : : EncodeStoreMemory < GfxFamily > : : programStoreDataImm ( cmdStream , contextEndAddress , 0 , 0 , false , multiTileOperation ) ;
}
2021-03-11 13:48:04 +00:00
template < typename GfxFamily >
2023-01-19 16:11:39 +00:00
static void programCsrDependenciesForForMultiRootDeviceSyncContainer ( LinearStream & cmdStream , const CsrDependencies & csrDependencies ) {
for ( auto timestampPacketContainer : csrDependencies . multiRootTimeStampSyncContainer ) {
for ( auto & node : timestampPacketContainer - > peekNodes ( ) ) {
TimestampPacketHelper : : programSemaphore < GfxFamily > ( cmdStream , * node ) ;
}
2021-03-11 13:48:04 +00:00
}
}
2019-11-09 19:02:25 +01:00
template < typename GfxFamily , AuxTranslationDirection auxTranslationDirection >
2021-06-23 10:34:31 +00:00
static void programSemaphoreForAuxTranslation ( LinearStream & cmdStream ,
const TimestampPacketDependencies * timestampPacketDependencies ,
2023-01-20 03:04:15 +00:00
const RootDeviceEnvironment & rootDeviceEnvironment ) {
2019-11-09 19:02:25 +01:00
auto & container = ( auxTranslationDirection = = AuxTranslationDirection : : AuxToNonAux )
? timestampPacketDependencies - > auxToNonAuxNodes
: timestampPacketDependencies - > nonAuxToAuxNodes ;
2020-03-09 13:48:30 +01:00
// cache flush after NDR, before NonAuxToAux
if ( auxTranslationDirection = = AuxTranslationDirection : : NonAuxToAux & & timestampPacketDependencies - > cacheFlushNodes . peekNodes ( ) . size ( ) > 0 ) {
UNRECOVERABLE_IF ( timestampPacketDependencies - > cacheFlushNodes . peekNodes ( ) . size ( ) ! = 1 ) ;
2020-05-19 16:20:41 +02:00
auto cacheFlushTimestampPacketGpuAddress = getContextEndGpuAddress ( * timestampPacketDependencies - > cacheFlushNodes . peekNodes ( ) [ 0 ] ) ;
2020-03-09 13:48:30 +01:00
2021-12-20 21:37:45 +00:00
PipeControlArgs args ;
2023-01-20 03:04:15 +00:00
args . dcFlushEnable = MemorySynchronizationCommands < GfxFamily > : : getDcFlushEnable ( true , rootDeviceEnvironment ) ;
2022-07-21 14:28:10 +00:00
MemorySynchronizationCommands < GfxFamily > : : addBarrierWithPostSyncOperation (
cmdStream , PostSyncMode : : ImmediateData ,
2023-01-26 03:58:18 +00:00
cacheFlushTimestampPacketGpuAddress , 0 , rootDeviceEnvironment , args ) ;
2020-03-09 13:48:30 +01:00
}
2019-11-09 19:02:25 +01:00
for ( auto & node : container . peekNodes ( ) ) {
2021-06-23 10:34:31 +00:00
TimestampPacketHelper : : programSemaphore < GfxFamily > ( cmdStream , * node ) ;
2019-11-09 19:02:25 +01:00
}
}
2020-03-09 13:48:30 +01:00
template < typename GfxFamily , AuxTranslationDirection auxTranslationDirection >
2023-01-26 03:58:18 +00:00
static size_t getRequiredCmdStreamSizeForAuxTranslationNodeDependency ( size_t count , const RootDeviceEnvironment & rootDeviceEnvironment , bool cacheFlushForBcsRequired ) {
2020-03-09 13:48:30 +01:00
size_t size = count * TimestampPacketHelper : : getRequiredCmdStreamSizeForNodeDependencyWithBlitEnqueue < GfxFamily > ( ) ;
if ( auxTranslationDirection = = AuxTranslationDirection : : NonAuxToAux & & cacheFlushForBcsRequired ) {
2023-01-26 03:58:18 +00:00
size + = MemorySynchronizationCommands < GfxFamily > : : getSizeForBarrierWithPostSyncOperation ( rootDeviceEnvironment , false ) ;
2020-03-09 13:48:30 +01:00
}
return size ;
2019-11-09 19:02:25 +01:00
}
2019-06-24 10:45:49 +02:00
template < typename GfxFamily >
2019-11-06 17:18:47 +01:00
static size_t getRequiredCmdStreamSizeForNodeDependencyWithBlitEnqueue ( ) {
2023-03-10 13:49:06 +00:00
return NEO : : EncodeSemaphore < GfxFamily > : : getSizeMiSemaphoreWait ( ) ;
2019-06-24 10:45:49 +02:00
}
2019-11-06 17:18:47 +01:00
template < typename GfxFamily >
2023-03-09 18:29:45 +00:00
static size_t getRequiredCmdStreamSizeForSemaphoreNodeDependency ( TagNodeBase & timestampPacketNode ) {
2023-03-10 13:49:06 +00:00
return ( timestampPacketNode . getPacketsUsed ( ) * NEO : : EncodeSemaphore < GfxFamily > : : getSizeMiSemaphoreWait ( ) ) ;
2019-11-06 17:18:47 +01:00
}
2019-01-25 10:20:32 +01:00
template < typename GfxFamily >
2023-03-09 18:29:45 +00:00
static size_t getRequiredCmdStreamSizeForRelaxedOrderingNodeDependency ( TagNodeBase & timestampPacketNode ) {
2023-09-11 17:20:00 +00:00
return ( timestampPacketNode . getPacketsUsed ( ) * EncodeBatchBufferStartOrEnd < GfxFamily > : : getCmdSizeConditionalDataMemBatchBufferStart ( false ) ) ;
2023-03-09 18:29:45 +00:00
}
template < typename GfxFamily >
static size_t getRequiredCmdStreamSize ( const CsrDependencies & csrDependencies , bool relaxedOrderingEnabled ) {
2019-11-06 17:18:47 +01:00
size_t totalCommandsSize = 0 ;
2021-03-11 13:48:04 +00:00
for ( auto timestampPacketContainer : csrDependencies . timestampPacketContainer ) {
2019-11-06 17:18:47 +01:00
for ( auto & node : timestampPacketContainer - > peekNodes ( ) ) {
2023-03-09 18:29:45 +00:00
if ( relaxedOrderingEnabled ) {
totalCommandsSize + = getRequiredCmdStreamSizeForRelaxedOrderingNodeDependency < GfxFamily > ( * node ) ;
} else {
totalCommandsSize + = getRequiredCmdStreamSizeForSemaphoreNodeDependency < GfxFamily > ( * node ) ;
}
2019-11-06 17:18:47 +01:00
}
2019-01-25 10:20:32 +01:00
}
2018-10-02 14:37:30 -07:00
2019-11-06 17:18:47 +01:00
return totalCommandsSize ;
2019-01-25 10:20:32 +01:00
}
2021-03-11 13:48:04 +00:00
template < typename GfxFamily >
2023-01-19 16:11:39 +00:00
static size_t getRequiredCmdStreamSizeForMultiRootDeviceSyncNodesContainer ( const CsrDependencies & csrDependencies ) {
2023-03-10 13:49:06 +00:00
return csrDependencies . multiRootTimeStampSyncContainer . size ( ) * NEO : : EncodeSemaphore < GfxFamily > : : getSizeMiSemaphoreWait ( ) ;
2021-03-11 13:48:04 +00:00
}
2018-10-02 14:37:30 -07:00
} ;
2019-11-09 19:02:25 +01:00
2019-03-26 11:59:46 +01:00
} // namespace NEO