From 85f890690d33c2bfd4bbc87483b5b98dcdfd7caa Mon Sep 17 00:00:00 2001 From: "Hoppe, Mateusz" Date: Mon, 12 Feb 2018 13:41:08 +0100 Subject: [PATCH] Refactor preemption methods - moving primary template definitions to preemption.inl Change-Id: Ia54c652503a6272c55800e5ba59b94ef21fa2a19 --- runtime/command_stream/preemption.h | 13 +++++ runtime/command_stream/preemption.inl | 60 +++++++++++++++++++ runtime/gen8/preemption.cpp | 30 +++++----- runtime/gen9/preemption.cpp | 84 +++++---------------------- 4 files changed, 103 insertions(+), 84 deletions(-) diff --git a/runtime/command_stream/preemption.h b/runtime/command_stream/preemption.h index f700f23c05..ed2f5ab638 100644 --- a/runtime/command_stream/preemption.h +++ b/runtime/command_stream/preemption.h @@ -66,4 +66,17 @@ class PreemptionHelper { static PreemptionMode getDefaultPreemptionMode(const HardwareInfo &hwInfo); }; + +template +struct PreemptionConfig { + static const uint32_t mmioAddress; + static const uint32_t maskVal; + static const uint32_t maskShift; + static const uint32_t mask; + + static const uint32_t threadGroupVal; + static const uint32_t cmdLevelVal; + static const uint32_t midThreadVal; +}; + } // namespace OCLRT diff --git a/runtime/command_stream/preemption.inl b/runtime/command_stream/preemption.inl index 432c50927c..e4b495dbb8 100644 --- a/runtime/command_stream/preemption.inl +++ b/runtime/command_stream/preemption.inl @@ -23,6 +23,7 @@ #include "runtime/command_stream/preemption.h" #include "runtime/device/device.h" #include "runtime/command_queue/dispatch_walker_helper.h" +#include "runtime/memory_manager/graphics_allocation.h" namespace OCLRT { @@ -70,4 +71,63 @@ void PreemptionHelper::applyPreemptionWaCmdsEnd(LinearStream *pCommandStream, co } } +template +void PreemptionHelper::programPreamble(LinearStream &preambleCmdStream, const Device &device, + const GraphicsAllocation *preemptionCsr) { + if (device.getPreemptionMode() != PreemptionMode::MidThread) { + return; + } + + UNRECOVERABLE_IF(nullptr == preemptionCsr); + using GPGPU_CSR_BASE_ADDRESS = typename GfxFamily::GPGPU_CSR_BASE_ADDRESS; + using STATE_SIP = typename GfxFamily::STATE_SIP; + + auto csr = reinterpret_cast(preambleCmdStream.getSpace(sizeof(GPGPU_CSR_BASE_ADDRESS))); + csr->init(); + csr->setGpgpuCsrBaseAddress(preemptionCsr->getGpuAddressToPatch()); + + auto sip = reinterpret_cast(preambleCmdStream.getSpace(sizeof(STATE_SIP))); + sip->init(); + sip->setSystemInstructionPointer(0); +} + +template +void PreemptionHelper::programCmdStream(LinearStream &cmdStream, + PreemptionMode newPreemptionMode, PreemptionMode oldPreemptionMode, + GraphicsAllocation *preemptionCsr, + const LinearStream &ih, const Device &device) { + if (oldPreemptionMode == newPreemptionMode) { + DEBUG_BREAK_IF((newPreemptionMode == PreemptionMode::MidThread) && (false == isValidInstructionHeapForMidThreadPreemption(ih, device))); + return; + } + + uint32_t regVal = 0; + if (newPreemptionMode == PreemptionMode::MidThread) { + regVal = PreemptionConfig::midThreadVal | PreemptionConfig::mask; + } else if (newPreemptionMode == PreemptionMode::ThreadGroup) { + regVal = PreemptionConfig::threadGroupVal | PreemptionConfig::mask; + } else { + regVal = PreemptionConfig::cmdLevelVal | PreemptionConfig::mask; + } + + LriHelper::program(&cmdStream, PreemptionConfig::mmioAddress, regVal); +} + +template +size_t PreemptionHelper::getRequiredCmdStreamSize(PreemptionMode newPreemptionMode, PreemptionMode oldPreemptionMode) { + if (newPreemptionMode == oldPreemptionMode) { + return 0; + } + return sizeof(typename GfxFamily::MI_LOAD_REGISTER_IMM); +} + +template +size_t PreemptionHelper::getRequiredPreambleSize(const Device &device) { + if (device.getPreemptionMode() != PreemptionMode::MidThread) { + return 0; + } + + return sizeof(typename GfxFamily::GPGPU_CSR_BASE_ADDRESS) + sizeof(typename GfxFamily::STATE_SIP); +} + } // namespace OCLRT diff --git a/runtime/gen8/preemption.cpp b/runtime/gen8/preemption.cpp index 1111837b26..7ffcae2753 100644 --- a/runtime/gen8/preemption.cpp +++ b/runtime/gen8/preemption.cpp @@ -27,12 +27,17 @@ namespace OCLRT { typedef BDWFamily GfxFamily; -namespace PreemptionBDW { -static constexpr uint32_t mmioAddress = 0x2248; +template <> +struct PreemptionConfig { + static constexpr uint32_t mmioAddress = 0x2248; + static constexpr uint32_t maskVal = 0; + static constexpr uint32_t maskShift = 0; + static constexpr uint32_t mask = 0; -static constexpr uint32_t threadGroupVal = 0; -static constexpr uint32_t cmdLevelVal = (1 << 2); -}; // namespace PreemptionBDW + static constexpr uint32_t threadGroupVal = 0; + static constexpr uint32_t cmdLevelVal = (1 << 2); + static constexpr uint32_t midThreadVal = 0; +}; template <> void PreemptionHelper::programCmdStream(LinearStream &cmdStream, PreemptionMode newPreemptionMode, PreemptionMode oldPreemptionMode, @@ -43,20 +48,12 @@ void PreemptionHelper::programCmdStream(LinearStream &cmdStream, Pree uint32_t regVal = 0; if (newPreemptionMode == PreemptionMode::ThreadGroup) { - regVal = PreemptionBDW::threadGroupVal; + regVal = PreemptionConfig::threadGroupVal; } else { - regVal = PreemptionBDW::cmdLevelVal; + regVal = PreemptionConfig::cmdLevelVal; } - LriHelper::program(&cmdStream, PreemptionBDW::mmioAddress, regVal); -} - -template <> -size_t PreemptionHelper::getRequiredCmdStreamSize(PreemptionMode newPreemptionMode, PreemptionMode oldPreemptionMode) { - if (newPreemptionMode == oldPreemptionMode) { - return 0; - } - return sizeof(typename GfxFamily::MI_LOAD_REGISTER_IMM); + LriHelper::program(&cmdStream, PreemptionConfig::mmioAddress, regVal); } template <> @@ -69,6 +66,7 @@ void PreemptionHelper::programPreamble(LinearStream &preambleCmdStrea const GraphicsAllocation *preemptionCsr) { } +template size_t PreemptionHelper::getRequiredCmdStreamSize(PreemptionMode newPreemptionMode, PreemptionMode oldPreemptionMode); template size_t PreemptionHelper::getPreemptionWaCsSize(const Device &device); template void PreemptionHelper::applyPreemptionWaCmdsBegin(LinearStream *pCommandStream, const Device &device); template void PreemptionHelper::applyPreemptionWaCmdsEnd(LinearStream *pCommandStream, const Device &device); diff --git a/runtime/gen9/preemption.cpp b/runtime/gen9/preemption.cpp index ecfb5cde46..a4d80b905a 100644 --- a/runtime/gen9/preemption.cpp +++ b/runtime/gen9/preemption.cpp @@ -25,82 +25,30 @@ #include "runtime/built_ins/built_ins.h" #include "runtime/command_stream/preemption.h" #include "runtime/command_stream/preemption.inl" -#include "runtime/memory_manager/graphics_allocation.h" namespace OCLRT { typedef SKLFamily GfxFamily; -namespace PreemptionSKL { -static constexpr uint32_t mmioAddress = 0x2580; -static constexpr uint32_t maskVal = (1 << 1) | (1 << 2); -static constexpr uint32_t maskShift = 16; -static constexpr uint32_t mask = PreemptionSKL::maskVal << PreemptionSKL::maskShift; - -static constexpr uint32_t threadGroupVal = (1 << 1); -static constexpr uint32_t cmdLevelVal = (1 << 2); -static constexpr uint32_t midThreadVal = 0; -}; // namespace PreemptionSKL - template <> -void PreemptionHelper::programCmdStream(LinearStream &cmdStream, - PreemptionMode newPreemptionMode, PreemptionMode oldPreemptionMode, - GraphicsAllocation *preemptionCsr, - const LinearStream &ih, const Device &device) { - if (oldPreemptionMode == newPreemptionMode) { - DEBUG_BREAK_IF((newPreemptionMode == PreemptionMode::MidThread) && (false == isValidInstructionHeapForMidThreadPreemption(ih, device))); - return; - } +struct PreemptionConfig { + static constexpr uint32_t mmioAddress = 0x2580; + static constexpr uint32_t maskVal = (1 << 1) | (1 << 2); + static constexpr uint32_t maskShift = 16; + static constexpr uint32_t mask = maskVal << maskShift; - uint32_t regVal = 0; - if (newPreemptionMode == PreemptionMode::MidThread) { - regVal = PreemptionSKL::midThreadVal | PreemptionSKL::mask; - } else if (newPreemptionMode == PreemptionMode::ThreadGroup) { - regVal = PreemptionSKL::threadGroupVal | PreemptionSKL::mask; - } else { - regVal = PreemptionSKL::cmdLevelVal | PreemptionSKL::mask; - } - - LriHelper::program(&cmdStream, PreemptionSKL::mmioAddress, regVal); -} - -template <> -size_t PreemptionHelper::getRequiredCmdStreamSize(PreemptionMode newPreemptionMode, PreemptionMode oldPreemptionMode) { - if (newPreemptionMode == oldPreemptionMode) { - return 0; - } - return sizeof(typename GfxFamily::MI_LOAD_REGISTER_IMM); -} - -template <> -size_t PreemptionHelper::getRequiredPreambleSize(const Device &device) { - if (device.getPreemptionMode() != PreemptionMode::MidThread) { - return 0; - } - - return sizeof(typename GfxFamily::GPGPU_CSR_BASE_ADDRESS) + sizeof(typename GfxFamily::STATE_SIP); -} - -template <> -void PreemptionHelper::programPreamble(LinearStream &preambleCmdStream, const Device &device, - const GraphicsAllocation *preemptionCsr) { - if (device.getPreemptionMode() != PreemptionMode::MidThread) { - return; - } - - UNRECOVERABLE_IF(nullptr == preemptionCsr); - using GPGPU_CSR_BASE_ADDRESS = typename GfxFamily::GPGPU_CSR_BASE_ADDRESS; - using STATE_SIP = typename GfxFamily::STATE_SIP; - - auto csr = reinterpret_cast(preambleCmdStream.getSpace(sizeof(GPGPU_CSR_BASE_ADDRESS))); - csr->init(); - csr->setGpgpuCsrBaseAddress(preemptionCsr->getGpuAddressToPatch()); - - auto sip = reinterpret_cast(preambleCmdStream.getSpace(sizeof(STATE_SIP))); - sip->init(); - sip->setSystemInstructionPointer(0); -} + static constexpr uint32_t threadGroupVal = (1 << 1); + static constexpr uint32_t cmdLevelVal = (1 << 2); + static constexpr uint32_t midThreadVal = 0; +}; +template void PreemptionHelper::programCmdStream(LinearStream &cmdStream, + PreemptionMode newPreemptionMode, PreemptionMode oldPreemptionMode, + GraphicsAllocation *preemptionCsr, + const LinearStream &ih, const Device &device); +template void PreemptionHelper::programPreamble(LinearStream &preambleCmdStream, const Device &device, const GraphicsAllocation *preemptionCsr); +template size_t PreemptionHelper::getRequiredPreambleSize(const Device &device); +template size_t PreemptionHelper::getRequiredCmdStreamSize(PreemptionMode newPreemptionMode, PreemptionMode oldPreemptionMode); template size_t PreemptionHelper::getPreemptionWaCsSize(const Device &device); template void PreemptionHelper::applyPreemptionWaCmdsBegin(LinearStream *pCommandStream, const Device &device); template void PreemptionHelper::applyPreemptionWaCmdsEnd(LinearStream *pCommandStream, const Device &device);