2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2018-09-18 15:11:08 +08:00
|
|
|
* Copyright (C) 2017-2018 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#include "runtime/built_ins/built_ins.h"
|
|
|
|
#include "runtime/device_queue/device_queue.h"
|
|
|
|
#include "runtime/helpers/basic_math.h"
|
|
|
|
#include "runtime/helpers/per_thread_data.h"
|
|
|
|
#include "runtime/indirect_heap/indirect_heap.h"
|
|
|
|
#include "runtime/kernel/kernel.h"
|
2018-04-18 20:59:28 +08:00
|
|
|
#include "runtime/scheduler/scheduler_kernel.h"
|
|
|
|
#include <algorithm>
|
2017-12-21 07:45:38 +08:00
|
|
|
#include <cstdint>
|
|
|
|
#include <cstddef>
|
|
|
|
|
|
|
|
namespace OCLRT {
|
|
|
|
|
|
|
|
class LinearStream;
|
|
|
|
class IndirectHeap;
|
|
|
|
struct CrossThreadInfo;
|
|
|
|
struct MultiDispatchInfo;
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
struct KernelCommandsHelper : public PerThreadDataHelper {
|
2018-05-11 19:33:16 +08:00
|
|
|
using BINDING_TABLE_STATE = typename GfxFamily::BINDING_TABLE_STATE;
|
|
|
|
using RENDER_SURFACE_STATE = typename GfxFamily::RENDER_SURFACE_STATE;
|
|
|
|
using INTERFACE_DESCRIPTOR_DATA = typename GfxFamily::INTERFACE_DESCRIPTOR_DATA;
|
2018-09-26 06:44:43 +08:00
|
|
|
using MI_ATOMIC = typename GfxFamily::MI_ATOMIC;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
static uint32_t computeSlmValues(uint32_t valueIn);
|
|
|
|
|
|
|
|
static size_t sendInterfaceDescriptorData(
|
|
|
|
const IndirectHeap &indirectHeap,
|
|
|
|
uint64_t offsetInterfaceDescriptor,
|
|
|
|
uint64_t kernelStartOffset,
|
|
|
|
size_t sizeCrossThreadData,
|
|
|
|
size_t sizePerThreadData,
|
|
|
|
size_t bindingTablePointer,
|
|
|
|
size_t offsetSamplerState,
|
|
|
|
uint32_t numSamplers,
|
|
|
|
uint32_t threadsPerThreadGroup,
|
|
|
|
uint32_t sizeSlm,
|
2018-08-13 21:05:59 +08:00
|
|
|
uint32_t bindingTablePrefetchSize,
|
2018-03-02 05:43:04 +08:00
|
|
|
bool barrierEnable,
|
2018-05-11 19:33:16 +08:00
|
|
|
PreemptionMode preemptionMode,
|
|
|
|
INTERFACE_DESCRIPTOR_DATA *inlineInterfaceDescriptor);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
static void sendMediaStateFlush(
|
|
|
|
LinearStream &commandStream,
|
|
|
|
size_t offsetInterfaceDescriptorData);
|
|
|
|
|
|
|
|
static void sendMediaInterfaceDescriptorLoad(
|
|
|
|
LinearStream &commandStream,
|
|
|
|
size_t offsetInterfaceDescriptorData,
|
|
|
|
size_t sizeInterfaceDescriptorData);
|
|
|
|
|
|
|
|
static size_t sendCrossThreadData(
|
|
|
|
IndirectHeap &indirectHeap,
|
2018-03-14 18:07:51 +08:00
|
|
|
Kernel &kernel);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
static size_t pushBindingTableAndSurfaceStates(IndirectHeap &dstHeap, const KernelInfo &srcKernelInfo,
|
2018-02-08 23:00:20 +08:00
|
|
|
const void *srcKernelSsh, size_t srcKernelSshSize,
|
|
|
|
size_t numberOfBindingTableStates, size_t offsetOfBindingTable);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
static size_t pushBindingTableAndSurfaceStates(IndirectHeap &dstHeap, const KernelInfo &srcKernelInfo) {
|
|
|
|
return pushBindingTableAndSurfaceStates(dstHeap, srcKernelInfo, srcKernelInfo.heapInfo.pSsh,
|
2018-02-08 23:00:20 +08:00
|
|
|
srcKernelInfo.heapInfo.pKernelHeader->SurfaceStateHeapSize,
|
|
|
|
(srcKernelInfo.patchInfo.bindingTableState != nullptr) ? srcKernelInfo.patchInfo.bindingTableState->Count : 0,
|
|
|
|
(srcKernelInfo.patchInfo.bindingTableState != nullptr) ? srcKernelInfo.patchInfo.bindingTableState->Offset : 0);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static size_t pushBindingTableAndSurfaceStates(IndirectHeap &dstHeap, const Kernel &srcKernel) {
|
|
|
|
return pushBindingTableAndSurfaceStates(dstHeap, srcKernel.getKernelInfo(),
|
2018-02-08 23:00:20 +08:00
|
|
|
srcKernel.getSurfaceStateHeap(), srcKernel.getSurfaceStateHeapSize(),
|
|
|
|
srcKernel.getNumberOfBindingTableStates(), srcKernel.getBindingTableOffset());
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static size_t sendIndirectState(
|
|
|
|
LinearStream &commandStream,
|
|
|
|
IndirectHeap &dsh,
|
|
|
|
IndirectHeap &ioh,
|
|
|
|
IndirectHeap &ssh,
|
2018-03-14 18:07:51 +08:00
|
|
|
Kernel &kernel,
|
2017-12-21 07:45:38 +08:00
|
|
|
uint32_t simd,
|
|
|
|
const size_t localWorkSize[3],
|
|
|
|
const uint64_t offsetInterfaceDescriptorTable,
|
2018-03-02 05:43:04 +08:00
|
|
|
const uint32_t interfaceDescriptorIndex,
|
2018-05-11 19:33:16 +08:00
|
|
|
PreemptionMode preemptionMode,
|
2018-09-25 02:53:35 +08:00
|
|
|
INTERFACE_DESCRIPTOR_DATA *inlineInterfaceDescriptor,
|
|
|
|
bool localIdsGeneration);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
static size_t getSizeRequiredCS();
|
|
|
|
static bool isPipeControlWArequired();
|
|
|
|
static size_t getSizeRequiredDSH(
|
|
|
|
const Kernel &kernel);
|
|
|
|
static size_t getSizeRequiredIOH(
|
|
|
|
const Kernel &kernel,
|
|
|
|
size_t localWorkSize = 256);
|
|
|
|
static size_t getSizeRequiredSSH(
|
|
|
|
const Kernel &kernel);
|
|
|
|
|
|
|
|
static size_t getTotalSizeRequiredDSH(
|
|
|
|
const MultiDispatchInfo &multiDispatchInfo);
|
|
|
|
static size_t getTotalSizeRequiredIOH(
|
2018-02-13 22:43:33 +08:00
|
|
|
const MultiDispatchInfo &multiDispatchInfo);
|
2017-12-21 07:45:38 +08:00
|
|
|
static size_t getTotalSizeRequiredSSH(
|
|
|
|
const MultiDispatchInfo &multiDispatchInfo);
|
|
|
|
|
|
|
|
template <IndirectHeap::Type heapType>
|
|
|
|
static size_t getSizeRequiredForExecutionModel(const Kernel &kernel) {
|
|
|
|
typedef typename GfxFamily::BINDING_TABLE_STATE BINDING_TABLE_STATE;
|
|
|
|
|
|
|
|
size_t totalSize = 0;
|
2018-03-29 01:21:07 +08:00
|
|
|
BlockKernelManager *blockManager = kernel.getProgram()->getBlockKernelManager();
|
|
|
|
uint32_t blockCount = static_cast<uint32_t>(blockManager->getCount());
|
|
|
|
uint32_t maxBindingTableCount = 0;
|
|
|
|
|
|
|
|
if (heapType == IndirectHeap::SURFACE_STATE) {
|
|
|
|
totalSize = BINDING_TABLE_STATE::SURFACESTATEPOINTER_ALIGN_SIZE - 1;
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < blockCount; i++) {
|
|
|
|
const KernelInfo *pBlockInfo = blockManager->getBlockKernelInfo(i);
|
|
|
|
totalSize += pBlockInfo->heapInfo.pKernelHeader->SurfaceStateHeapSize;
|
|
|
|
totalSize = alignUp(totalSize, BINDING_TABLE_STATE::SURFACESTATEPOINTER_ALIGN_SIZE);
|
|
|
|
|
|
|
|
maxBindingTableCount = std::max(maxBindingTableCount, pBlockInfo->patchInfo.bindingTableState->Count);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
2018-03-29 01:21:07 +08:00
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-03-29 01:21:07 +08:00
|
|
|
if (heapType == IndirectHeap::INDIRECT_OBJECT || heapType == IndirectHeap::SURFACE_STATE) {
|
2018-08-22 19:57:21 +08:00
|
|
|
BuiltIns &builtIns = *kernel.getDevice().getExecutionEnvironment()->getBuiltIns();
|
2018-03-29 01:21:07 +08:00
|
|
|
SchedulerKernel &scheduler = builtIns.getSchedulerKernel(kernel.getContext());
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-03-29 01:21:07 +08:00
|
|
|
if (heapType == IndirectHeap::INDIRECT_OBJECT) {
|
|
|
|
totalSize += getSizeRequiredIOH(scheduler);
|
|
|
|
} else {
|
|
|
|
totalSize += getSizeRequiredSSH(scheduler);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-03-29 01:21:07 +08:00
|
|
|
totalSize += maxBindingTableCount * sizeof(BINDING_TABLE_STATE) * DeviceQueue::interfaceDescriptorEntries;
|
|
|
|
totalSize = alignUp(totalSize, BINDING_TABLE_STATE::SURFACESTATEPOINTER_ALIGN_SIZE);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return totalSize;
|
|
|
|
}
|
|
|
|
|
2018-09-11 16:15:54 +08:00
|
|
|
static void programMiSemaphoreWait(LinearStream &commandStream, uint64_t compareAddress, uint32_t compareData);
|
2018-09-26 06:44:43 +08:00
|
|
|
static MI_ATOMIC *programMiAtomic(LinearStream &commandStream, uint64_t writeAddress, typename MI_ATOMIC::ATOMIC_OPCODES opcode, typename MI_ATOMIC::DATA_SIZE dataSize);
|
2018-09-11 16:15:54 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
static const size_t alignInterfaceDescriptorData = 64 * sizeof(uint8_t);
|
|
|
|
static const uint32_t alignIndirectStatePointer = 64 * sizeof(uint8_t);
|
2018-09-17 17:24:21 +08:00
|
|
|
|
|
|
|
static bool doBindingTablePrefetch();
|
2018-09-25 02:53:35 +08:00
|
|
|
|
|
|
|
static bool isDispatchForLocalIdsGeneration(uint32_t workDim, size_t *gws, size_t *lws);
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
} // namespace OCLRT
|