1 /* 2 * Copyright (C) 2018-2021 Intel Corporation 3 * 4 * SPDX-License-Identifier: MIT 5 * 6 */ 7 8 #pragma once 9 #include "shared/source/command_stream/command_stream_receiver.h" 10 #include "shared/source/command_stream/linear_stream.h" 11 #include "shared/source/command_stream/preemption_mode.h" 12 #include "shared/source/helpers/hw_info.h" 13 #include "shared/source/os_interface/hw_info_config.h" 14 15 #include "sku_info.h" 16 17 namespace NEO { 18 class Device; 19 class GraphicsAllocation; 20 struct KernelDescriptor; 21 22 struct PreemptionFlags { PreemptionFlagsPreemptionFlags23 PreemptionFlags() { 24 data = 0; 25 } 26 union { 27 struct { 28 uint32_t disabledMidThreadPreemptionKernel : 1; 29 uint32_t vmeKernel : 1; 30 uint32_t deviceSupportsVmePreemption : 1; 31 uint32_t disablePerCtxtPreemptionGranularityControl : 1; 32 uint32_t usesFencesForReadWriteImages : 1; 33 uint32_t disableLSQCROPERFforOCL : 1; 34 uint32_t schedulerKernel : 1; 35 uint32_t reserved : 25; 36 } flags; 37 uint32_t data; 38 }; 39 }; 40 41 class PreemptionHelper { 42 public: 43 template <typename CmdFamily> 44 using INTERFACE_DESCRIPTOR_DATA = typename CmdFamily::INTERFACE_DESCRIPTOR_DATA; 45 46 static PreemptionMode taskPreemptionMode(PreemptionMode devicePreemptionMode, const PreemptionFlags &flags); 47 static bool allowThreadGroupPreemption(const PreemptionFlags &flags); 48 static bool allowMidThreadPreemption(const PreemptionFlags &flags); 49 static void adjustDefaultPreemptionMode(RuntimeCapabilityTable &deviceCapabilities, bool allowMidThread, bool allowThreadGroup, bool allowMidBatch); 50 static PreemptionFlags createPreemptionLevelFlags(Device &device, const KernelDescriptor *kernelDescriptor, bool schedulerKernel); 51 52 template <typename GfxFamily> 53 static size_t getRequiredPreambleSize(const Device &device); 54 template <typename GfxFamily> 55 static size_t getRequiredStateSipCmdSize(Device &device, bool isRcs); 56 57 template <typename GfxFamily> 58 static void programCsrBaseAddress(LinearStream &preambleCmdStream, Device &device, const GraphicsAllocation *preemptionCsr); 59 60 template <typename GfxFamily> 61 static void programStateSip(LinearStream &preambleCmdStream, Device &device); 62 63 template <typename GfxFamily> 64 static void programStateSipEndWa(LinearStream &cmdStream, Device &device); 65 66 template <typename GfxFamily> 67 static size_t getRequiredCmdStreamSize(PreemptionMode newPreemptionMode, PreemptionMode oldPreemptionMode); 68 69 template <typename GfxFamily> 70 static void programCmdStream(LinearStream &cmdStream, PreemptionMode newPreemptionMode, PreemptionMode oldPreemptionMode, 71 GraphicsAllocation *preemptionCsr); 72 73 template <typename GfxFamily> 74 static size_t getPreemptionWaCsSize(const Device &device); 75 76 template <typename GfxFamily> 77 static void applyPreemptionWaCmdsBegin(LinearStream *pCommandStream, const Device &device); 78 79 template <typename GfxFamily> 80 static void applyPreemptionWaCmdsEnd(LinearStream *pCommandStream, const Device &device); 81 82 static PreemptionMode getDefaultPreemptionMode(const HardwareInfo &hwInfo); 83 84 template <typename GfxFamily> 85 static void programInterfaceDescriptorDataPreemption(INTERFACE_DESCRIPTOR_DATA<GfxFamily> *idd, PreemptionMode preemptionMode); 86 }; 87 88 template <typename GfxFamily> 89 struct PreemptionConfig { 90 static const uint32_t mmioAddress; 91 static const uint32_t mask; 92 93 static const uint32_t threadGroupVal; 94 static const uint32_t cmdLevelVal; 95 static const uint32_t midThreadVal; 96 }; 97 98 } // namespace NEO 99