2018-08-24 14:48:59 +08:00
|
|
|
/*
|
2018-09-18 15:11:08 +08:00
|
|
|
* Copyright (C) 2018 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
|
|
|
|
|
2018-10-03 05:37:30 +08:00
|
|
|
#include "runtime/helpers/properties_helper.h"
|
|
|
|
|
2018-08-24 14:48:59 +08:00
|
|
|
#include <cstdint>
|
|
|
|
#include <array>
|
2018-09-26 06:44:43 +08:00
|
|
|
#include <atomic>
|
2018-10-03 05:37:30 +08:00
|
|
|
#include <vector>
|
2018-08-24 14:48:59 +08:00
|
|
|
|
|
|
|
namespace OCLRT {
|
2018-10-03 05:37:30 +08:00
|
|
|
class MemoryManager;
|
|
|
|
template <typename TagType>
|
|
|
|
struct TagNode;
|
|
|
|
|
2018-09-26 06:44:43 +08:00
|
|
|
#pragma pack(1)
|
2018-08-24 14:48:59 +08:00
|
|
|
class TimestampPacket {
|
|
|
|
public:
|
|
|
|
enum class DataIndex : uint32_t {
|
2018-09-26 06:44:43 +08:00
|
|
|
ContextStart = 0,
|
2018-08-24 14:48:59 +08:00
|
|
|
GlobalStart,
|
|
|
|
ContextEnd,
|
|
|
|
GlobalEnd,
|
|
|
|
Max
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class WriteOperationType : uint32_t {
|
2018-09-03 15:34:57 +08:00
|
|
|
BeforeWalker,
|
|
|
|
AfterWalker
|
2018-08-24 14:48:59 +08:00
|
|
|
};
|
|
|
|
|
2018-09-04 15:05:55 +08:00
|
|
|
bool canBeReleased() const {
|
|
|
|
return data[static_cast<uint32_t>(DataIndex::ContextEnd)] != 1 &&
|
2018-09-26 06:44:43 +08:00
|
|
|
data[static_cast<uint32_t>(DataIndex::GlobalEnd)] != 1 &&
|
|
|
|
implicitDependenciesCount.load() == 0;
|
2018-09-04 15:05:55 +08:00
|
|
|
}
|
|
|
|
|
2018-09-03 15:34:57 +08:00
|
|
|
uint64_t pickAddressForDataWrite(DataIndex operationType) const {
|
|
|
|
auto index = static_cast<uint32_t>(operationType);
|
2018-08-24 14:48:59 +08:00
|
|
|
return reinterpret_cast<uint64_t>(&data[index]);
|
|
|
|
}
|
|
|
|
|
2018-09-26 06:44:43 +08:00
|
|
|
void initialize() {
|
|
|
|
data = {{1, 1, 1, 1}};
|
|
|
|
implicitDependenciesCount.store(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void incImplicitDependenciesCount() { implicitDependenciesCount++; }
|
|
|
|
uint64_t pickImplicitDependenciesCountWriteAddress() const { return reinterpret_cast<uint64_t>(&implicitDependenciesCount); }
|
2018-08-30 19:37:39 +08:00
|
|
|
|
2018-08-24 14:48:59 +08:00
|
|
|
protected:
|
2018-09-26 06:44:43 +08:00
|
|
|
std::array<uint32_t, static_cast<uint32_t>(DataIndex::Max)> data = {{1, 1, 1, 1}};
|
|
|
|
std::atomic<uint32_t> implicitDependenciesCount{0};
|
|
|
|
};
|
|
|
|
#pragma pack()
|
|
|
|
|
|
|
|
static_assert(((static_cast<uint32_t>(TimestampPacket::DataIndex::Max) + 1) * sizeof(uint32_t)) == sizeof(TimestampPacket),
|
|
|
|
"This structure is consumed by GPU and has to follow specific restrictions for padding and size");
|
|
|
|
|
|
|
|
struct TimestmapPacketHelper {
|
|
|
|
template <typename GfxFamily>
|
|
|
|
static void programSemaphoreWithImplicitDependency(LinearStream &cmdStream, TimestampPacket ×tmapPacket) {
|
|
|
|
using MI_ATOMIC = typename GfxFamily::MI_ATOMIC;
|
|
|
|
auto compareAddress = timestmapPacket.pickAddressForDataWrite(TimestampPacket::DataIndex::ContextEnd);
|
|
|
|
auto dependenciesCountAddress = timestmapPacket.pickImplicitDependenciesCountWriteAddress();
|
|
|
|
|
|
|
|
KernelCommandsHelper<GfxFamily>::programMiSemaphoreWait(cmdStream, compareAddress, 1);
|
|
|
|
|
|
|
|
timestmapPacket.incImplicitDependenciesCount();
|
|
|
|
|
|
|
|
KernelCommandsHelper<GfxFamily>::programMiAtomic(cmdStream, dependenciesCountAddress,
|
|
|
|
MI_ATOMIC::ATOMIC_OPCODES::ATOMIC_4B_DECREMENT,
|
|
|
|
MI_ATOMIC::DATA_SIZE::DATA_SIZE_DWORD);
|
|
|
|
}
|
2018-08-24 14:48:59 +08:00
|
|
|
};
|
2018-10-03 05:37:30 +08:00
|
|
|
|
|
|
|
class TimestampPacketContainer : public NonCopyableOrMovableClass {
|
|
|
|
public:
|
|
|
|
using Node = TagNode<TimestampPacket>;
|
|
|
|
TimestampPacketContainer() = delete;
|
|
|
|
TimestampPacketContainer(MemoryManager *memoryManager);
|
|
|
|
~TimestampPacketContainer();
|
|
|
|
|
|
|
|
const std::vector<Node *> &peekNodes() const { return timestampPacketNodes; }
|
|
|
|
void add(Node *timestampPacketNode);
|
|
|
|
void swapNodes(TimestampPacketContainer ×tampPacketContainer);
|
|
|
|
void assignAndIncrementNodesRefCounts(TimestampPacketContainer ×tampPacketContainer);
|
|
|
|
void resolveDependencies(bool clearAllDependencies);
|
|
|
|
void makeResident(CommandStreamReceiver &commandStreamReceiver);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
std::vector<Node *> timestampPacketNodes;
|
|
|
|
MemoryManager *memoryManager = nullptr;
|
|
|
|
};
|
2018-08-24 14:48:59 +08:00
|
|
|
} // namespace OCLRT
|