2018-01-02 19:10:34 +08:00
|
|
|
/*
|
2021-05-17 02:51:16 +08:00
|
|
|
* Copyright (C) 2018-2021 Intel Corporation
|
2018-01-02 19:10:34 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2018-01-02 19:10:34 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-02-24 20:10:44 +08:00
|
|
|
#include "shared/source/built_ins/sip.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/command_stream/preemption.h"
|
|
|
|
#include "shared/source/device/device.h"
|
|
|
|
#include "shared/source/helpers/hw_helper.h"
|
2021-10-05 20:44:41 +08:00
|
|
|
#include "shared/source/helpers/preamble.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/memory_manager/graphics_allocation.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2021-10-05 20:44:41 +08:00
|
|
|
#include "pipe_control_args.h"
|
2018-01-02 19:10:34 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2018-01-02 19:10:34 +08:00
|
|
|
|
2018-02-12 20:41:08 +08:00
|
|
|
template <typename GfxFamily>
|
2018-11-05 18:52:19 +08:00
|
|
|
void PreemptionHelper::programCsrBaseAddress(LinearStream &preambleCmdStream, Device &device, const GraphicsAllocation *preemptionCsr) {
|
2018-02-12 20:41:08 +08:00
|
|
|
using GPGPU_CSR_BASE_ADDRESS = typename GfxFamily::GPGPU_CSR_BASE_ADDRESS;
|
2018-11-05 18:52:19 +08:00
|
|
|
bool isMidThreadPreemption = device.getPreemptionMode() == PreemptionMode::MidThread;
|
|
|
|
if (isMidThreadPreemption) {
|
2018-04-10 19:49:26 +08:00
|
|
|
UNRECOVERABLE_IF(nullptr == preemptionCsr);
|
2018-02-12 20:41:08 +08:00
|
|
|
|
2018-04-10 19:49:26 +08:00
|
|
|
auto csr = reinterpret_cast<GPGPU_CSR_BASE_ADDRESS *>(preambleCmdStream.getSpace(sizeof(GPGPU_CSR_BASE_ADDRESS)));
|
2020-04-09 00:33:03 +08:00
|
|
|
GPGPU_CSR_BASE_ADDRESS cmd = GfxFamily::cmdInitGpgpuCsrBaseAddress;
|
|
|
|
cmd.setGpgpuCsrBaseAddress(preemptionCsr->getGpuAddressToPatch());
|
|
|
|
*csr = cmd;
|
2018-04-10 19:49:26 +08:00
|
|
|
}
|
2018-11-05 18:52:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
void PreemptionHelper::programStateSip(LinearStream &preambleCmdStream, Device &device) {
|
|
|
|
using STATE_SIP = typename GfxFamily::STATE_SIP;
|
2020-10-27 23:00:56 +08:00
|
|
|
bool debuggingEnabled = device.getDebugger() != nullptr || device.isDebuggerActive();
|
2018-11-05 18:52:19 +08:00
|
|
|
bool isMidThreadPreemption = device.getPreemptionMode() == PreemptionMode::MidThread;
|
|
|
|
|
2020-10-27 23:00:56 +08:00
|
|
|
if (isMidThreadPreemption || debuggingEnabled) {
|
2021-04-16 20:52:30 +08:00
|
|
|
auto sipAllocation = SipKernel::getSipKernel(device).getSipAllocation();
|
2020-04-09 00:33:03 +08:00
|
|
|
|
|
|
|
auto sip = reinterpret_cast<STATE_SIP *>(preambleCmdStream.getSpace(sizeof(STATE_SIP)));
|
|
|
|
STATE_SIP cmd = GfxFamily::cmdInitStateSip;
|
|
|
|
cmd.setSystemInstructionPointer(sipAllocation->getGpuAddressToPatch());
|
|
|
|
*sip = cmd;
|
2018-04-10 19:49:26 +08:00
|
|
|
}
|
2018-02-12 20:41:08 +08:00
|
|
|
}
|
|
|
|
|
2021-01-29 01:30:56 +08:00
|
|
|
template <typename GfxFamily>
|
|
|
|
void PreemptionHelper::programStateSipEndWa(LinearStream &cmdStream, Device &device) {}
|
|
|
|
|
2018-02-12 20:41:08 +08:00
|
|
|
template <typename GfxFamily>
|
2019-07-31 14:57:00 +08:00
|
|
|
void PreemptionHelper::programCmdStream(LinearStream &cmdStream, PreemptionMode newPreemptionMode,
|
|
|
|
PreemptionMode oldPreemptionMode, GraphicsAllocation *preemptionCsr) {
|
2018-02-12 20:41:08 +08:00
|
|
|
if (oldPreemptionMode == newPreemptionMode) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t regVal = 0;
|
|
|
|
if (newPreemptionMode == PreemptionMode::MidThread) {
|
|
|
|
regVal = PreemptionConfig<GfxFamily>::midThreadVal | PreemptionConfig<GfxFamily>::mask;
|
|
|
|
} else if (newPreemptionMode == PreemptionMode::ThreadGroup) {
|
|
|
|
regVal = PreemptionConfig<GfxFamily>::threadGroupVal | PreemptionConfig<GfxFamily>::mask;
|
|
|
|
} else {
|
|
|
|
regVal = PreemptionConfig<GfxFamily>::cmdLevelVal | PreemptionConfig<GfxFamily>::mask;
|
|
|
|
}
|
|
|
|
|
2020-04-28 22:48:23 +08:00
|
|
|
LriHelper<GfxFamily>::program(&cmdStream, PreemptionConfig<GfxFamily>::mmioAddress, regVal, true);
|
2018-02-12 20:41:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
size_t PreemptionHelper::getRequiredCmdStreamSize(PreemptionMode newPreemptionMode, PreemptionMode oldPreemptionMode) {
|
|
|
|
if (newPreemptionMode == oldPreemptionMode) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return sizeof(typename GfxFamily::MI_LOAD_REGISTER_IMM);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
size_t PreemptionHelper::getRequiredPreambleSize(const Device &device) {
|
2018-04-10 19:49:26 +08:00
|
|
|
if (device.getPreemptionMode() == PreemptionMode::MidThread) {
|
2018-11-05 18:52:19 +08:00
|
|
|
return sizeof(typename GfxFamily::GPGPU_CSR_BASE_ADDRESS);
|
2018-04-10 19:49:26 +08:00
|
|
|
}
|
2018-11-05 18:52:19 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2021-10-17 20:21:29 +08:00
|
|
|
size_t PreemptionHelper::getRequiredStateSipCmdSize(Device &device, bool isRcs) {
|
2018-11-05 18:52:19 +08:00
|
|
|
size_t size = 0;
|
|
|
|
bool isMidThreadPreemption = device.getPreemptionMode() == PreemptionMode::MidThread;
|
2020-10-27 23:00:56 +08:00
|
|
|
bool debuggingEnabled = device.getDebugger() != nullptr || device.isDebuggerActive();
|
2018-11-05 18:52:19 +08:00
|
|
|
|
2020-10-27 23:00:56 +08:00
|
|
|
if (isMidThreadPreemption || debuggingEnabled) {
|
2018-04-10 19:49:26 +08:00
|
|
|
size += sizeof(typename GfxFamily::STATE_SIP);
|
2018-02-12 20:41:08 +08:00
|
|
|
}
|
2018-04-10 19:49:26 +08:00
|
|
|
return size;
|
2018-02-12 20:41:08 +08:00
|
|
|
}
|
|
|
|
|
2020-02-07 21:46:11 +08:00
|
|
|
template <typename GfxFamily>
|
|
|
|
size_t PreemptionHelper::getPreemptionWaCsSize(const Device &device) {
|
|
|
|
return 0u;
|
|
|
|
}
|
|
|
|
template <typename GfxFamily>
|
|
|
|
void PreemptionHelper::applyPreemptionWaCmdsBegin(LinearStream *pCommandStream, const Device &device) {
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
void PreemptionHelper::applyPreemptionWaCmdsEnd(LinearStream *pCommandStream, const Device &device) {
|
|
|
|
}
|
|
|
|
|
2018-03-02 05:43:04 +08:00
|
|
|
template <typename GfxFamily>
|
|
|
|
void PreemptionHelper::programInterfaceDescriptorDataPreemption(INTERFACE_DESCRIPTOR_DATA<GfxFamily> *idd, PreemptionMode preemptionMode) {
|
2020-02-07 21:46:11 +08:00
|
|
|
using INTERFACE_DESCRIPTOR_DATA = typename GfxFamily::INTERFACE_DESCRIPTOR_DATA;
|
|
|
|
if (preemptionMode == PreemptionMode::MidThread) {
|
|
|
|
idd->setThreadPreemptionDisable(INTERFACE_DESCRIPTOR_DATA::THREAD_PREEMPTION_DISABLE_DISABLE);
|
|
|
|
} else {
|
|
|
|
idd->setThreadPreemptionDisable(INTERFACE_DESCRIPTOR_DATA::THREAD_PREEMPTION_DISABLE_ENABLE);
|
|
|
|
}
|
2018-03-02 05:43:04 +08:00
|
|
|
}
|
|
|
|
|
2019-10-31 23:22:41 +08:00
|
|
|
template <typename GfxFamily>
|
|
|
|
constexpr uint32_t PreemptionConfig<GfxFamily>::mmioAddress = 0x2580;
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
constexpr uint32_t PreemptionConfig<GfxFamily>::mask = ((1 << 1) | (1 << 2)) << 16;
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
constexpr uint32_t PreemptionConfig<GfxFamily>::threadGroupVal = (1 << 1);
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
constexpr uint32_t PreemptionConfig<GfxFamily>::cmdLevelVal = (1 << 2);
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
constexpr uint32_t PreemptionConfig<GfxFamily>::midThreadVal = 0;
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|