fix(zebin): Extend oneDNN WA for whole application context

When a dummy kernel "kernel void_(){}" is passed in sources - specific
for workloads with ngen backend - enforce fallback to CTNI for the whole
application context (mark the context as non-zebinary).

Related-To: NEO-7772
Signed-off-by: Kacper Nowak <kacper.nowak@intel.com>
This commit is contained in:
Kacper Nowak
2023-03-03 13:23:24 +00:00
committed by Compute-Runtime-Automation
parent 6c59953072
commit efba242570
13 changed files with 81 additions and 49 deletions

View File

@@ -579,4 +579,12 @@ std::unique_lock<std::mutex> Context::obtainOwnershipForMultiRootDeviceAllocator
return std::unique_lock<std::mutex>(multiRootDeviceAllocatorMtx); return std::unique_lock<std::mutex>(multiRootDeviceAllocatorMtx);
} }
void Context::setContextAsNonZebin() {
this->nonZebinContext = true;
}
bool Context::checkIfContextIsNonZebin() const {
return this->nonZebinContext;
}
} // namespace NEO } // namespace NEO

View File

@@ -226,6 +226,8 @@ class Context : public BaseObject<_cl_context> {
TagAllocatorBase *getMultiRootDeviceTimestampPacketAllocator(); TagAllocatorBase *getMultiRootDeviceTimestampPacketAllocator();
std::unique_lock<std::mutex> obtainOwnershipForMultiRootDeviceAllocator(); std::unique_lock<std::mutex> obtainOwnershipForMultiRootDeviceAllocator();
void setMultiRootDeviceTimestampPacketAllocator(std::unique_ptr<TagAllocatorBase> &allocator); void setMultiRootDeviceTimestampPacketAllocator(std::unique_ptr<TagAllocatorBase> &allocator);
void setContextAsNonZebin();
bool checkIfContextIsNonZebin() const;
protected: protected:
struct BuiltInKernel { struct BuiltInKernel {
@@ -271,5 +273,6 @@ class Context : public BaseObject<_cl_context> {
bool interopUserSync = false; bool interopUserSync = false;
bool resolvesRequiredInKernels = false; bool resolvesRequiredInKernels = false;
bool nonZebinContext = false;
}; };
} // namespace NEO } // namespace NEO

View File

@@ -19,6 +19,7 @@
#include "shared/source/utilities/logger.h" #include "shared/source/utilities/logger.h"
#include "opencl/source/cl_device/cl_device.h" #include "opencl/source/cl_device/cl_device.h"
#include "opencl/source/context/context.h"
#include "opencl/source/gtpin/gtpin_notify.h" #include "opencl/source/gtpin/gtpin_notify.h"
#include "opencl/source/helpers/cl_validators.h" #include "opencl/source/helpers/cl_validators.h"
#include "opencl/source/platform/platform.h" #include "opencl/source/platform/platform.h"
@@ -116,8 +117,10 @@ cl_int Program::build(
NEO::CompilerOptions::concatenateAppend(internalOptions, NEO::DebugManager.flags.InjectInternalBuildOptions.get()); NEO::CompilerOptions::concatenateAppend(internalOptions, NEO::DebugManager.flags.InjectInternalBuildOptions.get());
} }
if (this->enforceFallbackToPatchtokens) { if (nullptr != this->getContextPtr()) {
CompilerOptions::concatenateAppend(internalOptions, CompilerOptions::disableZebin); if (this->getContext().checkIfContextIsNonZebin()) {
CompilerOptions::concatenateAppend(internalOptions, CompilerOptions::disableZebin);
}
} }
inputArgs.apiOptions = ArrayRef<const char>(options.c_str(), options.length()); inputArgs.apiOptions = ArrayRef<const char>(options.c_str(), options.length());

View File

@@ -79,7 +79,9 @@ T *Program::create(
program = new T(pContext, false, pContext->getDevices()); program = new T(pContext, false, pContext->getDevices());
if (ail) { if (ail) {
ail->forceFallbackToPatchtokensIfRequired(combinedString, program->enforceFallbackToPatchtokens); if (ail->isFallbackToPatchtokensRequired(combinedString)) {
pContext->setContextAsNonZebin();
}
} }
program->sourceCode.swap(combinedString); program->sourceCode.swap(combinedString);
program->createdFrom = CreatedFrom::SOURCE; program->createdFrom = CreatedFrom::SOURCE;

View File

@@ -564,6 +564,14 @@ bool Program::isOptionValueValid(ConstStringRef option, ConstStringRef value) {
return false; return false;
} }
Context &Program::getContext() const {
return *context;
}
Context *Program::getContextPtr() const {
return context;
}
const ClDeviceVector &Program::getDevicesInProgram() const { const ClDeviceVector &Program::getDevicesInProgram() const {
if (clDevicesInProgram.empty()) { if (clDevicesInProgram.empty()) {
return clDevices; return clDevices;

View File

@@ -161,13 +161,8 @@ class Program : public BaseObject<_cl_program> {
return std::any_of(this->deviceBuildInfos.begin(), this->deviceBuildInfos.end(), [](auto deviceBuildInfo) { return deviceBuildInfo.second.buildStatus == CL_SUCCESS && deviceBuildInfo.second.programBinaryType == CL_PROGRAM_BINARY_TYPE_EXECUTABLE; }); return std::any_of(this->deviceBuildInfos.begin(), this->deviceBuildInfos.end(), [](auto deviceBuildInfo) { return deviceBuildInfo.second.buildStatus == CL_SUCCESS && deviceBuildInfo.second.programBinaryType == CL_PROGRAM_BINARY_TYPE_EXECUTABLE; });
} }
Context &getContext() const { Context &getContext() const;
return *context; Context *getContextPtr() const;
}
Context *getContextPtr() const {
return context;
}
ExecutionEnvironment &peekExecutionEnvironment() const { ExecutionEnvironment &peekExecutionEnvironment() const {
return executionEnvironment; return executionEnvironment;
@@ -385,7 +380,6 @@ class Program : public BaseObject<_cl_program> {
bool isBuiltIn = false; bool isBuiltIn = false;
bool kernelDebugEnabled = false; bool kernelDebugEnabled = false;
bool enforceFallbackToPatchtokens = false;
uint32_t maxRootDeviceIndex = std::numeric_limits<uint32_t>::max(); uint32_t maxRootDeviceIndex = std::numeric_limits<uint32_t>::max();
std::mutex lockMutex; std::mutex lockMutex;
uint32_t exposedKernels = 0; uint32_t exposedKernels = 0;

View File

@@ -54,7 +54,6 @@ class MockProgram : public Program {
using Program::debuggerInfos; using Program::debuggerInfos;
using Program::deviceBuildInfos; using Program::deviceBuildInfos;
using Program::disableZebinIfVmeEnabled; using Program::disableZebinIfVmeEnabled;
using Program::enforceFallbackToPatchtokens;
using Program::extractInternalOptions; using Program::extractInternalOptions;
using Program::getKernelInfo; using Program::getKernelInfo;
using Program::getModuleAllocations; using Program::getModuleAllocations;

View File

@@ -691,8 +691,7 @@ TEST_F(MinimumProgramFixture, givenEmptyAilWhenCreateProgramWithSourcesThenSourc
pProgram->release(); pProgram->release();
} }
HWTEST_F(MinimumProgramFixture, givenEmptyAilWhenCreateProgramWithSourcesAndWithDummyKernelThenDoNotSetFallbackRequired) { HWTEST_F(MinimumProgramFixture, givenEmptyAilWhenCreateProgramWithSourcesAndWithDummyKernelThenDoNotMarkApplicationContextAsNonZebin) {
VariableBackup<AILConfiguration *> ailConfigurationBackup(&ailConfigurationTable[productFamily]); VariableBackup<AILConfiguration *> ailConfigurationBackup(&ailConfigurationTable[productFamily]);
ailConfigurationTable[productFamily] = nullptr; ailConfigurationTable[productFamily] = nullptr;
const char *dummyKernelSources[] = {"kernel void _(){}"}; // if detected - should trigger fallback to CTNI const char *dummyKernelSources[] = {"kernel void _(){}"}; // if detected - should trigger fallback to CTNI
@@ -708,11 +707,11 @@ HWTEST_F(MinimumProgramFixture, givenEmptyAilWhenCreateProgramWithSourcesAndWith
ASSERT_NE(nullptr, pProgram); ASSERT_NE(nullptr, pProgram);
ASSERT_EQ(CL_SUCCESS, retVal); ASSERT_EQ(CL_SUCCESS, retVal);
EXPECT_FALSE(pProgram->enforceFallbackToPatchtokens); EXPECT_FALSE(pProgram->getContext().checkIfContextIsNonZebin());
pProgram->release(); pProgram->release();
} }
TEST_F(MinimumProgramFixture, givenEnforceLegacyBinaryFormatFlagSetWhenBuildingProgramThenInternalOptionsShouldContainDisableZebinOption) { TEST_F(MinimumProgramFixture, givenApplicationContextMarkedAsNonZebinWhenBuildingProgramThenInternalOptionsShouldContainDisableZebinOption) {
const char *kernelSources[] = {"some source code"}; const char *kernelSources[] = {"some source code"};
size_t knownSourceSize = strlen(kernelSources[0]); size_t knownSourceSize = strlen(kernelSources[0]);
@@ -720,7 +719,9 @@ TEST_F(MinimumProgramFixture, givenEnforceLegacyBinaryFormatFlagSetWhenBuildingP
auto pDevice = pContext->getDevice(0); auto pDevice = pContext->getDevice(0);
pDevice->getExecutionEnvironment()->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]->compilerInterface.reset(cip); pDevice->getExecutionEnvironment()->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]->compilerInterface.reset(cip);
auto pProgram = Program::create<SucceedingGenBinaryProgram>( MockProgram *pProgram = nullptr;
pContext->setContextAsNonZebin();
pProgram = Program::create<SucceedingGenBinaryProgram>(
pContext, pContext,
1, 1,
kernelSources, kernelSources,
@@ -730,14 +731,44 @@ TEST_F(MinimumProgramFixture, givenEnforceLegacyBinaryFormatFlagSetWhenBuildingP
ASSERT_NE(nullptr, pProgram); ASSERT_NE(nullptr, pProgram);
ASSERT_EQ(CL_SUCCESS, retVal); ASSERT_EQ(CL_SUCCESS, retVal);
pProgram->enforceFallbackToPatchtokens = true;
retVal = pProgram->build(pProgram->getDevices(), "", false); retVal = pProgram->build(pProgram->getDevices(), "", false);
EXPECT_EQ(CL_SUCCESS, retVal); EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_TRUE(CompilerOptions::contains(cip->buildInternalOptions, CompilerOptions::disableZebin)); EXPECT_TRUE(CompilerOptions::contains(cip->buildInternalOptions, CompilerOptions::disableZebin));
pProgram->release(); pProgram->release();
} }
HWTEST2_F(MinimumProgramFixture, givenAILReturningTrueForFallbackRequirementWhenBuildingProgramThenMarkContextAsNonZebin, IsAtLeastSkl) {
class MockAIL : public AILConfigurationHw<productFamily> {
public:
bool isFallbackToPatchtokensRequired(const std::string &kernelSources) override {
return true;
}
};
VariableBackup<AILConfiguration *> ailConfiguration(&ailConfigurationTable[productFamily]);
MockAIL mockAIL;
ailConfigurationTable[productFamily] = &mockAIL;
ASSERT_FALSE(pContext->checkIfContextIsNonZebin());
const char *kernelSources[] = {"some source code"};
size_t knownSourceSize = strlen(kernelSources[0]);
MockProgram *pProgram = nullptr;
pProgram = Program::create<SucceedingGenBinaryProgram>(
pContext,
1,
kernelSources,
&knownSourceSize,
retVal);
ASSERT_NE(nullptr, pProgram);
ASSERT_EQ(CL_SUCCESS, retVal);
retVal = pProgram->build(pProgram->getDevices(), "", false);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_TRUE(pContext->checkIfContextIsNonZebin());
pProgram->release();
}
TEST_F(ProgramFromSourceTest, GivenSpecificParamatersWhenBuildingProgramThenSuccessOrCorrectErrorCodeIsReturned) { TEST_F(ProgramFromSourceTest, GivenSpecificParamatersWhenBuildingProgramThenSuccessOrCorrectErrorCodeIsReturned) {
KernelBinaryHelper kbHelper(binaryFileName, true); KernelBinaryHelper kbHelper(binaryFileName, true);
auto device = pPlatform->getClDevice(0); auto device = pPlatform->getClDevice(0);

View File

@@ -50,7 +50,7 @@ class AILConfiguration {
virtual void modifyKernelIfRequired(std::string &kernel) = 0; virtual void modifyKernelIfRequired(std::string &kernel) = 0;
virtual void forceFallbackToPatchtokensIfRequired(const std::string &kernelSources, bool &requiresFallback) = 0; virtual bool isFallbackToPatchtokensRequired(const std::string &kernelSources) = 0;
protected: protected:
virtual void applyExt(RuntimeCapabilityTable &runtimeCapabilityTable) = 0; virtual void applyExt(RuntimeCapabilityTable &runtimeCapabilityTable) = 0;
@@ -73,7 +73,7 @@ class AILConfigurationHw : public AILConfiguration {
void applyExt(RuntimeCapabilityTable &runtimeCapabilityTable) override; void applyExt(RuntimeCapabilityTable &runtimeCapabilityTable) override;
void modifyKernelIfRequired(std::string &kernel) override; void modifyKernelIfRequired(std::string &kernel) override;
void forceFallbackToPatchtokensIfRequired(const std::string &kernelSources, bool &requiresFallback) override; bool isFallbackToPatchtokensRequired(const std::string &kernelSources) override;
}; };
template <PRODUCT_FAMILY product> template <PRODUCT_FAMILY product>

View File

@@ -20,20 +20,20 @@ inline void AILConfigurationHw<Product>::modifyKernelIfRequired(std::string &ker
// Only this specific kernel with that exact source code will be affected. // Only this specific kernel with that exact source code will be affected.
template <PRODUCT_FAMILY Product> template <PRODUCT_FAMILY Product>
inline void AILConfigurationHw<Product>::forceFallbackToPatchtokensIfRequired(const std::string &kernelSources, bool &requiresFallback) { inline bool AILConfigurationHw<Product>::isFallbackToPatchtokensRequired(const std::string &kernelSources) {
std::string_view dummyKernelSource{"kernel void _(){}"}; std::string_view dummyKernelSource{"kernel void _(){}"};
if (sourcesContain(kernelSources, dummyKernelSource)) { if (sourcesContain(kernelSources, dummyKernelSource)) {
requiresFallback = true; return true;
} }
for (const auto &name : {"Resolve", for (const auto &name : {"Resolve",
"ArcControlAssist", "ArcControlAssist",
"ArcControl"}) { "ArcControl"}) {
if (processName == name) { if (processName == name) {
requiresFallback = true; return true;
break;
} }
} }
return false;
} }
template <PRODUCT_FAMILY Product> template <PRODUCT_FAMILY Product>

View File

@@ -70,10 +70,10 @@ void AILConfigurationHw<IGFX_DG2>::modifyKernelIfRequired(std::string &kernelsSo
} }
template <> template <>
inline void AILConfigurationHw<IGFX_DG2>::forceFallbackToPatchtokensIfRequired(const std::string &kernelSources, bool &requiresFallback) { inline bool AILConfigurationHw<IGFX_DG2>::isFallbackToPatchtokensRequired(const std::string &kernelSources) {
std::string_view dummyKernelSource{"kernel void _(){}"}; std::string_view dummyKernelSource{"kernel void _(){}"};
if (sourcesContain(kernelSources, dummyKernelSource)) { if (sourcesContain(kernelSources, dummyKernelSource)) {
requiresFallback = true; return true;
} }
for (const auto &name : {"Wondershare Filmora 11", for (const auto &name : {"Wondershare Filmora 11",
@@ -84,10 +84,10 @@ inline void AILConfigurationHw<IGFX_DG2>::forceFallbackToPatchtokensIfRequired(c
"ArcControlAssist", "ArcControlAssist",
"ArcControl"}) { "ArcControl"}) {
if (processName == name) { if (processName == name) {
requiresFallback = true; return true;
break;
} }
} }
return false;
} }
template class AILConfigurationHw<IGFX_DG2>; template class AILConfigurationHw<IGFX_DG2>;

View File

@@ -16,22 +16,14 @@ using AILBaseTests = ::testing::Test;
HWTEST2_F(AILBaseTests, whenKernelSourceIsANGenDummyKernelThenDoEnforcePatchtokensFormat, IsAtLeastSkl) { HWTEST2_F(AILBaseTests, whenKernelSourceIsANGenDummyKernelThenDoEnforcePatchtokensFormat, IsAtLeastSkl) {
std::string dummyKernelSource{"kernel void _(){}"}; std::string dummyKernelSource{"kernel void _(){}"};
bool enforceRebuildToCTNI = false;
AILConfigurationHw<productFamily> ail; AILConfigurationHw<productFamily> ail;
ail.forceFallbackToPatchtokensIfRequired(dummyKernelSource, enforceRebuildToCTNI); EXPECT_TRUE(ail.isFallbackToPatchtokensRequired(dummyKernelSource));
EXPECT_TRUE(enforceRebuildToCTNI);
} }
HWTEST2_F(AILBaseTests, whenKernelSourceIsNotANGenDummyKernelThenDoNotEnforcePatchtokensFormat, IsAtLeastSkl) { HWTEST2_F(AILBaseTests, whenKernelSourceIsNotANGenDummyKernelThenDoNotEnforcePatchtokensFormat, IsAtLeastSkl) {
std::string dummyKernelSource{"kernel void copybuffer(__global int* a, __global int* b){ //some code }"}; std::string dummyKernelSource{"kernel void copybuffer(__global int* a, __global int* b){ //some code }"};
bool enforceRebuildToCTNI = false;
AILConfigurationHw<productFamily> ail; AILConfigurationHw<productFamily> ail;
ail.forceFallbackToPatchtokensIfRequired(dummyKernelSource, enforceRebuildToCTNI); EXPECT_FALSE(ail.isFallbackToPatchtokensRequired(dummyKernelSource));
EXPECT_FALSE(enforceRebuildToCTNI);
} }
HWTEST2_F(AILBaseTests, givenApplicationNamesThatRequirAILWhenCheckingIfPatchtokenFallbackIsRequiredThenIsCorrectResult, IsAtLeastSkl) { HWTEST2_F(AILBaseTests, givenApplicationNamesThatRequirAILWhenCheckingIfPatchtokenFallbackIsRequiredThenIsCorrectResult, IsAtLeastSkl) {
@@ -48,11 +40,7 @@ HWTEST2_F(AILBaseTests, givenApplicationNamesThatRequirAILWhenCheckingIfPatchtok
"ArcControlAssist", "ArcControlAssist",
"ArcControl"}) { "ArcControl"}) {
ail.processName = name; ail.processName = name;
EXPECT_TRUE(ail.isFallbackToPatchtokensRequired(""));
bool fallbackRequired;
ail.forceFallbackToPatchtokensIfRequired("", fallbackRequired);
EXPECT_TRUE(fallbackRequired);
} }
} }

View File

@@ -54,11 +54,7 @@ HWTEST2_F(AILTestsDg2, givenApplicationNamesThatRequirAILWhenCheckingIfPatchtoke
"ArcControlAssist", "ArcControlAssist",
"ArcControl"}) { "ArcControl"}) {
ail.processName = name; ail.processName = name;
EXPECT_TRUE(ail.isFallbackToPatchtokensRequired(""));
bool fallbackRequired;
ail.forceFallbackToPatchtokensIfRequired("", fallbackRequired);
EXPECT_TRUE(fallbackRequired);
} }
} }