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