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-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"
|
2020-03-09 20:48:30 +08:00
|
|
|
#include "shared/source/helpers/hw_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-01-20 21:01:19 +08:00
|
|
|
#include "shared/source/helpers/timestamp_packet_container.h"
|
2023-01-19 20:57:43 +08:00
|
|
|
#include "shared/source/helpers/timestamp_packet_size_control.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)
|
2020-09-15 15:33:12 +08:00
|
|
|
template <typename TSize>
|
2021-03-25 02:21:13 +08:00
|
|
|
class TimestampPackets : public TagTypeBase {
|
2021-03-27 00:12:19 +08:00
|
|
|
protected:
|
2019-04-17 19:29:50 +08:00
|
|
|
struct Packet {
|
2020-09-15 15:33:12 +08:00
|
|
|
TSize contextStart = 1u;
|
|
|
|
TSize globalStart = 1u;
|
|
|
|
TSize contextEnd = 1u;
|
|
|
|
TSize globalEnd = 1u;
|
2018-08-24 14:48:59 +08:00
|
|
|
};
|
|
|
|
|
2021-03-27 00:12:19 +08:00
|
|
|
public:
|
2022-02-04 21:59:01 +08:00
|
|
|
static constexpr AllocationType getAllocationType() {
|
|
|
|
return AllocationType::TIMESTAMP_PACKET_TAG_BUFFER;
|
2019-02-08 17:27:48 +08:00
|
|
|
}
|
|
|
|
|
2021-03-25 02:21:13 +08:00
|
|
|
static constexpr TagNodeType getTagNodeType() { return TagNodeType::TimestampPacket; }
|
|
|
|
|
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) {
|
|
|
|
packet.contextStart = 1u;
|
|
|
|
packet.globalStart = 1u;
|
|
|
|
packet.contextEnd = 1u;
|
|
|
|
packet.globalEnd = 1u;
|
|
|
|
}
|
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:
|
2019-04-17 19:29:50 +08:00
|
|
|
Packet packets[TimestampPacketSizeControl::preferredPacketCount];
|
2018-09-26 06:44:43 +08:00
|
|
|
};
|
|
|
|
#pragma pack()
|
|
|
|
|
2021-07-22 23:27:05 +08:00
|
|
|
static_assert(((4 * TimestampPacketSizeControl::preferredPacketCount) * sizeof(uint32_t)) == sizeof(TimestampPackets<uint32_t>),
|
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 ×tampPacketNode) {
|
|
|
|
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 ×tampPacketNode) {
|
|
|
|
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 ×tampPacketNode) {
|
|
|
|
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 ×tampPacketNode) {
|
|
|
|
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 ×tampPacketNode) {
|
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
|
|
|
using MI_SEMAPHORE_WAIT = typename GfxFamily::MI_SEMAPHORE_WAIT;
|
|
|
|
|
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();
|
2020-10-01 17:59:59 +08:00
|
|
|
EncodeSempahore<GfxFamily>::addMiSemaphoreWaitCommand(cmdStream, compareAddress + compareOffset, 1, COMPARE_OPERATION::COMPARE_OPERATION_SAD_NOT_EQUAL_SDD);
|
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>
|
2021-06-23 18:34:31 +08:00
|
|
|
static void programCsrDependenciesForTimestampPacketContainer(LinearStream &cmdStream, const CsrDependencies &csrDependencies) {
|
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()) {
|
2021-06-23 18:34:31 +08:00
|
|
|
TimestampPacketHelper::programSemaphore<GfxFamily>(cmdStream, *node);
|
2019-01-25 17:20:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-03 05:37:30 +08:00
|
|
|
|
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) {
|
2019-11-10 02:02:25 +08:00
|
|
|
auto &container = (auxTranslationDirection == AuxTranslationDirection::AuxToNonAux)
|
|
|
|
? timestampPacketDependencies->auxToNonAuxNodes
|
|
|
|
: timestampPacketDependencies->nonAuxToAuxNodes;
|
2023-01-20 11:04:15 +08:00
|
|
|
auto &hwInfo = *rootDeviceEnvironment.getHardwareInfo();
|
2019-11-10 02:02:25 +08:00
|
|
|
|
2020-03-09 20:48:30 +08: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 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(
|
|
|
|
cmdStream, PostSyncMode::ImmediateData,
|
2020-04-27 03:48:59 +08:00
|
|
|
cacheFlushTimestampPacketGpuAddress, 0, hwInfo, 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>
|
|
|
|
static size_t getRequiredCmdStreamSizeForAuxTranslationNodeDependency(size_t count, const HardwareInfo &hwInfo, bool cacheFlushForBcsRequired) {
|
|
|
|
size_t size = count * TimestampPacketHelper::getRequiredCmdStreamSizeForNodeDependencyWithBlitEnqueue<GfxFamily>();
|
|
|
|
|
|
|
|
if (auxTranslationDirection == AuxTranslationDirection::NonAuxToAux && cacheFlushForBcsRequired) {
|
2022-08-19 23:56:22 +08:00
|
|
|
size += MemorySynchronizationCommands<GfxFamily>::getSizeForBarrierWithPostSyncOperation(hwInfo, 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() {
|
2021-06-23 18:34:31 +08:00
|
|
|
return sizeof(typename GfxFamily::MI_SEMAPHORE_WAIT);
|
2019-06-24 16:45:49 +08:00
|
|
|
}
|
|
|
|
|
2019-11-07 00:18:47 +08:00
|
|
|
template <typename GfxFamily>
|
2021-03-25 02:21:13 +08:00
|
|
|
static size_t getRequiredCmdStreamSizeForNodeDependency(TagNodeBase ×tampPacketNode) {
|
2021-06-23 18:34:31 +08:00
|
|
|
return (timestampPacketNode.getPacketsUsed() * sizeof(typename GfxFamily::MI_SEMAPHORE_WAIT));
|
2019-11-07 00:18:47 +08:00
|
|
|
}
|
|
|
|
|
2019-01-25 17:20:32 +08:00
|
|
|
template <typename GfxFamily>
|
|
|
|
static size_t getRequiredCmdStreamSize(const CsrDependencies &csrDependencies) {
|
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()) {
|
|
|
|
totalCommandsSize += getRequiredCmdStreamSizeForNodeDependency<GfxFamily>(*node);
|
|
|
|
}
|
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) {
|
|
|
|
return csrDependencies.multiRootTimeStampSyncContainer.size() * sizeof(typename GfxFamily::MI_SEMAPHORE_WAIT);
|
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
|