2018-10-04 21:01:52 +08:00
|
|
|
/*
|
2020-01-23 22:52:49 +08:00
|
|
|
* Copyright (C) 2018-2020 Intel Corporation
|
2018-10-04 21:01:52 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/helpers/hw_helper.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2020-02-23 05:50:57 +08:00
|
|
|
#include "opencl/source/helpers/hardware_commands_helper.h"
|
|
|
|
#include "opencl/source/kernel/kernel.h"
|
2018-10-04 21:01:52 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2018-10-04 21:01:52 +08:00
|
|
|
|
2020-02-08 05:48:09 +08:00
|
|
|
template <typename GfxFamily>
|
|
|
|
bool HardwareCommandsHelper<GfxFamily>::isPipeControlWArequired(const HardwareInfo &hwInfo) { return false; }
|
|
|
|
|
2018-10-04 21:01:52 +08:00
|
|
|
template <typename GfxFamily>
|
2019-06-12 15:13:06 +08:00
|
|
|
typename HardwareCommandsHelper<GfxFamily>::INTERFACE_DESCRIPTOR_DATA *HardwareCommandsHelper<GfxFamily>::getInterfaceDescriptor(
|
2018-10-04 21:01:52 +08:00
|
|
|
const IndirectHeap &indirectHeap,
|
|
|
|
uint64_t offsetInterfaceDescriptor,
|
2019-06-12 15:13:06 +08:00
|
|
|
HardwareCommandsHelper<GfxFamily>::INTERFACE_DESCRIPTOR_DATA *inlineInterfaceDescriptor) {
|
2018-10-04 21:01:52 +08:00
|
|
|
return static_cast<INTERFACE_DESCRIPTOR_DATA *>(ptrOffset(indirectHeap.getCpuBase(), (size_t)offsetInterfaceDescriptor));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2019-06-12 15:13:06 +08:00
|
|
|
void HardwareCommandsHelper<GfxFamily>::setAdditionalInfo(
|
2018-10-04 21:01:52 +08:00
|
|
|
INTERFACE_DESCRIPTOR_DATA *pInterfaceDescriptor,
|
2019-09-20 20:55:06 +08:00
|
|
|
const Kernel &kernel,
|
2018-10-04 21:01:52 +08:00
|
|
|
const size_t &sizeCrossThreadData,
|
2019-10-09 15:30:14 +08:00
|
|
|
const size_t &sizePerThreadData,
|
|
|
|
const uint32_t threadsPerThreadGroup) {
|
2019-12-17 15:55:09 +08:00
|
|
|
auto grfSize = sizeof(typename GfxFamily::GRF);
|
|
|
|
DEBUG_BREAK_IF((sizeCrossThreadData % grfSize) != 0);
|
|
|
|
auto numGrfCrossThreadData = static_cast<uint32_t>(sizeCrossThreadData / grfSize);
|
2018-10-04 21:01:52 +08:00
|
|
|
DEBUG_BREAK_IF(numGrfCrossThreadData == 0);
|
|
|
|
pInterfaceDescriptor->setCrossThreadConstantDataReadLength(numGrfCrossThreadData);
|
|
|
|
|
2019-12-17 15:55:09 +08:00
|
|
|
DEBUG_BREAK_IF((sizePerThreadData % grfSize) != 0);
|
|
|
|
auto numGrfPerThreadData = static_cast<uint32_t>(sizePerThreadData / grfSize);
|
2018-10-04 21:01:52 +08:00
|
|
|
|
|
|
|
// at least 1 GRF of perThreadData for each thread in a thread group when sizeCrossThreadData != 0
|
|
|
|
numGrfPerThreadData = std::max(numGrfPerThreadData, 1u);
|
|
|
|
pInterfaceDescriptor->setConstantIndirectUrbEntryReadLength(numGrfPerThreadData);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2019-06-12 15:13:06 +08:00
|
|
|
uint32_t HardwareCommandsHelper<GfxFamily>::additionalSizeRequiredDsh() {
|
2018-10-04 21:01:52 +08:00
|
|
|
return sizeof(INTERFACE_DESCRIPTOR_DATA);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2019-06-12 15:13:06 +08:00
|
|
|
size_t HardwareCommandsHelper<GfxFamily>::getSizeRequiredCS(const Kernel *kernel) {
|
2018-12-06 22:33:02 +08:00
|
|
|
size_t size = 2 * sizeof(typename GfxFamily::MEDIA_STATE_FLUSH) +
|
|
|
|
sizeof(typename GfxFamily::MEDIA_INTERFACE_DESCRIPTOR_LOAD);
|
|
|
|
return size;
|
2018-10-04 21:01:52 +08:00
|
|
|
}
|
|
|
|
|
2019-01-31 21:47:55 +08:00
|
|
|
template <typename GfxFamily>
|
2019-06-27 19:58:18 +08:00
|
|
|
size_t HardwareCommandsHelper<GfxFamily>::getSizeRequiredForCacheFlush(const CommandQueue &commandQueue, const Kernel *kernel, uint64_t postSyncAddress) {
|
2019-02-11 00:50:54 +08:00
|
|
|
return kernel->requiresCacheFlushCommand(commandQueue) ? sizeof(typename GfxFamily::PIPE_CONTROL) : 0;
|
2019-01-31 21:47:55 +08:00
|
|
|
}
|
|
|
|
|
2018-10-04 21:01:52 +08:00
|
|
|
template <typename GfxFamily>
|
2019-06-12 15:13:06 +08:00
|
|
|
void HardwareCommandsHelper<GfxFamily>::sendMediaStateFlush(
|
2018-10-04 21:01:52 +08:00
|
|
|
LinearStream &commandStream,
|
|
|
|
size_t offsetInterfaceDescriptorData) {
|
|
|
|
|
|
|
|
typedef typename GfxFamily::MEDIA_STATE_FLUSH MEDIA_STATE_FLUSH;
|
|
|
|
auto pCmd = (MEDIA_STATE_FLUSH *)commandStream.getSpace(sizeof(MEDIA_STATE_FLUSH));
|
|
|
|
*pCmd = GfxFamily::cmdInitMediaStateFlush;
|
|
|
|
pCmd->setInterfaceDescriptorOffset((uint32_t)offsetInterfaceDescriptorData);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2019-06-12 15:13:06 +08:00
|
|
|
void HardwareCommandsHelper<GfxFamily>::sendMediaInterfaceDescriptorLoad(
|
2018-10-04 21:01:52 +08:00
|
|
|
LinearStream &commandStream,
|
|
|
|
size_t offsetInterfaceDescriptorData,
|
|
|
|
size_t sizeInterfaceDescriptorData) {
|
|
|
|
{
|
|
|
|
typedef typename GfxFamily::MEDIA_STATE_FLUSH MEDIA_STATE_FLUSH;
|
|
|
|
auto pCmd = (MEDIA_STATE_FLUSH *)commandStream.getSpace(sizeof(MEDIA_STATE_FLUSH));
|
|
|
|
*pCmd = GfxFamily::cmdInitMediaStateFlush;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
typedef typename GfxFamily::MEDIA_INTERFACE_DESCRIPTOR_LOAD MEDIA_INTERFACE_DESCRIPTOR_LOAD;
|
|
|
|
auto pCmd = (MEDIA_INTERFACE_DESCRIPTOR_LOAD *)commandStream.getSpace(sizeof(MEDIA_INTERFACE_DESCRIPTOR_LOAD));
|
|
|
|
*pCmd = GfxFamily::cmdInitMediaInterfaceDescriptorLoad;
|
|
|
|
pCmd->setInterfaceDescriptorDataStartAddress((uint32_t)offsetInterfaceDescriptorData);
|
|
|
|
pCmd->setInterfaceDescriptorTotalLength((uint32_t)sizeInterfaceDescriptorData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2019-06-12 15:13:06 +08:00
|
|
|
void HardwareCommandsHelper<GfxFamily>::programPerThreadData(
|
2018-10-04 21:01:52 +08:00
|
|
|
size_t &sizePerThreadData,
|
|
|
|
const bool &localIdsGenerationByRuntime,
|
|
|
|
LinearStream &ioh,
|
|
|
|
uint32_t &simd,
|
|
|
|
uint32_t &numChannels,
|
|
|
|
const size_t localWorkSize[3],
|
|
|
|
Kernel &kernel,
|
|
|
|
size_t &sizePerThreadDataTotal,
|
|
|
|
size_t &localWorkItems) {
|
|
|
|
|
2019-12-17 15:55:09 +08:00
|
|
|
uint32_t grfSize = sizeof(typename GfxFamily::GRF);
|
|
|
|
|
2018-10-04 21:01:52 +08:00
|
|
|
sendPerThreadData(
|
|
|
|
ioh,
|
|
|
|
simd,
|
2019-12-17 15:55:09 +08:00
|
|
|
grfSize,
|
2018-10-04 21:01:52 +08:00
|
|
|
numChannels,
|
|
|
|
localWorkSize,
|
|
|
|
kernel.getKernelInfo().workgroupDimensionsOrder,
|
|
|
|
kernel.usesOnlyImages());
|
|
|
|
|
|
|
|
updatePerThreadDataTotal(sizePerThreadData, simd, numChannels, sizePerThreadDataTotal, localWorkItems);
|
|
|
|
}
|
|
|
|
|
2018-10-18 12:38:18 +08:00
|
|
|
template <typename GfxFamily>
|
2019-06-12 15:13:06 +08:00
|
|
|
size_t HardwareCommandsHelper<GfxFamily>::sendCrossThreadData(
|
2018-10-18 12:38:18 +08:00
|
|
|
IndirectHeap &indirectHeap,
|
|
|
|
Kernel &kernel,
|
|
|
|
bool inlineDataProgrammingRequired,
|
|
|
|
WALKER_TYPE<GfxFamily> *walkerCmd,
|
|
|
|
uint32_t &sizeCrossThreadData) {
|
|
|
|
indirectHeap.align(WALKER_TYPE<GfxFamily>::INDIRECTDATASTARTADDRESS_ALIGN_SIZE);
|
|
|
|
|
|
|
|
auto offsetCrossThreadData = indirectHeap.getUsed();
|
|
|
|
char *pDest = static_cast<char *>(indirectHeap.getSpace(sizeCrossThreadData));
|
|
|
|
memcpy_s(pDest, sizeCrossThreadData, kernel.getCrossThreadData(), sizeCrossThreadData);
|
|
|
|
|
|
|
|
if (DebugManager.flags.AddPatchInfoCommentsForAUBDump.get()) {
|
|
|
|
FlatBatchBufferHelper::fixCrossThreadDataInfo(kernel.getPatchInfoDataList(), offsetCrossThreadData, indirectHeap.getGraphicsAllocation()->getGpuAddress());
|
|
|
|
}
|
|
|
|
|
|
|
|
return offsetCrossThreadData + static_cast<size_t>(indirectHeap.getHeapGpuStartOffset());
|
|
|
|
}
|
|
|
|
|
2018-10-04 21:01:52 +08:00
|
|
|
template <typename GfxFamily>
|
2019-06-12 15:13:06 +08:00
|
|
|
bool HardwareCommandsHelper<GfxFamily>::resetBindingTablePrefetch(Kernel &kernel) {
|
2018-10-04 21:01:52 +08:00
|
|
|
return kernel.isSchedulerKernel || !doBindingTablePrefetch();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
2019-06-12 15:13:06 +08:00
|
|
|
void HardwareCommandsHelper<GfxFamily>::setInterfaceDescriptorOffset(
|
2018-10-04 21:01:52 +08:00
|
|
|
WALKER_TYPE<GfxFamily> *walkerCmd,
|
|
|
|
uint32_t &interfaceDescriptorIndex) {
|
|
|
|
|
|
|
|
walkerCmd->setInterfaceDescriptorOffset(interfaceDescriptorIndex++);
|
|
|
|
}
|
|
|
|
|
2018-12-06 22:33:02 +08:00
|
|
|
template <typename GfxFamily>
|
2019-06-27 14:52:04 +08:00
|
|
|
void HardwareCommandsHelper<GfxFamily>::programCacheFlushAfterWalkerCommand(LinearStream *commandStream, const CommandQueue &commandQueue, const Kernel *kernel, uint64_t postSyncAddress) {
|
2019-02-21 23:59:10 +08:00
|
|
|
using PIPE_CONTROL = typename GfxFamily::PIPE_CONTROL;
|
|
|
|
auto pipeControl = reinterpret_cast<PIPE_CONTROL *>(commandStream->getSpace(sizeof(PIPE_CONTROL)));
|
|
|
|
*pipeControl = GfxFamily::cmdInitPipeControl;
|
|
|
|
pipeControl->setCommandStreamerStallEnable(true);
|
|
|
|
pipeControl->setDcFlushEnable(true);
|
2018-12-06 22:33:02 +08:00
|
|
|
}
|
2019-06-11 14:31:38 +08:00
|
|
|
|
2019-10-11 15:17:06 +08:00
|
|
|
template <typename GfxFamily>
|
|
|
|
void HardwareCommandsHelper<GfxFamily>::programBarrierEnable(INTERFACE_DESCRIPTOR_DATA *pInterfaceDescriptor, uint32_t value, const HardwareInfo &hwInfo) {
|
|
|
|
pInterfaceDescriptor->setBarrierEnable(value);
|
|
|
|
}
|
|
|
|
|
2019-10-30 17:23:26 +08:00
|
|
|
template <typename GfxFamily>
|
|
|
|
void HardwareCommandsHelper<GfxFamily>::adjustInterfaceDescriptorData(INTERFACE_DESCRIPTOR_DATA *pInterfaceDescriptor, const HardwareInfo &hwInfo) {}
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|