|
| 1 | +/* |
| 2 | + * Copyright (C) 2018-2020 Intel Corporation |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: MIT |
| 5 | + * |
| 6 | + */ |
| 7 | + |
| 8 | +#pragma once |
| 9 | +#include "shared/source/helpers/hw_helper.h" |
| 10 | + |
| 11 | +#include "opencl/source/helpers/hardware_commands_helper.h" |
| 12 | +#include "opencl/source/kernel/kernel.h" |
| 13 | + |
| 14 | +namespace NEO { |
| 15 | + |
| 16 | +template <typename GfxFamily> |
| 17 | +bool HardwareCommandsHelper<GfxFamily>::isPipeControlWArequired(const HardwareInfo &hwInfo) { return false; } |
| 18 | + |
| 19 | +template <typename GfxFamily> |
| 20 | +typename HardwareCommandsHelper<GfxFamily>::INTERFACE_DESCRIPTOR_DATA *HardwareCommandsHelper<GfxFamily>::getInterfaceDescriptor( |
| 21 | + const IndirectHeap &indirectHeap, |
| 22 | + uint64_t offsetInterfaceDescriptor, |
| 23 | + HardwareCommandsHelper<GfxFamily>::INTERFACE_DESCRIPTOR_DATA *inlineInterfaceDescriptor) { |
| 24 | + return static_cast<INTERFACE_DESCRIPTOR_DATA *>(ptrOffset(indirectHeap.getCpuBase(), (size_t)offsetInterfaceDescriptor)); |
| 25 | +} |
| 26 | + |
| 27 | +template <typename GfxFamily> |
| 28 | +void HardwareCommandsHelper<GfxFamily>::setAdditionalInfo( |
| 29 | + INTERFACE_DESCRIPTOR_DATA *pInterfaceDescriptor, |
| 30 | + const Kernel &kernel, |
| 31 | + const size_t &sizeCrossThreadData, |
| 32 | + const size_t &sizePerThreadData, |
| 33 | + const uint32_t threadsPerThreadGroup) { |
| 34 | + auto grfSize = sizeof(typename GfxFamily::GRF); |
| 35 | + DEBUG_BREAK_IF((sizeCrossThreadData % grfSize) != 0); |
| 36 | + auto numGrfCrossThreadData = static_cast<uint32_t>(sizeCrossThreadData / grfSize); |
| 37 | + DEBUG_BREAK_IF(numGrfCrossThreadData == 0); |
| 38 | + pInterfaceDescriptor->setCrossThreadConstantDataReadLength(numGrfCrossThreadData); |
| 39 | + |
| 40 | + DEBUG_BREAK_IF((sizePerThreadData % grfSize) != 0); |
| 41 | + auto numGrfPerThreadData = static_cast<uint32_t>(sizePerThreadData / grfSize); |
| 42 | + |
| 43 | + // at least 1 GRF of perThreadData for each thread in a thread group when sizeCrossThreadData != 0 |
| 44 | + numGrfPerThreadData = std::max(numGrfPerThreadData, 1u); |
| 45 | + pInterfaceDescriptor->setConstantIndirectUrbEntryReadLength(numGrfPerThreadData); |
| 46 | +} |
| 47 | + |
| 48 | +template <typename GfxFamily> |
| 49 | +uint32_t HardwareCommandsHelper<GfxFamily>::additionalSizeRequiredDsh() { |
| 50 | + return sizeof(INTERFACE_DESCRIPTOR_DATA); |
| 51 | +} |
| 52 | + |
| 53 | +template <typename GfxFamily> |
| 54 | +size_t HardwareCommandsHelper<GfxFamily>::getSizeRequiredCS(const Kernel *kernel) { |
| 55 | + size_t size = 2 * sizeof(typename GfxFamily::MEDIA_STATE_FLUSH) + |
| 56 | + sizeof(typename GfxFamily::MEDIA_INTERFACE_DESCRIPTOR_LOAD); |
| 57 | + return size; |
| 58 | +} |
| 59 | + |
| 60 | +template <typename GfxFamily> |
| 61 | +size_t HardwareCommandsHelper<GfxFamily>::getSizeRequiredForCacheFlush(const CommandQueue &commandQueue, const Kernel *kernel, uint64_t postSyncAddress) { |
| 62 | + return kernel->requiresCacheFlushCommand(commandQueue) ? sizeof(typename GfxFamily::PIPE_CONTROL) : 0; |
| 63 | +} |
| 64 | + |
| 65 | +template <typename GfxFamily> |
| 66 | +void HardwareCommandsHelper<GfxFamily>::sendMediaStateFlush( |
| 67 | + LinearStream &commandStream, |
| 68 | + size_t offsetInterfaceDescriptorData) { |
| 69 | + |
| 70 | + typedef typename GfxFamily::MEDIA_STATE_FLUSH MEDIA_STATE_FLUSH; |
| 71 | + auto pCmd = (MEDIA_STATE_FLUSH *)commandStream.getSpace(sizeof(MEDIA_STATE_FLUSH)); |
| 72 | + *pCmd = GfxFamily::cmdInitMediaStateFlush; |
| 73 | + pCmd->setInterfaceDescriptorOffset((uint32_t)offsetInterfaceDescriptorData); |
| 74 | +} |
| 75 | + |
| 76 | +template <typename GfxFamily> |
| 77 | +void HardwareCommandsHelper<GfxFamily>::sendMediaInterfaceDescriptorLoad( |
| 78 | + LinearStream &commandStream, |
| 79 | + size_t offsetInterfaceDescriptorData, |
| 80 | + size_t sizeInterfaceDescriptorData) { |
| 81 | + { |
| 82 | + typedef typename GfxFamily::MEDIA_STATE_FLUSH MEDIA_STATE_FLUSH; |
| 83 | + auto pCmd = (MEDIA_STATE_FLUSH *)commandStream.getSpace(sizeof(MEDIA_STATE_FLUSH)); |
| 84 | + *pCmd = GfxFamily::cmdInitMediaStateFlush; |
| 85 | + } |
| 86 | + |
| 87 | + { |
| 88 | + typedef typename GfxFamily::MEDIA_INTERFACE_DESCRIPTOR_LOAD MEDIA_INTERFACE_DESCRIPTOR_LOAD; |
| 89 | + auto pCmd = (MEDIA_INTERFACE_DESCRIPTOR_LOAD *)commandStream.getSpace(sizeof(MEDIA_INTERFACE_DESCRIPTOR_LOAD)); |
| 90 | + *pCmd = GfxFamily::cmdInitMediaInterfaceDescriptorLoad; |
| 91 | + pCmd->setInterfaceDescriptorDataStartAddress((uint32_t)offsetInterfaceDescriptorData); |
| 92 | + pCmd->setInterfaceDescriptorTotalLength((uint32_t)sizeInterfaceDescriptorData); |
| 93 | + } |
| 94 | +} |
| 95 | + |
| 96 | +template <typename GfxFamily> |
| 97 | +void HardwareCommandsHelper<GfxFamily>::programPerThreadData( |
| 98 | + size_t &sizePerThreadData, |
| 99 | + const bool &localIdsGenerationByRuntime, |
| 100 | + LinearStream &ioh, |
| 101 | + uint32_t &simd, |
| 102 | + uint32_t &numChannels, |
| 103 | + const size_t localWorkSize[3], |
| 104 | + Kernel &kernel, |
| 105 | + size_t &sizePerThreadDataTotal, |
| 106 | + size_t &localWorkItems) { |
| 107 | + |
| 108 | + uint32_t grfSize = sizeof(typename GfxFamily::GRF); |
| 109 | + |
| 110 | + sendPerThreadData( |
| 111 | + ioh, |
| 112 | + simd, |
| 113 | + grfSize, |
| 114 | + numChannels, |
| 115 | + localWorkSize, |
| 116 | + kernel.getKernelInfo().workgroupDimensionsOrder, |
| 117 | + kernel.usesOnlyImages()); |
| 118 | + |
| 119 | + updatePerThreadDataTotal(sizePerThreadData, simd, numChannels, sizePerThreadDataTotal, localWorkItems); |
| 120 | +} |
| 121 | + |
| 122 | +template <typename GfxFamily> |
| 123 | +size_t HardwareCommandsHelper<GfxFamily>::sendCrossThreadData( |
| 124 | + IndirectHeap &indirectHeap, |
| 125 | + Kernel &kernel, |
| 126 | + bool inlineDataProgrammingRequired, |
| 127 | + WALKER_TYPE<GfxFamily> *walkerCmd, |
| 128 | + uint32_t &sizeCrossThreadData) { |
| 129 | + indirectHeap.align(WALKER_TYPE<GfxFamily>::INDIRECTDATASTARTADDRESS_ALIGN_SIZE); |
| 130 | + |
| 131 | + auto offsetCrossThreadData = indirectHeap.getUsed(); |
| 132 | + char *pDest = static_cast<char *>(indirectHeap.getSpace(sizeCrossThreadData)); |
| 133 | + memcpy_s(pDest, sizeCrossThreadData, kernel.getCrossThreadData(), sizeCrossThreadData); |
| 134 | + |
| 135 | + if (DebugManager.flags.AddPatchInfoCommentsForAUBDump.get()) { |
| 136 | + FlatBatchBufferHelper::fixCrossThreadDataInfo(kernel.getPatchInfoDataList(), offsetCrossThreadData, indirectHeap.getGraphicsAllocation()->getGpuAddress()); |
| 137 | + } |
| 138 | + |
| 139 | + return offsetCrossThreadData + static_cast<size_t>(indirectHeap.getHeapGpuStartOffset()); |
| 140 | +} |
| 141 | + |
| 142 | +template <typename GfxFamily> |
| 143 | +bool HardwareCommandsHelper<GfxFamily>::resetBindingTablePrefetch(Kernel &kernel) { |
| 144 | + return kernel.isSchedulerKernel || !doBindingTablePrefetch(); |
| 145 | +} |
| 146 | + |
| 147 | +template <typename GfxFamily> |
| 148 | +void HardwareCommandsHelper<GfxFamily>::setInterfaceDescriptorOffset( |
| 149 | + WALKER_TYPE<GfxFamily> *walkerCmd, |
| 150 | + uint32_t &interfaceDescriptorIndex) { |
| 151 | + |
| 152 | + walkerCmd->setInterfaceDescriptorOffset(interfaceDescriptorIndex++); |
| 153 | +} |
| 154 | + |
| 155 | +template <typename GfxFamily> |
| 156 | +void HardwareCommandsHelper<GfxFamily>::programCacheFlushAfterWalkerCommand(LinearStream *commandStream, const CommandQueue &commandQueue, const Kernel *kernel, uint64_t postSyncAddress) { |
| 157 | + using PIPE_CONTROL = typename GfxFamily::PIPE_CONTROL; |
| 158 | + auto pipeControl = reinterpret_cast<PIPE_CONTROL *>(commandStream->getSpace(sizeof(PIPE_CONTROL))); |
| 159 | + *pipeControl = GfxFamily::cmdInitPipeControl; |
| 160 | + pipeControl->setCommandStreamerStallEnable(true); |
| 161 | + pipeControl->setDcFlushEnable(true); |
| 162 | +} |
| 163 | + |
| 164 | +template <typename GfxFamily> |
| 165 | +void HardwareCommandsHelper<GfxFamily>::programBarrierEnable(INTERFACE_DESCRIPTOR_DATA *pInterfaceDescriptor, uint32_t value, const HardwareInfo &hwInfo) { |
| 166 | + pInterfaceDescriptor->setBarrierEnable(value); |
| 167 | +} |
| 168 | + |
| 169 | +template <typename GfxFamily> |
| 170 | +void HardwareCommandsHelper<GfxFamily>::adjustInterfaceDescriptorData(INTERFACE_DESCRIPTOR_DATA *pInterfaceDescriptor, const HardwareInfo &hwInfo) {} |
| 171 | +} // namespace NEO |
0 commit comments