2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2019-02-27 18:39:32 +08:00
|
|
|
* Copyright (C) 2018-2019 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
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "runtime/command_stream/preemption.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
|
|
|
#include "runtime/built_ins/built_ins.h"
|
2018-01-08 22:58:02 +08:00
|
|
|
#include "runtime/device/device.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "runtime/helpers/dispatch_info.h"
|
2018-01-08 22:58:02 +08:00
|
|
|
#include "runtime/helpers/string.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "runtime/kernel/kernel.h"
|
|
|
|
|
|
|
|
namespace OCLRT {
|
|
|
|
|
|
|
|
bool PreemptionHelper::allowThreadGroupPreemption(Kernel *kernel, const WorkaroundTable *waTable) {
|
|
|
|
if (waTable->waDisablePerCtxtPreemptionGranularityControl) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kernel) {
|
|
|
|
if (kernel->getKernelInfo().patchInfo.executionEnvironment &&
|
|
|
|
kernel->getKernelInfo().patchInfo.executionEnvironment->UsesFencesForReadWriteImages &&
|
|
|
|
waTable->waDisableLSQCROPERFforOCL) {
|
|
|
|
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-21 00:01:16 +08:00
|
|
|
allowedByKernel = (kernel->getKernelInfo().patchInfo.executionEnvironment->DisableMidThreadPreemption == 0) &&
|
|
|
|
!(kernel->isVmeKernel() && !device.getDeviceInfo().vmeAvcSupportsPreemption);
|
2017-12-21 07:45:38 +08: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 &&
|
|
|
|
allowThreadGroupPreemption(kernel, device.getWaTable())) {
|
|
|
|
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-22 13:21:52 +08:00
|
|
|
printDebugString(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());
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
} // namespace OCLRT
|