2018-03-30 23:57:51 +08:00
|
|
|
/*
|
2020-01-28 00:28:10 +08:00
|
|
|
* Copyright (C) 2018-2020 Intel Corporation
|
2018-03-30 23:57:51 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2018-03-30 23:57:51 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-02-24 20:10:44 +08:00
|
|
|
#include "shared/source/built_ins/built_ins.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/command_stream/linear_stream.h"
|
|
|
|
#include "shared/source/command_stream/preemption.h"
|
|
|
|
#include "shared/source/helpers/register_offsets.h"
|
|
|
|
#include "shared/source/helpers/timestamp_packet.h"
|
|
|
|
#include "shared/source/helpers/vec.h"
|
|
|
|
#include "shared/source/indirect_heap/indirect_heap.h"
|
|
|
|
#include "shared/source/utilities/tag_allocator.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2020-02-23 05:50:57 +08:00
|
|
|
#include "opencl/source/command_queue/command_queue.h"
|
|
|
|
#include "opencl/source/context/context.h"
|
|
|
|
#include "opencl/source/device_queue/device_queue_hw.h"
|
|
|
|
#include "opencl/source/event/hw_timestamps.h"
|
|
|
|
#include "opencl/source/event/perf_counter.h"
|
|
|
|
#include "opencl/source/helpers/dispatch_info.h"
|
|
|
|
#include "opencl/source/helpers/hardware_commands_helper.h"
|
|
|
|
#include "opencl/source/helpers/task_information.h"
|
|
|
|
#include "opencl/source/kernel/kernel.h"
|
|
|
|
#include "opencl/source/program/kernel_info.h"
|
2018-03-30 23:57:51 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2018-03-30 23:57:51 +08:00
|
|
|
|
2020-02-05 20:53:29 +08:00
|
|
|
struct RootDeviceEnvironment;
|
|
|
|
|
2018-08-24 21:53:33 +08:00
|
|
|
template <typename GfxFamily>
|
|
|
|
using WALKER_TYPE = typename GfxFamily::WALKER_TYPE;
|
2018-12-27 23:01:22 +08:00
|
|
|
template <typename GfxFamily>
|
|
|
|
using MI_STORE_REG_MEM = typename GfxFamily::MI_STORE_REGISTER_MEM_CMD;
|
2018-08-24 21:53:33 +08:00
|
|
|
|
2018-03-30 23:57:51 +08:00
|
|
|
void computeWorkgroupSize1D(
|
|
|
|
uint32_t maxWorkGroupSize,
|
|
|
|
size_t workGroupSize[3],
|
|
|
|
const size_t workItems[3],
|
|
|
|
size_t simdSize);
|
|
|
|
|
|
|
|
void computeWorkgroupSizeND(
|
|
|
|
WorkSizeInfo wsInfo,
|
|
|
|
size_t workGroupSize[3],
|
|
|
|
const size_t workItems[3],
|
|
|
|
const uint32_t workDim);
|
|
|
|
|
|
|
|
void computeWorkgroupSize2D(
|
|
|
|
uint32_t maxWorkGroupSize,
|
|
|
|
size_t workGroupSize[3],
|
|
|
|
const size_t workItems[3],
|
|
|
|
size_t simdSize);
|
|
|
|
|
|
|
|
void computeWorkgroupSizeSquared(
|
|
|
|
uint32_t maxWorkGroupSize,
|
|
|
|
size_t workGroupSize[3],
|
|
|
|
const size_t workItems[3],
|
|
|
|
size_t simdSize,
|
|
|
|
const uint32_t workDim);
|
|
|
|
|
|
|
|
Vec3<size_t> computeWorkgroupSize(
|
|
|
|
const DispatchInfo &dispatchInfo);
|
|
|
|
|
|
|
|
Vec3<size_t> generateWorkgroupSize(
|
|
|
|
const DispatchInfo &dispatchInfo);
|
|
|
|
|
|
|
|
Vec3<size_t> computeWorkgroupsNumber(
|
|
|
|
const Vec3<size_t> gws,
|
|
|
|
const Vec3<size_t> lws);
|
|
|
|
|
|
|
|
Vec3<size_t> generateWorkgroupsNumber(
|
|
|
|
const Vec3<size_t> gws,
|
|
|
|
const Vec3<size_t> lws);
|
|
|
|
|
|
|
|
Vec3<size_t> generateWorkgroupsNumber(
|
|
|
|
const DispatchInfo &dispatchInfo);
|
|
|
|
|
|
|
|
inline uint32_t calculateDispatchDim(Vec3<size_t> dispatchSize, Vec3<size_t> dispatchOffset) {
|
|
|
|
return std::max(1U, std::max(dispatchSize.getSimplifiedDim(), dispatchOffset.getSimplifiedDim()));
|
|
|
|
}
|
|
|
|
|
|
|
|
Vec3<size_t> canonizeWorkgroup(
|
|
|
|
Vec3<size_t> workgroup);
|
|
|
|
|
2019-09-13 19:41:40 +08:00
|
|
|
void provideLocalWorkGroupSizeHints(Context *context, DispatchInfo dispatchInfo);
|
2018-03-30 23:57:51 +08:00
|
|
|
|
2020-05-07 19:51:31 +08:00
|
|
|
void setSpecialWorkgroupSize(size_t workgroupSize[3]);
|
|
|
|
|
2018-03-30 23:57:51 +08:00
|
|
|
inline cl_uint computeDimensions(const size_t workItems[3]) {
|
|
|
|
return (workItems[2] > 1) ? 3 : (workItems[1] > 1) ? 2 : 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
class GpgpuWalkerHelper {
|
|
|
|
public:
|
|
|
|
static void applyWADisableLSQCROPERFforOCL(LinearStream *pCommandStream,
|
|
|
|
const Kernel &kernel,
|
|
|
|
bool disablePerfMode);
|
|
|
|
|
|
|
|
static size_t getSizeForWADisableLSQCROPERFforOCL(const Kernel *pKernel);
|
|
|
|
|
|
|
|
static size_t setGpgpuWalkerThreadData(
|
2018-09-28 22:16:18 +08:00
|
|
|
WALKER_TYPE<GfxFamily> *walkerCmd,
|
2018-03-30 23:57:51 +08:00
|
|
|
const size_t globalOffsets[3],
|
|
|
|
const size_t startWorkGroups[3],
|
|
|
|
const size_t numWorkGroups[3],
|
|
|
|
const size_t localWorkSizesIn[3],
|
2018-09-26 20:56:01 +08:00
|
|
|
uint32_t simd,
|
|
|
|
uint32_t workDim,
|
2018-10-03 21:13:54 +08:00
|
|
|
bool localIdsGenerationByRuntime,
|
2018-10-18 12:38:18 +08:00
|
|
|
bool inlineDataProgrammingRequired,
|
2019-07-02 18:58:22 +08:00
|
|
|
const iOpenCL::SPatchThreadPayload &threadPayload,
|
|
|
|
uint32_t requiredWorkgroupOrder);
|
2018-03-30 23:57:51 +08:00
|
|
|
|
|
|
|
static void dispatchProfilingCommandsStart(
|
2018-12-21 20:05:21 +08:00
|
|
|
TagNode<HwTimeStamps> &hwTimeStamps,
|
2019-08-14 15:33:51 +08:00
|
|
|
LinearStream *commandStream,
|
|
|
|
const HardwareInfo &hwInfo);
|
2018-03-30 23:57:51 +08:00
|
|
|
|
|
|
|
static void dispatchProfilingCommandsEnd(
|
2018-12-21 20:05:21 +08:00
|
|
|
TagNode<HwTimeStamps> &hwTimeStamps,
|
2019-04-18 18:25:29 +08:00
|
|
|
LinearStream *commandStream);
|
2018-03-30 23:57:51 +08:00
|
|
|
|
|
|
|
static void dispatchPerfCountersCommandsStart(
|
|
|
|
CommandQueue &commandQueue,
|
2019-04-18 18:25:29 +08:00
|
|
|
TagNode<HwPerfCounter> &hwPerfCounter,
|
|
|
|
LinearStream *commandStream);
|
2018-03-30 23:57:51 +08:00
|
|
|
|
|
|
|
static void dispatchPerfCountersCommandsEnd(
|
|
|
|
CommandQueue &commandQueue,
|
2019-04-18 18:25:29 +08:00
|
|
|
TagNode<HwPerfCounter> &hwPerfCounter,
|
|
|
|
LinearStream *commandStream);
|
2018-03-30 23:57:51 +08:00
|
|
|
|
2018-08-24 14:48:59 +08:00
|
|
|
static void setupTimestampPacket(
|
|
|
|
LinearStream *cmdStream,
|
2018-09-28 22:16:18 +08:00
|
|
|
WALKER_TYPE<GfxFamily> *walkerCmd,
|
2019-04-16 20:07:50 +08:00
|
|
|
TagNode<TimestampPacketStorage> *timestampPacketNode,
|
2019-08-14 15:33:51 +08:00
|
|
|
TimestampPacketStorage::WriteOperationType writeOperationType,
|
2020-02-05 20:53:29 +08:00
|
|
|
const RootDeviceEnvironment &rootDeviceEnvironment);
|
2018-08-24 14:48:59 +08:00
|
|
|
|
2018-03-30 23:57:51 +08:00
|
|
|
static void dispatchScheduler(
|
2019-02-25 16:42:15 +08:00
|
|
|
LinearStream &commandStream,
|
2018-03-30 23:57:51 +08:00
|
|
|
DeviceQueueHw<GfxFamily> &devQueueHw,
|
|
|
|
PreemptionMode preemptionMode,
|
2018-04-05 21:12:28 +08:00
|
|
|
SchedulerKernel &scheduler,
|
|
|
|
IndirectHeap *ssh,
|
2019-11-13 22:37:52 +08:00
|
|
|
IndirectHeap *dsh,
|
|
|
|
bool isCcsUsed);
|
2018-09-07 15:09:24 +08:00
|
|
|
|
2018-12-27 23:01:22 +08:00
|
|
|
static void adjustMiStoreRegMemMode(MI_STORE_REG_MEM<GfxFamily> *storeCmd);
|
2019-04-18 18:25:29 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
using PIPE_CONTROL = typename GfxFamily::PIPE_CONTROL;
|
|
|
|
|
|
|
|
static void addAluReadModifyWriteRegister(
|
|
|
|
LinearStream *pCommandStream,
|
|
|
|
uint32_t aluRegister,
|
2020-02-26 02:23:04 +08:00
|
|
|
AluRegisters operation,
|
2019-04-18 18:25:29 +08:00
|
|
|
uint32_t mask);
|
2018-03-30 23:57:51 +08:00
|
|
|
};
|
|
|
|
|
2018-04-09 22:39:32 +08:00
|
|
|
template <typename GfxFamily>
|
2018-03-30 23:57:51 +08:00
|
|
|
struct EnqueueOperation {
|
2018-08-24 14:48:59 +08:00
|
|
|
using PIPE_CONTROL = typename GfxFamily::PIPE_CONTROL;
|
2019-07-03 15:30:30 +08:00
|
|
|
static size_t getTotalSizeRequiredCS(uint32_t eventType, const CsrDependencies &csrDeps, bool reserveProfilingCmdsSpace, bool reservePerfCounters, bool blitEnqueue, CommandQueue &commandQueue, const MultiDispatchInfo &multiDispatchInfo);
|
2018-04-09 22:39:32 +08:00
|
|
|
static size_t getSizeRequiredCS(uint32_t cmdType, bool reserveProfilingCmdsSpace, bool reservePerfCounters, CommandQueue &commandQueue, const Kernel *pKernel);
|
2018-09-06 16:01:51 +08:00
|
|
|
static size_t getSizeRequiredForTimestampPacketWrite();
|
2020-08-19 17:06:01 +08:00
|
|
|
static size_t getSizeForCacheFlushAfterWalkerCommands(const Kernel &kernel, const CommandQueue &commandQueue);
|
2018-03-30 23:57:51 +08:00
|
|
|
|
2018-04-09 22:39:32 +08:00
|
|
|
private:
|
|
|
|
static size_t getSizeRequiredCSKernel(bool reserveProfilingCmdsSpace, bool reservePerfCounters, CommandQueue &commandQueue, const Kernel *pKernel);
|
|
|
|
static size_t getSizeRequiredCSNonKernel(bool reserveProfilingCmdsSpace, bool reservePerfCounters, CommandQueue &commandQueue);
|
2018-03-30 23:57:51 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename GfxFamily, uint32_t eventType>
|
2019-07-18 22:14:41 +08:00
|
|
|
LinearStream &getCommandStream(CommandQueue &commandQueue, const CsrDependencies &csrDeps, bool reserveProfilingCmdsSpace,
|
|
|
|
bool reservePerfCounterCmdsSpace, bool blitEnqueue, const MultiDispatchInfo &multiDispatchInfo,
|
|
|
|
Surface **surfaces, size_t numSurfaces) {
|
2019-07-03 15:30:30 +08:00
|
|
|
size_t expectedSizeCS = EnqueueOperation<GfxFamily>::getTotalSizeRequiredCS(eventType, csrDeps, reserveProfilingCmdsSpace, reservePerfCounterCmdsSpace, blitEnqueue, commandQueue, multiDispatchInfo);
|
2018-03-30 23:57:51 +08:00
|
|
|
return commandQueue.getCS(expectedSizeCS);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename GfxFamily, IndirectHeap::Type heapType>
|
|
|
|
IndirectHeap &getIndirectHeap(CommandQueue &commandQueue, const MultiDispatchInfo &multiDispatchInfo) {
|
|
|
|
size_t expectedSize = 0;
|
|
|
|
IndirectHeap *ih = nullptr;
|
|
|
|
|
|
|
|
// clang-format off
|
|
|
|
switch (heapType) {
|
2019-06-12 15:13:06 +08:00
|
|
|
case IndirectHeap::DYNAMIC_STATE: expectedSize = HardwareCommandsHelper<GfxFamily>::getTotalSizeRequiredDSH(multiDispatchInfo); break;
|
|
|
|
case IndirectHeap::INDIRECT_OBJECT: expectedSize = HardwareCommandsHelper<GfxFamily>::getTotalSizeRequiredIOH(multiDispatchInfo); break;
|
|
|
|
case IndirectHeap::SURFACE_STATE: expectedSize = HardwareCommandsHelper<GfxFamily>::getTotalSizeRequiredSSH(multiDispatchInfo); break;
|
2018-03-30 23:57:51 +08:00
|
|
|
}
|
|
|
|
// clang-format on
|
|
|
|
|
2018-08-16 21:47:25 +08:00
|
|
|
if (Kernel *parentKernel = multiDispatchInfo.peekParentKernel()) {
|
2018-03-30 23:57:51 +08:00
|
|
|
if (heapType == IndirectHeap::SURFACE_STATE) {
|
2019-12-17 17:43:19 +08:00
|
|
|
expectedSize += HardwareCommandsHelper<GfxFamily>::getSshSizeForExecutionModel(*parentKernel);
|
2018-03-30 23:57:51 +08:00
|
|
|
} else //if (heapType == IndirectHeap::DYNAMIC_STATE || heapType == IndirectHeap::INDIRECT_OBJECT)
|
|
|
|
{
|
|
|
|
DeviceQueueHw<GfxFamily> *pDevQueue = castToObject<DeviceQueueHw<GfxFamily>>(commandQueue.getContext().getDefaultDeviceQueue());
|
|
|
|
DEBUG_BREAK_IF(pDevQueue == nullptr);
|
|
|
|
ih = pDevQueue->getIndirectHeap(IndirectHeap::DYNAMIC_STATE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ih == nullptr)
|
|
|
|
ih = &commandQueue.getIndirectHeap(heapType, expectedSize);
|
|
|
|
|
|
|
|
return *ih;
|
|
|
|
}
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|