2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2019-02-27 11:39:32 +01:00
|
|
|
* Copyright (C) 2018-2019 Intel Corporation
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
2018-09-18 09:11:08 +02:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "runtime/command_stream/preemption.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
|
2019-06-19 00:21:29 -07:00
|
|
|
#include "core/helpers/string.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
#include "runtime/built_ins/built_ins.h"
|
2018-01-08 15:58:02 +01:00
|
|
|
#include "runtime/device/device.h"
|
2017-12-21 00:45:38 +01:00
|
|
|
#include "runtime/helpers/dispatch_info.h"
|
|
|
|
#include "runtime/kernel/kernel.h"
|
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
namespace NEO {
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2019-05-08 16:00:24 +02:00
|
|
|
bool PreemptionHelper::allowThreadGroupPreemption(Kernel *kernel, const WorkaroundTable *workaroundTable) {
|
|
|
|
if (workaroundTable->waDisablePerCtxtPreemptionGranularityControl) {
|
2017-12-21 00:45:38 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kernel) {
|
|
|
|
if (kernel->getKernelInfo().patchInfo.executionEnvironment &&
|
|
|
|
kernel->getKernelInfo().patchInfo.executionEnvironment->UsesFencesForReadWriteImages &&
|
2019-05-08 16:00:24 +02:00
|
|
|
workaroundTable->waDisableLSQCROPERFforOCL) {
|
2017-12-21 00:45:38 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (kernel->isSchedulerKernel || kernel->isVmeKernel()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PreemptionHelper::allowMidThreadPreemption(Kernel *kernel, Device &device) {
|
|
|
|
bool allowedByKernel = true;
|
|
|
|
if (kernel) {
|
2017-12-20 17:01:16 +01:00
|
|
|
allowedByKernel = (kernel->getKernelInfo().patchInfo.executionEnvironment->DisableMidThreadPreemption == 0) &&
|
|
|
|
!(kernel->isVmeKernel() && !device.getDeviceInfo().vmeAvcSupportsPreemption);
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
bool supportedByDevice = (device.getPreemptionMode() >= PreemptionMode::MidThread);
|
|
|
|
return supportedByDevice && allowedByKernel;
|
|
|
|
}
|
|
|
|
|
|
|
|
PreemptionMode PreemptionHelper::taskPreemptionMode(Device &device, Kernel *kernel) {
|
|
|
|
if (device.getPreemptionMode() == PreemptionMode::Disabled) {
|
|
|
|
return PreemptionMode::Disabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (device.getPreemptionMode() >= PreemptionMode::MidThread &&
|
|
|
|
allowMidThreadPreemption(kernel, device)) {
|
|
|
|
return PreemptionMode::MidThread;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (device.getPreemptionMode() >= PreemptionMode::ThreadGroup &&
|
2019-09-04 09:10:18 +02:00
|
|
|
allowThreadGroupPreemption(kernel, &device.getHardwareInfo().workaroundTable)) {
|
2017-12-21 00:45:38 +01:00
|
|
|
return PreemptionMode::ThreadGroup;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PreemptionMode::MidBatch;
|
|
|
|
};
|
|
|
|
|
|
|
|
PreemptionMode PreemptionHelper::taskPreemptionMode(Device &device, const MultiDispatchInfo &multiDispatchInfo) {
|
|
|
|
PreemptionMode devMode = device.getPreemptionMode();
|
|
|
|
|
|
|
|
for (const auto &di : multiDispatchInfo) {
|
|
|
|
PreemptionMode taskMode = taskPreemptionMode(device, di.getKernel());
|
|
|
|
if (devMode > taskMode) {
|
|
|
|
devMode = taskMode;
|
|
|
|
}
|
2019-03-21 22:21:52 -07:00
|
|
|
printDebugString(DebugManager.flags.PrintDebugMessages.get(), stdout, "devMode = %d, taskMode = %d.\n",
|
|
|
|
static_cast<int>(device.getPreemptionMode()), static_cast<int>(taskMode));
|
2017-12-21 00:45:38 +01: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 11:58:05 +01:00
|
|
|
PreemptionMode PreemptionHelper::getDefaultPreemptionMode(const HardwareInfo &hwInfo) {
|
2018-02-08 13:41:02 +01:00
|
|
|
return DebugManager.flags.ForcePreemptionMode.get() == -1
|
2018-02-06 11:58:05 +01:00
|
|
|
? hwInfo.capabilityTable.defaultPreemptionMode
|
|
|
|
: static_cast<PreemptionMode>(DebugManager.flags.ForcePreemptionMode.get());
|
|
|
|
}
|
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
} // namespace NEO
|