2018-08-24 14:48:59 +08:00
|
|
|
/*
|
2020-01-09 00:42:14 +08:00
|
|
|
* Copyright (C) 2018-2020 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-01-22 23:22:30 +08:00
|
|
|
#include "core/command_stream/csr_deps.h"
|
2019-07-12 22:50:14 +08:00
|
|
|
#include "core/helpers/non_copyable_or_moveable.h"
|
2019-06-12 15:13:06 +08:00
|
|
|
#include "runtime/helpers/hardware_commands_helper.h"
|
2019-01-25 17:20:32 +08:00
|
|
|
#include "runtime/utilities/tag_allocator.h"
|
2018-10-03 05:37:30 +08:00
|
|
|
|
2018-09-26 06:44:43 +08:00
|
|
|
#include <atomic>
|
2019-02-27 18:39:32 +08:00
|
|
|
#include <cstdint>
|
2018-10-03 05:37:30 +08:00
|
|
|
#include <vector>
|
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-11-21 21:05:01 +08:00
|
|
|
namespace TimestampPacketSizeControl {
|
2019-04-17 19:29:50 +08:00
|
|
|
constexpr uint32_t preferredPacketCount = 16u;
|
2018-11-21 21:05:01 +08:00
|
|
|
}
|
|
|
|
|
2018-09-26 06:44:43 +08:00
|
|
|
#pragma pack(1)
|
2019-04-16 20:07:50 +08:00
|
|
|
struct TimestampPacketStorage {
|
2019-04-17 19:29:50 +08:00
|
|
|
struct Packet {
|
|
|
|
uint32_t contextStart = 1u;
|
|
|
|
uint32_t globalStart = 1u;
|
|
|
|
uint32_t contextEnd = 1u;
|
|
|
|
uint32_t globalEnd = 1u;
|
2018-08-24 14:48:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
enum class WriteOperationType : uint32_t {
|
2018-09-03 15:34:57 +08:00
|
|
|
BeforeWalker,
|
|
|
|
AfterWalker
|
2018-08-24 14:48:59 +08:00
|
|
|
};
|
|
|
|
|
2019-02-08 17:27:48 +08:00
|
|
|
static GraphicsAllocation::AllocationType getAllocationType() {
|
|
|
|
return GraphicsAllocation::AllocationType::TIMESTAMP_PACKET_TAG_BUFFER;
|
|
|
|
}
|
|
|
|
|
2019-07-10 16:52:03 +08:00
|
|
|
bool isCompleted() const {
|
2019-11-07 00:18:47 +08:00
|
|
|
for (uint32_t i = 0; i < packetsUsed; i++) {
|
2019-11-29 04:15:36 +08:00
|
|
|
if ((packets[i].contextEnd & 1) || (packets[i].globalEnd & 1)) {
|
2019-11-07 00:18:47 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2019-12-02 15:37:42 +08:00
|
|
|
return implicitDependenciesCount.load() == 0;
|
2018-09-04 15:05:55 +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
|
|
|
implicitDependenciesCount.store(0);
|
2019-11-07 00:18:47 +08:00
|
|
|
packetsUsed = 1;
|
2018-09-26 06:44:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void incImplicitDependenciesCount() { implicitDependenciesCount++; }
|
2018-08-30 19:37:39 +08:00
|
|
|
|
2019-04-17 19:29:50 +08:00
|
|
|
Packet packets[TimestampPacketSizeControl::preferredPacketCount];
|
|
|
|
std::atomic<uint32_t> implicitDependenciesCount{0u};
|
2019-11-07 00:18:47 +08:00
|
|
|
uint32_t packetsUsed = 1;
|
2018-09-26 06:44:43 +08:00
|
|
|
};
|
|
|
|
#pragma pack()
|
|
|
|
|
2019-11-07 00:18:47 +08:00
|
|
|
static_assert(((4 * TimestampPacketSizeControl::preferredPacketCount + 2) * sizeof(uint32_t)) == sizeof(TimestampPacketStorage),
|
2018-09-26 06:44:43 +08:00
|
|
|
"This structure is consumed by GPU and has to follow specific restrictions for padding and size");
|
|
|
|
|
2019-11-12 15:31:46 +08:00
|
|
|
class TimestampPacketContainer : public NonCopyableClass {
|
2019-01-25 17:20:32 +08:00
|
|
|
public:
|
2019-04-16 20:07:50 +08:00
|
|
|
using Node = TagNode<TimestampPacketStorage>;
|
2019-01-25 17:20:32 +08:00
|
|
|
TimestampPacketContainer() = default;
|
2019-11-12 15:31:46 +08:00
|
|
|
TimestampPacketContainer(TimestampPacketContainer &&) = default;
|
|
|
|
TimestampPacketContainer &operator=(TimestampPacketContainer &&) = default;
|
2019-01-25 17:20:32 +08:00
|
|
|
MOCKABLE_VIRTUAL ~TimestampPacketContainer();
|
|
|
|
|
|
|
|
const std::vector<Node *> &peekNodes() const { return timestampPacketNodes; }
|
|
|
|
void add(Node *timestampPacketNode);
|
|
|
|
void swapNodes(TimestampPacketContainer ×tampPacketContainer);
|
|
|
|
void assignAndIncrementNodesRefCounts(const TimestampPacketContainer &inputTimestampPacketContainer);
|
|
|
|
void resolveDependencies(bool clearAllDependencies);
|
|
|
|
void makeResident(CommandStreamReceiver &commandStreamReceiver);
|
2019-07-10 16:52:03 +08:00
|
|
|
bool isCompleted() const;
|
2019-01-25 17:20:32 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
std::vector<Node *> timestampPacketNodes;
|
|
|
|
};
|
|
|
|
|
2019-11-13 19:23:29 +08:00
|
|
|
struct TimestampPacketDependencies : public NonCopyableClass {
|
|
|
|
TimestampPacketContainer previousEnqueueNodes;
|
|
|
|
TimestampPacketContainer barrierNodes;
|
2019-11-10 02:02:25 +08:00
|
|
|
TimestampPacketContainer auxToNonAuxNodes;
|
|
|
|
TimestampPacketContainer nonAuxToAuxNodes;
|
2019-11-13 19:23:29 +08:00
|
|
|
};
|
|
|
|
|
2018-11-14 22:29:10 +08:00
|
|
|
struct TimestampPacketHelper {
|
2018-09-26 06:44:43 +08:00
|
|
|
template <typename GfxFamily>
|
2019-04-16 20:07:50 +08:00
|
|
|
static void programSemaphoreWithImplicitDependency(LinearStream &cmdStream, TagNode<TimestampPacketStorage> ×tampPacketNode) {
|
2018-09-26 06:44:43 +08:00
|
|
|
using MI_ATOMIC = typename GfxFamily::MI_ATOMIC;
|
2020-01-09 00:42:14 +08:00
|
|
|
using COMPARE_OPERATION = typename GfxFamily::MI_SEMAPHORE_WAIT::COMPARE_OPERATION;
|
2019-04-17 19:29:50 +08:00
|
|
|
auto compareAddress = timestampPacketNode.getGpuAddress() + offsetof(TimestampPacketStorage, packets[0].contextEnd);
|
2019-04-16 20:07:50 +08:00
|
|
|
auto dependenciesCountAddress = timestampPacketNode.getGpuAddress() + offsetof(TimestampPacketStorage, implicitDependenciesCount);
|
2018-09-26 06:44:43 +08:00
|
|
|
|
2019-11-07 00:18:47 +08:00
|
|
|
for (uint32_t packetId = 0; packetId < timestampPacketNode.tagForCpuAccess->packetsUsed; packetId++) {
|
|
|
|
uint64_t compareOffset = packetId * sizeof(TimestampPacketStorage::Packet);
|
2020-01-09 00:42:14 +08:00
|
|
|
HardwareCommandsHelper<GfxFamily>::programMiSemaphoreWait(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
|
|
|
|
2019-02-08 17:27:48 +08:00
|
|
|
timestampPacketNode.tagForCpuAccess->incImplicitDependenciesCount();
|
2018-09-26 06:44:43 +08:00
|
|
|
|
2019-06-12 15:13:06 +08:00
|
|
|
HardwareCommandsHelper<GfxFamily>::programMiAtomic(cmdStream, dependenciesCountAddress,
|
|
|
|
MI_ATOMIC::ATOMIC_OPCODES::ATOMIC_4B_DECREMENT,
|
|
|
|
MI_ATOMIC::DATA_SIZE::DATA_SIZE_DWORD);
|
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>
|
|
|
|
static void programCsrDependencies(LinearStream &cmdStream, const CsrDependencies &csrDependencies) {
|
|
|
|
for (auto timestampPacketContainer : csrDependencies) {
|
|
|
|
for (auto &node : timestampPacketContainer->peekNodes()) {
|
2019-02-08 17:27:48 +08:00
|
|
|
TimestampPacketHelper::programSemaphoreWithImplicitDependency<GfxFamily>(cmdStream, *node);
|
2019-01-25 17:20:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-03 05:37:30 +08:00
|
|
|
|
2019-11-10 02:02:25 +08:00
|
|
|
template <typename GfxFamily, AuxTranslationDirection auxTranslationDirection>
|
|
|
|
static void programSemaphoreWithImplicitDependencyForAuxTranslation(LinearStream &cmdStream,
|
|
|
|
const TimestampPacketDependencies *timestampPacketDependencies) {
|
|
|
|
auto &container = (auxTranslationDirection == AuxTranslationDirection::AuxToNonAux)
|
|
|
|
? timestampPacketDependencies->auxToNonAuxNodes
|
|
|
|
: timestampPacketDependencies->nonAuxToAuxNodes;
|
|
|
|
|
|
|
|
for (auto &node : container.peekNodes()) {
|
|
|
|
TimestampPacketHelper::programSemaphoreWithImplicitDependency<GfxFamily>(cmdStream, *node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
static size_t getRequiredCmdStreamSizeForAuxTranslationNodeDependency(const MemObjsForAuxTranslation *memObjsForAuxTranslation) {
|
2019-11-07 00:18:47 +08:00
|
|
|
return memObjsForAuxTranslation->size() * TimestampPacketHelper::getRequiredCmdStreamSizeForNodeDependencyWithBlitEnqueue<GfxFamily>();
|
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() {
|
2019-06-24 16:45:49 +08:00
|
|
|
return sizeof(typename GfxFamily::MI_SEMAPHORE_WAIT) + sizeof(typename GfxFamily::MI_ATOMIC);
|
|
|
|
}
|
|
|
|
|
2019-11-07 00:18:47 +08:00
|
|
|
template <typename GfxFamily>
|
|
|
|
static size_t getRequiredCmdStreamSizeForNodeDependency(TagNode<TimestampPacketStorage> ×tampPacketNode) {
|
|
|
|
size_t totalMiSemaphoreWaitSize = timestampPacketNode.tagForCpuAccess->packetsUsed * sizeof(typename GfxFamily::MI_SEMAPHORE_WAIT);
|
|
|
|
|
|
|
|
return totalMiSemaphoreWaitSize + sizeof(typename GfxFamily::MI_ATOMIC);
|
|
|
|
}
|
|
|
|
|
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;
|
2019-01-25 17:20:32 +08:00
|
|
|
for (auto timestampPacketContainer : csrDependencies) {
|
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
|
|
|
}
|
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
|