feature: fail stateful kernel when stateless is required

Resolves: NEO-11859

Signed-off-by: Damian Tomczak <damian.tomczak@intel.com>
This commit is contained in:
Damian Tomczak
2025-09-29 07:10:17 +00:00
committed by Compute-Runtime-Automation
parent 495cdca789
commit 2a8c0d867f
11 changed files with 46 additions and 33 deletions

View File

@@ -100,8 +100,9 @@ TEST_F(ClBuildProgramTests, GivenBinaryAsInputWhenCreatingProgramWithSourceThenP
EXPECT_EQ(CL_SUCCESS, retVal);
}
HWTEST2_F(ClBuildProgramTests, GivenFailBuildProgramAndBinaryAsInputWhenCreatingProgramWithSourceThenProgramBuildFails, IsAtLeastXeHpcCore) {
debugManager.flags.FailBuildProgramWithStatefulAccess.set(1);
HWTEST_F(ClBuildProgramTests, GivenFailBuildProgramIsDisabledAndStatelessDisabledAndBinaryAsInputWhenCreatingProgramWithSourceThenProgramBuildSuccesses) {
debugManager.flags.FailBuildProgramWithStatefulAccess.set(0);
debugManager.flags.DisableForceToStateless.set(1);
cl_program pProgram = nullptr;
cl_int binaryStatus = CL_SUCCESS;
MockZebinWrapper zebin{pDevice->getHardwareInfo()};
@@ -126,7 +127,7 @@ HWTEST2_F(ClBuildProgramTests, GivenFailBuildProgramAndBinaryAsInputWhenCreating
nullptr,
nullptr);
EXPECT_EQ(CL_BUILD_PROGRAM_FAILURE, retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
retVal = clReleaseProgram(pProgram);
EXPECT_EQ(CL_SUCCESS, retVal);

View File

@@ -88,7 +88,7 @@ TEST_F(ClCreateProgramWithBinaryTests, GivenInvalidInputWhenCreatingProgramWithB
EXPECT_EQ(CL_INVALID_VALUE, retVal);
EXPECT_EQ(nullptr, pProgram);
zebin.binarySizes[1] = zebin.data.storage.size();
zebin.binarySizes[1] = zebin.data->storage.size();
pProgram = clCreateProgramWithBinary(
pContext,

View File

@@ -318,7 +318,7 @@ TEST(clGetProgramInfoTest, GivenMultiDeviceBuiltInProgramCreatedWithGenBinaryWhe
cl_program pProgram = nullptr;
cl_int retVal = CL_INVALID_PROGRAM;
pProgram = Program::createBuiltInFromGenBinary(&context, context.getDevices(), zebin.data.storage.data(), zebin.data.storage.size(), &retVal);
pProgram = Program::createBuiltInFromGenBinary(&context, context.getDevices(), zebin.data->storage.data(), zebin.data->storage.size(), &retVal);
EXPECT_NE(nullptr, pProgram);
EXPECT_EQ(CL_SUCCESS, retVal);
@@ -346,8 +346,8 @@ TEST(clGetProgramInfoTest, GivenMultiDeviceBuiltInProgramCreatedWithGenBinaryWhe
cl_int retVal = CL_INVALID_PROGRAM;
unsigned char *pBinary = zebin.data.storage.data();
const size_t binarySize = zebin.data.storage.size();
unsigned char *pBinary = zebin.data->storage.data();
const size_t binarySize = zebin.data->storage.size();
pProgram = Program::createBuiltInFromGenBinary(&context, context.getDevices(), pBinary, binarySize, &retVal);
EXPECT_NE(nullptr, pProgram);

View File

@@ -129,6 +129,7 @@ HWTEST2_F(EnqueueKernelTest, GivenIndirectAccessBufferVersion1WhenExecutingKerne
ZebinTestData::ZebinCopyBufferModule<numBits>::Descriptor desc{};
desc.execEnv["simd_size"] = std::to_string(simd);
desc.execEnv["require_iab"] = "true";
desc.isStateless = pDevice->getCompilerProductHelper().isForceToStatelessRequired();
auto zebinData = std::make_unique<ZebinTestData::ZebinCopyBufferModule<numBits>>(pDevice->getHardwareInfo(), desc);
const auto src = zebinData->storage.data();
const auto binarySize = zebinData->storage.size();

View File

@@ -44,11 +44,6 @@ const char *CompilerProductHelperHw<gfxProduct>::getCachingPolicyOptions(bool is
return L1CachePolicyHelper<gfxProduct>::getCachingPolicyOptions(isDebuggerActive);
}
template <PRODUCT_FAMILY gfxProduct>
bool CompilerProductHelperHw<gfxProduct>::failBuildProgramWithStatefulAccessPreference() const {
return false;
}
template <PRODUCT_FAMILY gfxProduct>
bool CompilerProductHelperHw<gfxProduct>::oclocEnforceZebinFormat() const {
return false;

View File

@@ -39,4 +39,9 @@ bool CompilerProductHelperHw<gfxProduct>::isSubgroupBufferPrefetchSupported() co
return false;
}
template <PRODUCT_FAMILY gfxProduct>
bool CompilerProductHelperHw<gfxProduct>::failBuildProgramWithStatefulAccessPreference() const {
return false;
}
} // namespace NEO

View File

@@ -43,4 +43,9 @@ bool CompilerProductHelperHw<gfxProduct>::isSubgroupBufferPrefetchSupported() co
return true;
}
template <PRODUCT_FAMILY gfxProduct>
bool CompilerProductHelperHw<gfxProduct>::failBuildProgramWithStatefulAccessPreference() const {
return true;
}
} // namespace NEO

View File

@@ -63,11 +63,6 @@ uint32_t CompilerProductHelperHw<IGFX_PVC>::matchRevisionIdWithProductConfig(Har
return pvcConfig.value;
}
template <>
bool CompilerProductHelperHw<IGFX_PVC>::failBuildProgramWithStatefulAccessPreference() const {
return false;
}
template <>
bool CompilerProductHelperHw<IGFX_PVC>::isMatrixMultiplyAccumulateSupported(const ReleaseHelper *releaseHelper) const {
if (releaseHelper) {

View File

@@ -7,6 +7,7 @@
#pragma once
#include "shared/source/helpers/compiler_product_helper.h"
#include "shared/test/common/libult/global_environment.h"
#include "shared/test/common/mocks/mock_modules_zebin.h"
@@ -19,16 +20,18 @@ template <size_t binariesCount = 1u, Elf::ElfIdentifierClass numBits = is32bit ?
struct MockZebinWrapper {
using Descriptor = ZebinTestData::ZebinCopyBufferModule<numBits>::Descriptor;
MockZebinWrapper(const HardwareInfo &hwInfo, Descriptor desc)
: data(hwInfo, desc) {
std::fill_n(binaries.begin(), binariesCount, reinterpret_cast<const unsigned char *>(this->data.storage.data()));
std::fill_n(binarySizes.begin(), binariesCount, this->data.storage.size());
MockZebinWrapper(const HardwareInfo &hwInfo, Descriptor desc = {}) {
auto productHelper = NEO::CompilerProductHelper::create(defaultHwInfo->platform.eProductFamily);
desc.isStateless = productHelper->isForceToStatelessRequired();
data = std::make_unique<ZebinTestData::ZebinCopyBufferModule<numBits>>(hwInfo, desc);
std::fill_n(binaries.begin(), binariesCount, reinterpret_cast<const unsigned char *>(this->data->storage.data()));
std::fill_n(binarySizes.begin(), binariesCount, this->data->storage.size());
}
MockZebinWrapper(const HardwareInfo &hwInfo) : MockZebinWrapper(hwInfo, Descriptor{}) {}
auto &getFlags() {
return reinterpret_cast<Zebin::Elf::ZebinTargetFlags &>(this->data.elfHeader->flags);
return reinterpret_cast<Zebin::Elf::ZebinTargetFlags &>(this->data->elfHeader->flags);
}
void setAsMockCompilerReturnedBinary() {
@@ -57,7 +60,7 @@ struct MockZebinWrapper {
}};
}
ZebinTestData::ZebinCopyBufferModule<numBits> data;
std::unique_ptr<ZebinTestData::ZebinCopyBufferModule<numBits>> data;
std::array<const unsigned char *, binariesCount> binaries;
std::array<size_t, binariesCount> binarySizes;
std::unique_ptr<void, void (*)(void *)> debugVarsRestore{nullptr, nullptr};

View File

@@ -14,6 +14,7 @@
#include "shared/test/common/helpers/gtest_helpers.h"
#include "shared/test/common/helpers/unit_test_helper.h"
#include "shared/test/common/mocks/mock_device.h"
#include "shared/test/common/mocks/mock_execution_environment.h"
#include "shared/test/common/mocks/mock_release_helper.h"
#include "shared/test/common/test_macros/hw_test.h"
@@ -545,3 +546,17 @@ HWTEST_F(CompilerProductHelperFixture, GivenRequestForExtraKernelCapabilitiesThe
EXPECT_EQ(0u, extraCaps);
}
}
HWTEST2_F(CompilerProductHelperFixture, givenStatefulPlatformWhenFailBuildProgramWithStatefulAccessPreferenceThenFalseIsReturned, IsStatefulBufferPreferredForProduct) {
MockExecutionEnvironment executionEnvironment{};
auto &rootDeviceEnvironment = *executionEnvironment.rootDeviceEnvironments[0];
auto &compilerProductHelper = rootDeviceEnvironment.getHelper<CompilerProductHelper>();
EXPECT_FALSE(compilerProductHelper.failBuildProgramWithStatefulAccessPreference());
}
HWTEST2_F(CompilerProductHelperFixture, givenNotStatefulPlatformWhenFailBuildProgramWithStatefulAccessPreferenceThenTrueIsReturned, IsStatelessBufferPreferredForProduct) {
MockExecutionEnvironment executionEnvironment{};
auto &rootDeviceEnvironment = *executionEnvironment.rootDeviceEnvironments[0];
auto &compilerProductHelper = rootDeviceEnvironment.getHelper<CompilerProductHelper>();
EXPECT_TRUE(compilerProductHelper.failBuildProgramWithStatefulAccessPreference());
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Intel Corporation
* Copyright (C) 2023-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -38,13 +38,6 @@ PVCTEST_F(CompilerProductHelperPvcTest, givenPvcConfigsWhenMatchConfigWithRevIdT
EXPECT_EQ(compilerProductHelper.matchRevisionIdWithProductConfig(AOT::PVC_XT_C0_VG, 0x2f), AOT::PVC_XT_C0_VG);
}
PVCTEST_F(CompilerProductHelperPvcTest, givenPvcWhenFailBuildProgramWithStatefulAccessPreferenceThenFalseIsReturned) {
MockExecutionEnvironment executionEnvironment{};
auto &rootDeviceEnvironment = *executionEnvironment.rootDeviceEnvironments[0];
auto &compilerProductHelper = rootDeviceEnvironment.getHelper<CompilerProductHelper>();
EXPECT_FALSE(compilerProductHelper.failBuildProgramWithStatefulAccessPreference());
}
PVCTEST_F(CompilerProductHelperPvcTest, givenPvcB0AndLaterThenMatrixMultiplyAccumulateTF32IsSupported) {
MockExecutionEnvironment executionEnvironment{};
auto &rootDeviceEnvironment = *executionEnvironment.rootDeviceEnvironments[0];