From 4147f409706f16c4b67e37e0f67251d90ed21324 Mon Sep 17 00:00:00 2001 From: "Warchulski, Jaroslaw" Date: Fri, 8 Jul 2022 10:39:28 +0000 Subject: [PATCH] DisableKernelRecompilation flag and binary kernel recompilation warning Resolves: NEO-6513 Signed-off-by: Warchulski, Jaroslaw --- opencl/source/program/program.cpp | 3 ++- .../test/unit_test/program/program_tests.cpp | 26 +++++++++++++++++++ .../debug_settings/debug_variables_base.inl | 1 + .../device_binary_format_patchtokens.cpp | 1 + shared/test/common/test_files/igdrcl.config | 1 + ...device_binary_format_patchtokens_tests.cpp | 6 ++--- 6 files changed, 34 insertions(+), 4 deletions(-) diff --git a/opencl/source/program/program.cpp b/opencl/source/program/program.cpp index ead7baf7c5..d94b47c2a0 100644 --- a/opencl/source/program/program.cpp +++ b/opencl/source/program/program.cpp @@ -178,7 +178,8 @@ cl_int Program::createProgramFromBinary( PRINT_DEBUG_STRING(DebugManager.flags.PrintDebugMessages.get(), stderr, "%s\n", decodeWarnings.c_str()); } - if (singleDeviceBinary.intermediateRepresentation.empty() && singleDeviceBinary.deviceBinary.empty()) { + bool singleDeviceBinaryEmpty = singleDeviceBinary.intermediateRepresentation.empty() && singleDeviceBinary.deviceBinary.empty(); + if (singleDeviceBinaryEmpty || (singleDeviceBinary.deviceBinary.empty() && DebugManager.flags.DisableKernelRecompilation.get())) { retVal = CL_INVALID_BINARY; PRINT_DEBUG_STRING(DebugManager.flags.PrintDebugMessages.get(), stderr, "%s\n", decodeErrors.c_str()); } else { diff --git a/opencl/test/unit_test/program/program_tests.cpp b/opencl/test/unit_test/program/program_tests.cpp index 519baa96d9..981fe92422 100644 --- a/opencl/test/unit_test/program/program_tests.cpp +++ b/opencl/test/unit_test/program/program_tests.cpp @@ -1619,6 +1619,32 @@ TEST(ProgramFromBinaryTests, givenBinaryWithInvalidICBEThenErrorIsReturned) { } } +TEST(ProgramFromBinaryTests, givenBinaryWithInvalidICBEAndDisableKernelRecompilationThenErrorIsReturned) { + DebugManagerStateRestore dbgRestorer; + DebugManager.flags.DisableKernelRecompilation.set(true); + cl_int retVal = CL_INVALID_BINARY; + + SProgramBinaryHeader binHeader; + memset(&binHeader, 0, sizeof(binHeader)); + binHeader.Magic = iOpenCL::MAGIC_CL; + binHeader.Version = iOpenCL::CURRENT_ICBE_VERSION - 3; + binHeader.Device = defaultHwInfo->platform.eRenderCoreFamily; + binHeader.GPUPointerSizeInBytes = 8; + binHeader.NumberOfKernels = 0; + binHeader.SteppingId = 0; + binHeader.PatchListSize = 0; + size_t binSize = sizeof(SProgramBinaryHeader); + + { + const unsigned char *binaries[1] = {reinterpret_cast(&binHeader)}; + MockContext context; + + std::unique_ptr pProgram(Program::create(&context, context.getDevices(), &binSize, binaries, nullptr, retVal)); + EXPECT_EQ(nullptr, pProgram.get()); + EXPECT_EQ(CL_INVALID_BINARY, retVal); + } +} + TEST(ProgramFromBinaryTests, givenEmptyProgramThenErrorIsReturned) { cl_int retVal = CL_INVALID_BINARY; diff --git a/shared/source/debug_settings/debug_variables_base.inl b/shared/source/debug_settings/debug_variables_base.inl index e159d0b39e..ec68232a61 100644 --- a/shared/source/debug_settings/debug_variables_base.inl +++ b/shared/source/debug_settings/debug_variables_base.inl @@ -50,6 +50,7 @@ DECLARE_DEBUG_VARIABLE(bool, MakeEachEnqueueBlocking, false, "equivalent of fini DECLARE_DEBUG_VARIABLE(bool, DisableResourceRecycling, false, "when set to true disables resource recycling optimization") DECLARE_DEBUG_VARIABLE(bool, TrackParentEvents, false, "events track their parents") DECLARE_DEBUG_VARIABLE(bool, RebuildPrecompiledKernels, false, "forces driver to recompile precompiled kernels from sources") +DECLARE_DEBUG_VARIABLE(bool, DisableKernelRecompilation, false, "Disable kernel recompilation") DECLARE_DEBUG_VARIABLE(bool, LoopAtDriverInit, false, "Adds endless loop in DebugSettingsManager constructor, useful for debugging.") DECLARE_DEBUG_VARIABLE(bool, DoNotRegisterTrimCallback, false, "When set to true driver does not register trim callback.") DECLARE_DEBUG_VARIABLE(bool, OverrideInvalidEngineWithDefault, false, "When set to true driver chooses engine 0 if no engine is found.") diff --git a/shared/source/device_binary_format/device_binary_format_patchtokens.cpp b/shared/source/device_binary_format/device_binary_format_patchtokens.cpp index e6f7ec43ae..d70e405f97 100644 --- a/shared/source/device_binary_format/device_binary_format_patchtokens.cpp +++ b/shared/source/device_binary_format/device_binary_format_patchtokens.cpp @@ -36,6 +36,7 @@ SingleDeviceBinary unpackSingleDeviceBinaryVersion); if (false == validForTarget) { outErrReason = "Unhandled target device"; + outWarning = "Binary kernel recompilation due to incompatible device"; return {}; } SingleDeviceBinary ret = {}; diff --git a/shared/test/common/test_files/igdrcl.config b/shared/test/common/test_files/igdrcl.config index 2f589ebe09..1788d233eb 100644 --- a/shared/test/common/test_files/igdrcl.config +++ b/shared/test/common/test_files/igdrcl.config @@ -57,6 +57,7 @@ MakeEachEnqueueBlocking = 0 DisableResourceRecycling = 0 TrackParentEvents = 0 RebuildPrecompiledKernels = 0 +DisableKernelRecompilation = 0 LoopAtDriverInit = 0 DoNotRegisterTrimCallback = 0 OverrideInvalidEngineWithDefault = 0 diff --git a/shared/test/unit_test/device_binary_format/device_binary_format_patchtokens_tests.cpp b/shared/test/unit_test/device_binary_format/device_binary_format_patchtokens_tests.cpp index dadac9b102..b5b7bc5ccb 100644 --- a/shared/test/unit_test/device_binary_format/device_binary_format_patchtokens_tests.cpp +++ b/shared/test/unit_test/device_binary_format/device_binary_format_patchtokens_tests.cpp @@ -75,7 +75,7 @@ TEST(UnpackSingleDeviceBinaryPatchtokens, WhenValidBinaryForDifferentCoreFamilyD EXPECT_TRUE(unpackResult.debugData.empty()); EXPECT_TRUE(unpackResult.intermediateRepresentation.empty()); EXPECT_TRUE(unpackResult.buildOptions.empty()); - EXPECT_TRUE(unpackWarnings.empty()); + EXPECT_EQ("Binary kernel recompilation due to incompatible device", unpackWarnings); EXPECT_FALSE(unpackErrors.empty()); EXPECT_STREQ("Unhandled target device", unpackErrors.c_str()); } @@ -99,7 +99,7 @@ TEST(UnpackSingleDeviceBinaryPatchtokens, WhenValidBinaryWithUnsupportedPatchTok EXPECT_TRUE(unpackResult.debugData.empty()); EXPECT_TRUE(unpackResult.intermediateRepresentation.empty()); EXPECT_TRUE(unpackResult.buildOptions.empty()); - EXPECT_TRUE(unpackWarnings.empty()); + EXPECT_EQ("Binary kernel recompilation due to incompatible device", unpackWarnings); EXPECT_FALSE(unpackErrors.empty()); EXPECT_STREQ("Unhandled target device", unpackErrors.c_str()); } @@ -123,7 +123,7 @@ TEST(UnpackSingleDeviceBinaryPatchtokens, WhenValidBinaryWithUnsupportedPointerS EXPECT_TRUE(unpackResult.debugData.empty()); EXPECT_TRUE(unpackResult.intermediateRepresentation.empty()); EXPECT_TRUE(unpackResult.buildOptions.empty()); - EXPECT_TRUE(unpackWarnings.empty()); + EXPECT_EQ("Binary kernel recompilation due to incompatible device", unpackWarnings); EXPECT_FALSE(unpackErrors.empty()); EXPECT_STREQ("Unhandled target device", unpackErrors.c_str()); }