2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2020-02-07 01:57:00 +08:00
|
|
|
* Copyright (C) 2018-2020 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
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/command_stream/preemption.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
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/device/device.h"
|
|
|
|
#include "shared/source/helpers/string.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2020-02-23 05:50:57 +08:00
|
|
|
#include "opencl/source/helpers/dispatch_info.h"
|
|
|
|
#include "opencl/source/kernel/kernel.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-11-25 23:45:52 +08:00
|
|
|
bool PreemptionHelper::allowThreadGroupPreemption(const PreemptionFlags &flags) {
|
|
|
|
if (flags.flags.disablePerCtxtPreemptionGranularityControl) {
|
2017-12-21 07:45:38 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-11-25 23:45:52 +08:00
|
|
|
if (flags.flags.usesFencesForReadWriteImages &&
|
|
|
|
flags.flags.disableLSQCROPERFforOCL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (flags.flags.schedulerKernel || flags.flags.vmeKernel) {
|
|
|
|
return false;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-11-25 23:45:52 +08:00
|
|
|
bool PreemptionHelper::allowMidThreadPreemption(const PreemptionFlags &flags) {
|
|
|
|
return (flags.flags.disabledMidThreadPreemptionKernel == 0) &&
|
|
|
|
!(flags.flags.vmeKernel && !flags.flags.deviceSupportsVmePreemption);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2019-11-27 19:59:47 +08:00
|
|
|
PreemptionMode PreemptionHelper::taskPreemptionMode(PreemptionMode devicePreemptionMode, const PreemptionFlags &flags) {
|
2020-04-30 23:07:07 +08:00
|
|
|
if (DebugManager.flags.ForceKernelPreemptionMode.get() != -1) {
|
|
|
|
return static_cast<PreemptionMode>(DebugManager.flags.ForceKernelPreemptionMode.get());
|
|
|
|
}
|
2019-11-27 19:59:47 +08:00
|
|
|
if (devicePreemptionMode == PreemptionMode::Disabled) {
|
2017-12-21 07:45:38 +08:00
|
|
|
return PreemptionMode::Disabled;
|
|
|
|
}
|
|
|
|
|
2019-11-27 19:59:47 +08:00
|
|
|
if (devicePreemptionMode >= PreemptionMode::MidThread &&
|
2019-11-25 23:45:52 +08:00
|
|
|
allowMidThreadPreemption(flags)) {
|
2017-12-21 07:45:38 +08:00
|
|
|
return PreemptionMode::MidThread;
|
|
|
|
}
|
|
|
|
|
2019-11-27 19:59:47 +08:00
|
|
|
if (devicePreemptionMode >= PreemptionMode::ThreadGroup &&
|
2019-11-25 23:45:52 +08:00
|
|
|
allowThreadGroupPreemption(flags)) {
|
2017-12-21 07:45:38 +08:00
|
|
|
return PreemptionMode::ThreadGroup;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PreemptionMode::MidBatch;
|
|
|
|
};
|
|
|
|
|
2019-11-25 23:45:52 +08:00
|
|
|
void PreemptionHelper::setPreemptionLevelFlags(PreemptionFlags &flags, Device &device, Kernel *kernel) {
|
|
|
|
if (kernel) {
|
|
|
|
flags.flags.disabledMidThreadPreemptionKernel =
|
|
|
|
kernel->getKernelInfo().patchInfo.executionEnvironment &&
|
|
|
|
kernel->getKernelInfo().patchInfo.executionEnvironment->DisableMidThreadPreemption;
|
|
|
|
flags.flags.vmeKernel = kernel->isVmeKernel();
|
|
|
|
flags.flags.usesFencesForReadWriteImages =
|
|
|
|
kernel->getKernelInfo().patchInfo.executionEnvironment &&
|
|
|
|
kernel->getKernelInfo().patchInfo.executionEnvironment->UsesFencesForReadWriteImages;
|
|
|
|
flags.flags.schedulerKernel = kernel->isSchedulerKernel;
|
|
|
|
}
|
|
|
|
flags.flags.deviceSupportsVmePreemption = device.getDeviceInfo().vmeAvcSupportsPreemption;
|
|
|
|
flags.flags.disablePerCtxtPreemptionGranularityControl = device.getHardwareInfo().workaroundTable.waDisablePerCtxtPreemptionGranularityControl;
|
|
|
|
flags.flags.disableLSQCROPERFforOCL = device.getHardwareInfo().workaroundTable.waDisableLSQCROPERFforOCL;
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
PreemptionMode PreemptionHelper::taskPreemptionMode(Device &device, const MultiDispatchInfo &multiDispatchInfo) {
|
|
|
|
PreemptionMode devMode = device.getPreemptionMode();
|
|
|
|
|
|
|
|
for (const auto &di : multiDispatchInfo) {
|
2019-11-25 23:45:52 +08:00
|
|
|
auto kernel = di.getKernel();
|
|
|
|
|
|
|
|
PreemptionFlags flags = {};
|
|
|
|
setPreemptionLevelFlags(flags, device, kernel);
|
|
|
|
|
2019-11-27 19:59:47 +08:00
|
|
|
PreemptionMode taskMode = taskPreemptionMode(devMode, flags);
|
2017-12-21 07:45:38 +08:00
|
|
|
if (devMode > taskMode) {
|
|
|
|
devMode = taskMode;
|
|
|
|
}
|
2020-09-25 17:24:15 +08:00
|
|
|
PRINT_DEBUG_STRING(DebugManager.flags.PrintDebugMessages.get(), stdout, "devMode = %d, taskMode = %d.\n",
|
|
|
|
static_cast<int>(device.getPreemptionMode()), static_cast<int>(taskMode));
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
return devMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreemptionHelper::adjustDefaultPreemptionMode(RuntimeCapabilityTable &deviceCapabilities, bool allowMidThread, bool allowThreadGroup, bool allowMidBatch) {
|
|
|
|
if (deviceCapabilities.defaultPreemptionMode >= PreemptionMode::MidThread &&
|
|
|
|
allowMidThread) {
|
|
|
|
deviceCapabilities.defaultPreemptionMode = PreemptionMode::MidThread;
|
|
|
|
} else if (deviceCapabilities.defaultPreemptionMode >= PreemptionMode::ThreadGroup &&
|
|
|
|
allowThreadGroup) {
|
|
|
|
deviceCapabilities.defaultPreemptionMode = PreemptionMode::ThreadGroup;
|
|
|
|
} else if (deviceCapabilities.defaultPreemptionMode >= PreemptionMode::MidBatch &&
|
|
|
|
allowMidBatch) {
|
|
|
|
deviceCapabilities.defaultPreemptionMode = PreemptionMode::MidBatch;
|
|
|
|
} else {
|
|
|
|
deviceCapabilities.defaultPreemptionMode = PreemptionMode::Disabled;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-06 18:58:05 +08:00
|
|
|
PreemptionMode PreemptionHelper::getDefaultPreemptionMode(const HardwareInfo &hwInfo) {
|
2018-02-08 20:41:02 +08:00
|
|
|
return DebugManager.flags.ForcePreemptionMode.get() == -1
|
2018-02-06 18:58:05 +08:00
|
|
|
? hwInfo.capabilityTable.defaultPreemptionMode
|
|
|
|
: static_cast<PreemptionMode>(DebugManager.flags.ForcePreemptionMode.get());
|
|
|
|
}
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|