feature: add method to switch enable/disable mid thread preemption

Resolves: NEO-8089

Signed-off-by: Katarzyna Cencelewska <katarzyna.cencelewska@intel.com>
This commit is contained in:
Katarzyna Cencelewska
2024-04-15 12:23:11 +00:00
committed by Compute-Runtime-Automation
parent f10e0e1d0a
commit ce3bb1327e
8 changed files with 64 additions and 5 deletions

View File

@@ -47,6 +47,7 @@ class ClGfxCoreHelper : public ApiGfxCoreHelper {
virtual cl_device_feature_capabilities_intel getSupportedDeviceFeatureCapabilities(const RootDeviceEnvironment &rootDeviceEnvironment) const = 0;
virtual bool allowImageCompression(cl_image_format format) const = 0;
virtual bool isFormatRedescribable(cl_image_format format) const = 0;
virtual bool isLimitationForPreemptionNeeded() const = 0;
protected:
virtual bool hasStatelessAccessToBuffer(const KernelInfo &kernelInfo) const = 0;
@@ -76,6 +77,7 @@ class ClGfxCoreHelperHw : public ClGfxCoreHelper {
cl_device_feature_capabilities_intel getSupportedDeviceFeatureCapabilities(const RootDeviceEnvironment &rootDeviceEnvironment) const override;
bool allowImageCompression(cl_image_format format) const override;
bool isFormatRedescribable(cl_image_format format) const override;
bool isLimitationForPreemptionNeeded() const override;
protected:
bool hasStatelessAccessToBuffer(const KernelInfo &kernelInfo) const override;

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2023 Intel Corporation
* Copyright (C) 2020-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -55,4 +55,9 @@ bool ClGfxCoreHelperHw<GfxFamily>::allowImageCompression(cl_image_format format)
return true;
}
template <typename GfxFamily>
bool ClGfxCoreHelperHw<GfxFamily>::isLimitationForPreemptionNeeded() const {
return false;
}
} // namespace NEO

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021-2023 Intel Corporation
* Copyright (C) 2021-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -7,6 +7,10 @@
#include "opencl/source/helpers/cl_preemption_helper.h"
#include "shared/source/execution_environment/root_device_environment.h"
#include "opencl/source/context/context.h"
#include "opencl/source/helpers/cl_gfx_core_helper.h"
#include "opencl/source/helpers/dispatch_info.h"
namespace NEO {
@@ -32,4 +36,14 @@ PreemptionMode ClPreemptionHelper::taskPreemptionMode(Device &device, const Mult
}
return devMode;
}
void ClPreemptionHelper::overrideMidThreadPreemptionSupport(Context &context, bool value) {
for (auto device : context.getDevices()) {
auto &clGfxCoreHelper = device->getDevice().getRootDeviceEnvironment().getHelper<ClGfxCoreHelper>();
auto isPreemptionDisabled = debugManager.flags.ForcePreemptionMode.get() == static_cast<int32_t>(PreemptionMode::Disabled);
if (clGfxCoreHelper.isLimitationForPreemptionNeeded() && !isPreemptionDisabled) {
device->getDevice().overridePreemptionMode(value ? PreemptionMode::Disabled : PreemptionMode::MidThread);
}
}
}
} // namespace NEO

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 Intel Corporation
* Copyright (C) 2021-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -11,11 +11,13 @@
namespace NEO {
class Kernel;
class Device;
class Context;
struct MultiDispatchInfo;
class ClPreemptionHelper {
public:
static PreemptionMode taskPreemptionMode(Device &device, const MultiDispatchInfo &multiDispatchInfo);
static void overrideMidThreadPreemptionSupport(Context &context, bool value);
};
} // namespace NEO

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2023 Intel Corporation
* Copyright (C) 2018-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -137,6 +137,12 @@ TEST_F(ClGfxCoreHelperTest, givenGenHelperWhenKernelArgumentIsNotPureStatefulThe
}
}
HWTEST_F(ClGfxCoreHelperTest, WhenCheckingIsLimitationForPreemptionNeededThenReturnFalse) {
auto &clGfxCoreHelper = getHelper<ClGfxCoreHelper>();
EXPECT_FALSE(clGfxCoreHelper.isLimitationForPreemptionNeeded());
}
HWCMDTEST_F(IGFX_GEN8_CORE, ClGfxCoreHelperTest, givenCLImageFormatsWhenCallingIsFormatRedescribableThenCorrectValueReturned) {
static const cl_image_format redescribeFormats[] = {
{CL_R, CL_UNSIGNED_INT8},

View File

@@ -59,3 +59,21 @@ TEST_F(MidThreadPreemptionTests, GivenMultiDispatchWithoutKernelWhenDevicePreemp
EXPECT_EQ(PreemptionMode::MidThread, ClPreemptionHelper::taskPreemptionMode(device->getDevice(), multiDispatchInfo));
}
HWTEST_F(MidThreadPreemptionTests, GivenValueArgWhenOverrideMidThreadPreemptionSupportThenNothingChange) {
device->setPreemptionMode(PreemptionMode::MidThread);
bool value = true;
ClPreemptionHelper::overrideMidThreadPreemptionSupport(*context.get(), value);
EXPECT_EQ(PreemptionMode::MidThread, device->getPreemptionMode());
value = false;
ClPreemptionHelper::overrideMidThreadPreemptionSupport(*context.get(), value);
EXPECT_EQ(PreemptionMode::MidThread, device->getPreemptionMode());
device->setPreemptionMode(PreemptionMode::ThreadGroup);
value = true;
ClPreemptionHelper::overrideMidThreadPreemptionSupport(*context.get(), value);
EXPECT_EQ(PreemptionMode::ThreadGroup, device->getPreemptionMode());
value = false;
ClPreemptionHelper::overrideMidThreadPreemptionSupport(*context.get(), value);
EXPECT_EQ(PreemptionMode::ThreadGroup, device->getPreemptionMode());
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2023 Intel Corporation
* Copyright (C) 2018-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -119,6 +119,7 @@ class Device : public ReferenceTrackedObject<Device> {
GFXCORE_FAMILY getRenderCoreFamily() const;
PerformanceCounters *getPerformanceCounters() { return performanceCounters.get(); }
PreemptionMode getPreemptionMode() const { return preemptionMode; }
void overridePreemptionMode(PreemptionMode mode) { preemptionMode = mode; }
Debugger *getDebugger() const;
DebuggerL0 *getL0Debugger();
const EnginesT &getAllEngines() const;

View File

@@ -610,6 +610,17 @@ TEST_F(DeviceTests, givenMtPreemptionEnabledWhenCreatingRootCsrThenCreatePreempt
EXPECT_NE(nullptr, deviceFactory.rootDevices[0]->getDefaultEngine().commandStreamReceiver->getPreemptionAllocation());
}
TEST_F(DeviceTests, givenPreemptionModeWhenOverridePreemptionModeThenProperlySet) {
auto newPreemptionMode = PreemptionMode::ThreadGroup;
auto device = std::unique_ptr<MockDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(defaultHwInfo.get()));
device->overridePreemptionMode(newPreemptionMode);
EXPECT_EQ(newPreemptionMode, device->getPreemptionMode());
newPreemptionMode = PreemptionMode::Disabled;
device->overridePreemptionMode(newPreemptionMode);
EXPECT_EQ(newPreemptionMode, device->getPreemptionMode());
}
HWCMDTEST_F(IGFX_XE_HP_CORE, DeviceTests, givenZexNumberOfCssEnvVariableDefinedWhenDeviceIsCreatedThenCreateDevicesWithProperCcsCount) {
VariableBackup<UltHwConfig> backup(&ultHwConfig);
ultHwConfig.useMockedPrepareDeviceEnvironmentsFunc = false;