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