2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2024-10-01 13:56:05 +00:00
|
|
|
* Copyright (C) 2018-2024 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
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/command_stream/preemption.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
|
2023-01-09 15:02:00 +00:00
|
|
|
#include "shared/source/command_stream/linear_stream.h"
|
|
|
|
|
#include "shared/source/command_stream/preemption_mode.h"
|
2021-09-22 22:24:59 +00:00
|
|
|
#include "shared/source/debug_settings/debug_settings_manager.h"
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/device/device.h"
|
2022-12-15 17:32:03 +00:00
|
|
|
#include "shared/source/execution_environment/root_device_environment.h"
|
2023-02-06 09:05:43 +00:00
|
|
|
#include "shared/source/helpers/hw_info.h"
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/helpers/string.h"
|
2021-09-23 13:06:18 +00:00
|
|
|
#include "shared/source/kernel/kernel_descriptor.h"
|
2024-10-01 13:56:05 +00:00
|
|
|
#include "shared/source/release_helper/release_helper.h"
|
2020-02-24 10:22:30 +01:00
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
namespace NEO {
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2019-11-25 16:45:52 +01:00
|
|
|
bool PreemptionHelper::allowThreadGroupPreemption(const PreemptionFlags &flags) {
|
|
|
|
|
if (flags.flags.disablePerCtxtPreemptionGranularityControl) {
|
2017-12-21 00:45:38 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-25 16:45:52 +01:00
|
|
|
if (flags.flags.usesFencesForReadWriteImages &&
|
|
|
|
|
flags.flags.disableLSQCROPERFforOCL) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2022-01-10 18:55:21 +00:00
|
|
|
if (flags.flags.vmeKernel) {
|
2019-11-25 16:45:52 +01:00
|
|
|
return false;
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-25 16:45:52 +01:00
|
|
|
bool PreemptionHelper::allowMidThreadPreemption(const PreemptionFlags &flags) {
|
|
|
|
|
return (flags.flags.disabledMidThreadPreemptionKernel == 0) &&
|
|
|
|
|
!(flags.flags.vmeKernel && !flags.flags.deviceSupportsVmePreemption);
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
2019-11-27 12:59:47 +01:00
|
|
|
PreemptionMode PreemptionHelper::taskPreemptionMode(PreemptionMode devicePreemptionMode, const PreemptionFlags &flags) {
|
2023-11-30 08:32:25 +00:00
|
|
|
if (debugManager.flags.ForceKernelPreemptionMode.get() != -1) {
|
|
|
|
|
return static_cast<PreemptionMode>(debugManager.flags.ForceKernelPreemptionMode.get());
|
2020-04-30 17:07:07 +02:00
|
|
|
}
|
2019-11-27 12:59:47 +01:00
|
|
|
if (devicePreemptionMode == PreemptionMode::Disabled) {
|
2017-12-21 00:45:38 +01:00
|
|
|
return PreemptionMode::Disabled;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-27 12:59:47 +01:00
|
|
|
if (devicePreemptionMode >= PreemptionMode::MidThread &&
|
2019-11-25 16:45:52 +01:00
|
|
|
allowMidThreadPreemption(flags)) {
|
2017-12-21 00:45:38 +01:00
|
|
|
return PreemptionMode::MidThread;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-27 12:59:47 +01:00
|
|
|
if (devicePreemptionMode >= PreemptionMode::ThreadGroup &&
|
2019-11-25 16:45:52 +01:00
|
|
|
allowThreadGroupPreemption(flags)) {
|
2017-12-21 00:45:38 +01:00
|
|
|
return PreemptionMode::ThreadGroup;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return PreemptionMode::MidBatch;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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) {
|
2023-11-30 08:32:25 +00:00
|
|
|
return debugManager.flags.ForcePreemptionMode.get() == -1
|
2018-02-06 11:58:05 +01:00
|
|
|
? hwInfo.capabilityTable.defaultPreemptionMode
|
2023-11-30 08:32:25 +00:00
|
|
|
: static_cast<PreemptionMode>(debugManager.flags.ForcePreemptionMode.get());
|
2018-02-06 11:58:05 +01:00
|
|
|
}
|
|
|
|
|
|
2022-01-10 18:55:21 +00:00
|
|
|
PreemptionFlags PreemptionHelper::createPreemptionLevelFlags(Device &device, const KernelDescriptor *kernelDescriptor) {
|
2021-09-23 13:06:18 +00:00
|
|
|
PreemptionFlags flags = {};
|
|
|
|
|
if (kernelDescriptor) {
|
|
|
|
|
flags.flags.disabledMidThreadPreemptionKernel = kernelDescriptor->kernelAttributes.flags.requiresDisabledMidThreadPreemption;
|
|
|
|
|
flags.flags.vmeKernel = kernelDescriptor->kernelAttributes.flags.usesVme;
|
|
|
|
|
flags.flags.usesFencesForReadWriteImages = kernelDescriptor->kernelAttributes.flags.usesFencesForReadWriteImages;
|
|
|
|
|
}
|
|
|
|
|
flags.flags.deviceSupportsVmePreemption = device.getDeviceInfo().vmeAvcSupportsPreemption;
|
2021-11-25 09:31:14 +00:00
|
|
|
flags.flags.disablePerCtxtPreemptionGranularityControl = device.getHardwareInfo().workaroundTable.flags.waDisablePerCtxtPreemptionGranularityControl;
|
|
|
|
|
flags.flags.disableLSQCROPERFforOCL = device.getHardwareInfo().workaroundTable.flags.waDisableLSQCROPERFforOCL;
|
2021-09-23 13:06:18 +00:00
|
|
|
return flags;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
} // namespace NEO
|