From 234573399d3dc75e134e73ad8e865ada7440004e Mon Sep 17 00:00:00 2001 From: Kamil Kopryk Date: Sun, 1 Jan 2023 17:24:10 +0000 Subject: [PATCH] Refactor: pass gfxCoreHelper to decodeSingleDeviceBinary Related-To: NEO-6853 Signed-off-by: Kamil Kopryk --- level_zero/core/source/module/module_imp.cpp | 5 +- .../source/program/process_device_binary.cpp | 5 +- .../device_binary_format_ar.cpp | 4 +- .../device_binary_format_ocl_elf.cpp | 4 +- .../device_binary_format_patchtokens.cpp | 7 +- .../device_binary_format_zebin.cpp | 4 +- .../device_binary_formats.h | 23 ++-- .../device_binary_format_ocl_elf_tests.cpp | 7 +- ...device_binary_format_patchtokens_tests.cpp | 11 +- .../device_binary_formats_tests.cpp | 27 +++- .../zebin_decoder_tests.cpp | 120 +++++++++++++----- 11 files changed, 150 insertions(+), 67 deletions(-) diff --git a/level_zero/core/source/module/module_imp.cpp b/level_zero/core/source/module/module_imp.cpp index 7dd6b4e998..96e3de43d7 100644 --- a/level_zero/core/source/module/module_imp.cpp +++ b/level_zero/core/source/module/module_imp.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2022 Intel Corporation + * Copyright (C) 2020-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -348,7 +348,8 @@ ze_result_t ModuleTranslationUnit::processUnpackedBinary() { NEO::DecodeError decodeError; NEO::DeviceBinaryFormat singleDeviceBinaryFormat; - std::tie(decodeError, singleDeviceBinaryFormat) = NEO::decodeSingleDeviceBinary(programInfo, binary, decodeErrors, decodeWarnings); + auto &gfxCoreHelper = device->getGfxCoreHelper(); + std::tie(decodeError, singleDeviceBinaryFormat) = NEO::decodeSingleDeviceBinary(programInfo, binary, decodeErrors, decodeWarnings, gfxCoreHelper); if (decodeWarnings.empty() == false) { PRINT_DEBUG_STRING(NEO::DebugManager.flags.PrintDebugMessages.get(), stderr, "%s\n", decodeWarnings.c_str()); } diff --git a/opencl/source/program/process_device_binary.cpp b/opencl/source/program/process_device_binary.cpp index 332063a187..d5872e495b 100644 --- a/opencl/source/program/process_device_binary.cpp +++ b/opencl/source/program/process_device_binary.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2022 Intel Corporation + * Copyright (C) 2020-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -213,7 +213,8 @@ cl_int Program::processGenBinary(const ClDevice &clDevice) { DecodeError decodeError; DeviceBinaryFormat singleDeviceBinaryFormat; - std::tie(decodeError, singleDeviceBinaryFormat) = NEO::decodeSingleDeviceBinary(programInfo, binary, decodeErrors, decodeWarnings); + auto &gfxCoreHelper = clDevice.getGfxCoreHelper(); + std::tie(decodeError, singleDeviceBinaryFormat) = NEO::decodeSingleDeviceBinary(programInfo, binary, decodeErrors, decodeWarnings, gfxCoreHelper); if (decodeWarnings.empty() == false) { PRINT_DEBUG_STRING(DebugManager.flags.PrintDebugMessages.get(), stderr, "%s\n", decodeWarnings.c_str()); diff --git a/shared/source/device_binary_format/device_binary_format_ar.cpp b/shared/source/device_binary_format/device_binary_format_ar.cpp index 4cc3588da5..a1523b5450 100644 --- a/shared/source/device_binary_format/device_binary_format_ar.cpp +++ b/shared/source/device_binary_format/device_binary_format_ar.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2022 Intel Corporation + * Copyright (C) 2020-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -87,7 +87,7 @@ SingleDeviceBinary unpackSingleDeviceBinary(co } template <> -DecodeError decodeSingleDeviceBinary(ProgramInfo &dst, const SingleDeviceBinary &src, std::string &outErrReason, std::string &outWarning) { +DecodeError decodeSingleDeviceBinary(ProgramInfo &dst, const SingleDeviceBinary &src, std::string &outErrReason, std::string &outWarning, const GfxCoreHelper &gfxCoreHelper) { // packed binary format outErrReason = "Device binary format is packed"; return DecodeError::InvalidBinary; diff --git a/shared/source/device_binary_format/device_binary_format_ocl_elf.cpp b/shared/source/device_binary_format/device_binary_format_ocl_elf.cpp index 7c460fae7b..6b94e2220b 100644 --- a/shared/source/device_binary_format/device_binary_format_ocl_elf.cpp +++ b/shared/source/device_binary_format/device_binary_format_ocl_elf.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2022 Intel Corporation + * Copyright (C) 2020-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -111,7 +111,7 @@ SingleDeviceBinary unpackSingleDeviceBinary(con } template <> -DecodeError decodeSingleDeviceBinary(ProgramInfo &dst, const SingleDeviceBinary &src, std::string &outErrReason, std::string &outWarning) { +DecodeError decodeSingleDeviceBinary(ProgramInfo &dst, const SingleDeviceBinary &src, std::string &outErrReason, std::string &outWarning, const GfxCoreHelper &gfxCoreHelper) { // packed binary format outErrReason = "Device binary format is packed"; return DecodeError::InvalidBinary; 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 79eba5e88a..2d5f6162b2 100644 --- a/shared/source/device_binary_format/device_binary_format_patchtokens.cpp +++ b/shared/source/device_binary_format/device_binary_format_patchtokens.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2022 Intel Corporation + * Copyright (C) 2020-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -47,7 +47,7 @@ SingleDeviceBinary unpackSingleDeviceBinary -DecodeError decodeSingleDeviceBinary(ProgramInfo &dst, const SingleDeviceBinary &src, std::string &outErrReason, std::string &outWarning) { +DecodeError decodeSingleDeviceBinary(ProgramInfo &dst, const SingleDeviceBinary &src, std::string &outErrReason, std::string &outWarning, const GfxCoreHelper &gfxCoreHelper) { NEO::PatchTokenBinary::ProgramFromPatchtokens decodedProgram = {}; NEO::PatchTokenBinary::decodeProgramFromPatchtokensBlob(src.deviceBinary, decodedProgram); DBG_LOG(LogPatchTokens, NEO::PatchTokenBinary::asString(decodedProgram).c_str()); @@ -62,8 +62,7 @@ DecodeError decodeSingleDeviceBinary(Progr NEO::populateProgramInfo(dst, decodedProgram); // set barrierCount to number of barriers decoded from hasBarriers token - UNRECOVERABLE_IF(src.targetDevice.coreFamily == IGFX_UNKNOWN_CORE); - auto &gfxCoreHelper = NEO::GfxCoreHelper::get(src.targetDevice.coreFamily); + for (auto &ki : dst.kernelInfos) { auto &kd = ki->kernelDescriptor; kd.kernelAttributes.barrierCount = gfxCoreHelper.getBarriersCountFromHasBarriers(kd.kernelAttributes.barrierCount); diff --git a/shared/source/device_binary_format/device_binary_format_zebin.cpp b/shared/source/device_binary_format/device_binary_format_zebin.cpp index e6182fe0d4..b61106afc6 100644 --- a/shared/source/device_binary_format/device_binary_format_zebin.cpp +++ b/shared/source/device_binary_format/device_binary_format_zebin.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2022 Intel Corporation + * Copyright (C) 2020-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -115,7 +115,7 @@ DecodeError decodeSingleZebin(ProgramInfo &dst, const SingleDeviceBinary &src, s } template <> -DecodeError decodeSingleDeviceBinary(ProgramInfo &dst, const SingleDeviceBinary &src, std::string &outErrReason, std::string &outWarning) { +DecodeError decodeSingleDeviceBinary(ProgramInfo &dst, const SingleDeviceBinary &src, std::string &outErrReason, std::string &outWarning, const GfxCoreHelper &gfxCoreHelper) { return Elf::isElf(src.deviceBinary) ? decodeSingleZebin(dst, src, outErrReason, outWarning) : decodeSingleZebin(dst, src, outErrReason, outWarning); diff --git a/shared/source/device_binary_format/device_binary_formats.h b/shared/source/device_binary_format/device_binary_formats.h index 5b54ace076..2dcc1f7f61 100644 --- a/shared/source/device_binary_format/device_binary_formats.h +++ b/shared/source/device_binary_format/device_binary_formats.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2022 Intel Corporation + * Copyright (C) 2020-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -19,6 +19,7 @@ namespace NEO { struct ProgramInfo; struct RootDeviceEnvironment; +class GfxCoreHelper; enum class DeviceBinaryFormat : uint8_t { Unknown, @@ -160,33 +161,33 @@ inline bool isAnySingleDeviceBinaryFormat(const ArrayRef binary) } template -DecodeError decodeSingleDeviceBinary(ProgramInfo &dst, const SingleDeviceBinary &src, std::string &outErrReason, std::string &outWarning); +DecodeError decodeSingleDeviceBinary(ProgramInfo &dst, const SingleDeviceBinary &src, std::string &outErrReason, std::string &outWarning, const GfxCoreHelper &gfxCoreHelper); template <> -DecodeError decodeSingleDeviceBinary(ProgramInfo &, const SingleDeviceBinary &, std::string &, std::string &); +DecodeError decodeSingleDeviceBinary(ProgramInfo &, const SingleDeviceBinary &, std::string &, std::string &, const GfxCoreHelper &gfxCoreHelper); template <> -DecodeError decodeSingleDeviceBinary(ProgramInfo &, const SingleDeviceBinary &, std::string &, std::string &); +DecodeError decodeSingleDeviceBinary(ProgramInfo &, const SingleDeviceBinary &, std::string &, std::string &, const GfxCoreHelper &gfxCoreHelper); template <> -DecodeError decodeSingleDeviceBinary(ProgramInfo &, const SingleDeviceBinary &, std::string &, std::string &); +DecodeError decodeSingleDeviceBinary(ProgramInfo &, const SingleDeviceBinary &, std::string &, std::string &, const GfxCoreHelper &gfxCoreHelper); template <> -DecodeError decodeSingleDeviceBinary(ProgramInfo &, const SingleDeviceBinary &, std::string &, std::string &); +DecodeError decodeSingleDeviceBinary(ProgramInfo &, const SingleDeviceBinary &, std::string &, std::string &, const GfxCoreHelper &gfxCoreHelper); -inline std::pair decodeSingleDeviceBinary(ProgramInfo &dst, const SingleDeviceBinary &src, std::string &outErrReason, std::string &outWarning) { +inline std::pair decodeSingleDeviceBinary(ProgramInfo &dst, const SingleDeviceBinary &src, std::string &outErrReason, std::string &outWarning, const GfxCoreHelper &gfxCoreHelper) { std::pair ret; ret.first = DecodeError::InvalidBinary; ret.second = DeviceBinaryFormat::Unknown; if (isDeviceBinaryFormat(src.deviceBinary)) { ret.second = DeviceBinaryFormat::OclElf; - ret.first = decodeSingleDeviceBinary(dst, src, outErrReason, outWarning); + ret.first = decodeSingleDeviceBinary(dst, src, outErrReason, outWarning, gfxCoreHelper); } else if (isDeviceBinaryFormat(src.deviceBinary)) { ret.second = DeviceBinaryFormat::Patchtokens; - ret.first = decodeSingleDeviceBinary(dst, src, outErrReason, outWarning); + ret.first = decodeSingleDeviceBinary(dst, src, outErrReason, outWarning, gfxCoreHelper); } else if (isDeviceBinaryFormat(src.deviceBinary)) { ret.second = DeviceBinaryFormat::Archive; - ret.first = decodeSingleDeviceBinary(dst, src, outErrReason, outWarning); + ret.first = decodeSingleDeviceBinary(dst, src, outErrReason, outWarning, gfxCoreHelper); } else if (isDeviceBinaryFormat(src.deviceBinary)) { ret.second = DeviceBinaryFormat::Zebin; - ret.first = decodeSingleDeviceBinary(dst, src, outErrReason, outWarning); + ret.first = decodeSingleDeviceBinary(dst, src, outErrReason, outWarning, gfxCoreHelper); } else { outErrReason = "Unknown format"; } diff --git a/shared/test/unit_test/device_binary_format/device_binary_format_ocl_elf_tests.cpp b/shared/test/unit_test/device_binary_format/device_binary_format_ocl_elf_tests.cpp index fe136902a4..8de63662b7 100644 --- a/shared/test/unit_test/device_binary_format/device_binary_format_ocl_elf_tests.cpp +++ b/shared/test/unit_test/device_binary_format/device_binary_format_ocl_elf_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2022 Intel Corporation + * Copyright (C) 2020-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -12,6 +12,7 @@ #include "shared/source/device_binary_format/elf/ocl_elf.h" #include "shared/source/program/program_info.h" #include "shared/test/common/device_binary_format/patchtokens_tests.h" +#include "shared/test/common/mocks/mock_execution_environment.h" #include "shared/test/common/test_macros/test.h" #include @@ -213,6 +214,8 @@ TEST(UnpackSingleDeviceBinaryOclElf, GivenOclElfExecutableWhenPatchtokensBinaryI } TEST(DecodeSingleDeviceBinaryOclElf, WhenUsedAsSingleDeviceBinaryThenDecodingFails) { + NEO::MockExecutionEnvironment mockExecutionEnvironment{}; + auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); PatchTokensTestData::ValidEmptyProgram patchtokensProgram; NEO::Elf::ElfEncoder elfEnc64; @@ -232,7 +235,7 @@ TEST(DecodeSingleDeviceBinaryOclElf, WhenUsedAsSingleDeviceBinaryThenDecodingFai std::string unpackErrors; std::string unpackWarnings; NEO::ProgramInfo programInfo; - NEO::DecodeError error = NEO::decodeSingleDeviceBinary(programInfo, deviceBinary, unpackErrors, unpackWarnings); + NEO::DecodeError error = NEO::decodeSingleDeviceBinary(programInfo, deviceBinary, unpackErrors, unpackWarnings, gfxCoreHelper); EXPECT_EQ(NEO::DecodeError::InvalidBinary, error); EXPECT_TRUE(unpackWarnings.empty()); EXPECT_FALSE(unpackErrors.empty()); 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 bfe96653db..4102652707 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 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2022 Intel Corporation + * Copyright (C) 2020-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -8,6 +8,7 @@ #include "shared/source/device_binary_format/device_binary_formats.h" #include "shared/source/program/program_info.h" #include "shared/test/common/device_binary_format/patchtokens_tests.h" +#include "shared/test/common/mocks/mock_execution_environment.h" #include "shared/test/common/test_macros/test.h" TEST(IsDeviceBinaryFormatPatchtokens, GivenValidBinaryThenReturnTrue) { @@ -129,11 +130,13 @@ TEST(UnpackSingleDeviceBinaryPatchtokens, WhenValidBinaryWithUnsupportedPointerS } TEST(DecodeSingleDeviceBinaryPatchtokens, GivenInvalidBinaryThenReturnError) { + NEO::MockExecutionEnvironment mockExecutionEnvironment{}; + auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); NEO::ProgramInfo programInfo; NEO::SingleDeviceBinary singleBinary; std::string decodeErrors; std::string decodeWarnings; - auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings); + auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings, gfxCoreHelper); EXPECT_EQ(NEO::DecodeError::InvalidBinary, error); EXPECT_TRUE(decodeWarnings.empty()); EXPECT_FALSE(decodeErrors.empty()); @@ -141,6 +144,8 @@ TEST(DecodeSingleDeviceBinaryPatchtokens, GivenInvalidBinaryThenReturnError) { } TEST(DecodeSingleDeviceBinaryPatchtokens, GivenValidBinaryThenOutputIsProperlyPopulated) { + NEO::MockExecutionEnvironment mockExecutionEnvironment{}; + auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); PatchTokensTestData::ValidProgramWithKernel programTokens; NEO::ProgramInfo programInfo; NEO::SingleDeviceBinary singleBinary; @@ -148,7 +153,7 @@ TEST(DecodeSingleDeviceBinaryPatchtokens, GivenValidBinaryThenOutputIsProperlyPo singleBinary.targetDevice.coreFamily = static_cast(programTokens.header->Device); std::string decodeErrors; std::string decodeWarnings; - auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings); + auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings, gfxCoreHelper); EXPECT_EQ(NEO::DecodeError::Success, error); EXPECT_TRUE(decodeWarnings.empty()); EXPECT_TRUE(decodeErrors.empty()); diff --git a/shared/test/unit_test/device_binary_format/device_binary_formats_tests.cpp b/shared/test/unit_test/device_binary_format/device_binary_formats_tests.cpp index be3b9f260e..3c7f75e1ac 100644 --- a/shared/test/unit_test/device_binary_format/device_binary_formats_tests.cpp +++ b/shared/test/unit_test/device_binary_format/device_binary_formats_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2022 Intel Corporation + * Copyright (C) 2020-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -11,6 +11,7 @@ #include "shared/source/device_binary_format/elf/ocl_elf.h" #include "shared/source/program/program_info.h" #include "shared/test/common/device_binary_format/patchtokens_tests.h" +#include "shared/test/common/mocks/mock_execution_environment.h" #include "shared/test/common/mocks/mock_modules_zebin.h" #include "shared/test/common/test_macros/test.h" @@ -238,6 +239,8 @@ TEST(IsAnySingleDeviceBinaryFormat, GivenZebinFormatThenReturnsTrue) { } TEST(DecodeSingleDeviceBinary, GivenUnknownFormatThenReturnFalse) { + NEO::MockExecutionEnvironment mockExecutionEnvironment{}; + auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); const uint8_t data[] = "none of known formats"; NEO::ProgramInfo programInfo; std::string decodeErrors; @@ -246,7 +249,7 @@ TEST(DecodeSingleDeviceBinary, GivenUnknownFormatThenReturnFalse) { bin.deviceBinary = data; NEO::DecodeError status; NEO::DeviceBinaryFormat format; - std::tie(status, format) = NEO::decodeSingleDeviceBinary(programInfo, bin, decodeErrors, decodeWarnings); + std::tie(status, format) = NEO::decodeSingleDeviceBinary(programInfo, bin, decodeErrors, decodeWarnings, gfxCoreHelper); EXPECT_EQ(NEO::DecodeError::InvalidBinary, status); EXPECT_EQ(NEO::DeviceBinaryFormat::Unknown, format); EXPECT_TRUE(decodeWarnings.empty()); @@ -254,6 +257,8 @@ TEST(DecodeSingleDeviceBinary, GivenUnknownFormatThenReturnFalse) { } TEST(DecodeSingleDeviceBinary, GivenPatchTokensFormatThenDecodingSucceeds) { + NEO::MockExecutionEnvironment mockExecutionEnvironment{}; + auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); PatchTokensTestData::ValidEmptyProgram patchtokensProgram; NEO::ProgramInfo programInfo; std::string decodeErrors; @@ -263,7 +268,7 @@ TEST(DecodeSingleDeviceBinary, GivenPatchTokensFormatThenDecodingSucceeds) { bin.targetDevice.coreFamily = static_cast(patchtokensProgram.header->Device); NEO::DecodeError status; NEO::DeviceBinaryFormat format; - std::tie(status, format) = NEO::decodeSingleDeviceBinary(programInfo, bin, decodeErrors, decodeWarnings); + std::tie(status, format) = NEO::decodeSingleDeviceBinary(programInfo, bin, decodeErrors, decodeWarnings, gfxCoreHelper); EXPECT_EQ(NEO::DecodeError::Success, status); EXPECT_EQ(NEO::DeviceBinaryFormat::Patchtokens, format); EXPECT_TRUE(decodeWarnings.empty()); @@ -271,6 +276,8 @@ TEST(DecodeSingleDeviceBinary, GivenPatchTokensFormatThenDecodingSucceeds) { } TEST(DecodeSingleDeviceBinary, GivenZebinFormatThenDecodingSucceeds) { + NEO::MockExecutionEnvironment mockExecutionEnvironment{}; + auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); ZebinTestData::ValidEmptyProgram zebinElf; NEO::ProgramInfo programInfo; std::string decodeErrors; @@ -279,7 +286,7 @@ TEST(DecodeSingleDeviceBinary, GivenZebinFormatThenDecodingSucceeds) { bin.deviceBinary = zebinElf.storage; NEO::DecodeError status; NEO::DeviceBinaryFormat format; - std::tie(status, format) = NEO::decodeSingleDeviceBinary(programInfo, bin, decodeErrors, decodeWarnings); + std::tie(status, format) = NEO::decodeSingleDeviceBinary(programInfo, bin, decodeErrors, decodeWarnings, gfxCoreHelper); EXPECT_EQ(NEO::DecodeError::Success, status); EXPECT_EQ(NEO::DeviceBinaryFormat::Zebin, format); EXPECT_TRUE(decodeWarnings.empty()) << decodeWarnings; @@ -287,6 +294,8 @@ TEST(DecodeSingleDeviceBinary, GivenZebinFormatThenDecodingSucceeds) { } TEST(DecodeSingleDeviceBinary, GivenZebinWithExternalFunctionsThenDecodingSucceedsAndLinkerInputIsSet) { + NEO::MockExecutionEnvironment mockExecutionEnvironment{}; + auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); ZebinTestData::ZebinWithExternalFunctionsInfo zebinElf; NEO::ProgramInfo programInfo; std::string decodeErrors; @@ -295,7 +304,7 @@ TEST(DecodeSingleDeviceBinary, GivenZebinWithExternalFunctionsThenDecodingSuccee bin.deviceBinary = zebinElf.storage; NEO::DecodeError status; NEO::DeviceBinaryFormat format; - std::tie(status, format) = NEO::decodeSingleDeviceBinary(programInfo, bin, decodeErrors, decodeWarnings); + std::tie(status, format) = NEO::decodeSingleDeviceBinary(programInfo, bin, decodeErrors, decodeWarnings, gfxCoreHelper); EXPECT_EQ(NEO::DecodeError::Success, status); EXPECT_EQ(NEO::DeviceBinaryFormat::Zebin, format); EXPECT_TRUE(decodeErrors.empty()) << decodeErrors; @@ -304,6 +313,8 @@ TEST(DecodeSingleDeviceBinary, GivenZebinWithExternalFunctionsThenDecodingSuccee } TEST(DecodeSingleDeviceBinary, GivenOclElfFormatThenDecodingFails) { + NEO::MockExecutionEnvironment mockExecutionEnvironment{}; + auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); PatchTokensTestData::ValidEmptyProgram patchtokensProgram; NEO::Elf::ElfEncoder elfEnc; @@ -318,7 +329,7 @@ TEST(DecodeSingleDeviceBinary, GivenOclElfFormatThenDecodingFails) { bin.deviceBinary = elfData; NEO::DecodeError status; NEO::DeviceBinaryFormat format; - std::tie(status, format) = NEO::decodeSingleDeviceBinary(programInfo, bin, decodeErrors, decodeWarnings); + std::tie(status, format) = NEO::decodeSingleDeviceBinary(programInfo, bin, decodeErrors, decodeWarnings, gfxCoreHelper); EXPECT_EQ(NEO::DecodeError::InvalidBinary, status); EXPECT_EQ(NEO::DeviceBinaryFormat::OclElf, format); EXPECT_TRUE(decodeWarnings.empty()); @@ -326,6 +337,8 @@ TEST(DecodeSingleDeviceBinary, GivenOclElfFormatThenDecodingFails) { } TEST(DecodeSingleDeviceBinary, GivenArFormatThenDecodingFails) { + NEO::MockExecutionEnvironment mockExecutionEnvironment{}; + auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); NEO::Ar::ArEncoder arEnc; auto arData = arEnc.encode(); NEO::ProgramInfo programInfo; @@ -335,7 +348,7 @@ TEST(DecodeSingleDeviceBinary, GivenArFormatThenDecodingFails) { bin.deviceBinary = arData; NEO::DecodeError status; NEO::DeviceBinaryFormat format; - std::tie(status, format) = NEO::decodeSingleDeviceBinary(programInfo, bin, decodeErrors, decodeWarnings); + std::tie(status, format) = NEO::decodeSingleDeviceBinary(programInfo, bin, decodeErrors, decodeWarnings, gfxCoreHelper); EXPECT_EQ(NEO::DecodeError::InvalidBinary, status); EXPECT_EQ(NEO::DeviceBinaryFormat::Archive, format); EXPECT_TRUE(decodeWarnings.empty()); diff --git a/shared/test/unit_test/device_binary_format/zebin_decoder_tests.cpp b/shared/test/unit_test/device_binary_format/zebin_decoder_tests.cpp index 82f32b16c3..fa76e585f0 100644 --- a/shared/test/unit_test/device_binary_format/zebin_decoder_tests.cpp +++ b/shared/test/unit_test/device_binary_format/zebin_decoder_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2022 Intel Corporation + * Copyright (C) 2020-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -17,6 +17,7 @@ #include "shared/source/program/program_info.h" #include "shared/test/common/helpers/debug_manager_state_restore.h" #include "shared/test/common/mocks/mock_elf.h" +#include "shared/test/common/mocks/mock_execution_environment.h" #include "shared/test/common/mocks/mock_modules_zebin.h" #include "shared/test/common/test_macros/test.h" @@ -2562,24 +2563,28 @@ kernels: } TEST(DecodeSingleDeviceBinaryZebin, GivenValid32BitZebinThenReturnSuccess) { + NEO::MockExecutionEnvironment mockExecutionEnvironment{}; + auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); NEO::ProgramInfo programInfo; NEO::SingleDeviceBinary singleBinary; ZebinTestData::ValidEmptyProgram zebin; singleBinary.deviceBinary = {zebin.storage.data(), zebin.storage.size()}; std::string decodeErrors; std::string decodeWarnings; - auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings); + auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings, gfxCoreHelper); EXPECT_EQ(NEO::DecodeError::Success, error); EXPECT_TRUE(decodeWarnings.empty()); EXPECT_TRUE(decodeErrors.empty()); } TEST(DecodeSingleDeviceBinaryZebin, GivenInvalidElfThenReturnError) { + NEO::MockExecutionEnvironment mockExecutionEnvironment{}; + auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); NEO::ProgramInfo programInfo; NEO::SingleDeviceBinary singleBinary; std::string decodeErrors; std::string decodeWarnings; - auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings); + auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings, gfxCoreHelper); EXPECT_EQ(NEO::DecodeError::InvalidBinary, error); EXPECT_TRUE(decodeWarnings.empty()); EXPECT_FALSE(decodeErrors.empty()); @@ -2587,6 +2592,8 @@ TEST(DecodeSingleDeviceBinaryZebin, GivenInvalidElfThenReturnError) { } TEST(DecodeSingleDeviceBinaryZebin, WhenFailedToExtractZebinSectionsThenDecodingFails) { + NEO::MockExecutionEnvironment mockExecutionEnvironment{}; + auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); ZebinTestData::ValidEmptyProgram zebin; zebin.elfHeader->shStrNdx = NEO::Elf::SHN_UNDEF; @@ -2595,7 +2602,7 @@ TEST(DecodeSingleDeviceBinaryZebin, WhenFailedToExtractZebinSectionsThenDecoding singleBinary.deviceBinary = zebin.storage; std::string decodeErrors; std::string decodeWarnings; - auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings); + auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings, gfxCoreHelper); EXPECT_EQ(NEO::DecodeError::InvalidBinary, error); EXPECT_TRUE(decodeWarnings.empty()) << decodeWarnings; EXPECT_FALSE(decodeErrors.empty()); @@ -2614,6 +2621,8 @@ TEST(DecodeSingleDeviceBinaryZebin, WhenFailedToExtractZebinSectionsThenDecoding } TEST(DecodeSingleDeviceBinaryZebin, WhenValidationOfZebinSectionsCountFailsThenDecodingFails) { + NEO::MockExecutionEnvironment mockExecutionEnvironment{}; + auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); ZebinTestData::ValidEmptyProgram zebin; zebin.appendSection(NEO::Elf::SHT_ZEBIN_SPIRV, NEO::Elf::SectionsNamesZebin::spv, {}); zebin.appendSection(NEO::Elf::SHT_ZEBIN_SPIRV, NEO::Elf::SectionsNamesZebin::spv, {}); @@ -2623,7 +2632,7 @@ TEST(DecodeSingleDeviceBinaryZebin, WhenValidationOfZebinSectionsCountFailsThenD singleBinary.deviceBinary = zebin.storage; std::string decodeErrors; std::string decodeWarnings; - auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings); + auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings, gfxCoreHelper); EXPECT_EQ(NEO::DecodeError::InvalidBinary, error); EXPECT_TRUE(decodeWarnings.empty()) << decodeWarnings; EXPECT_FALSE(decodeErrors.empty()); @@ -2649,6 +2658,8 @@ TEST(DecodeSingleDeviceBinaryZebin, WhenValidationOfZebinSectionsCountFailsThenD } TEST(DecodeSingleDeviceBinaryZebin, GivenGlobalDataSectionThenSetsUpInitDataAndSize) { + NEO::MockExecutionEnvironment mockExecutionEnvironment{}; + auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); ZebinTestData::ValidEmptyProgram zebin; const uint8_t data[] = {2, 3, 5, 7, 11, 13, 17, 19}; zebin.appendSection(NEO::Elf::SHT_PROGBITS, NEO::Elf::SectionsNamesZebin::dataGlobal, data); @@ -2658,7 +2669,7 @@ TEST(DecodeSingleDeviceBinaryZebin, GivenGlobalDataSectionThenSetsUpInitDataAndS singleBinary.deviceBinary = zebin.storage; std::string decodeErrors; std::string decodeWarnings; - auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings); + auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings, gfxCoreHelper); EXPECT_EQ(NEO::DecodeError::Success, error); EXPECT_TRUE(decodeWarnings.empty()) << decodeWarnings; EXPECT_TRUE(decodeErrors.empty()) << decodeErrors; @@ -2669,6 +2680,8 @@ TEST(DecodeSingleDeviceBinaryZebin, GivenGlobalDataSectionThenSetsUpInitDataAndS } TEST(DecodeSingleDeviceBinaryZebin, GivenConstDataSectionThenSetsUpInitDataAndSize) { + NEO::MockExecutionEnvironment mockExecutionEnvironment{}; + auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); ZebinTestData::ValidEmptyProgram zebin; const uint8_t data[] = {2, 3, 5, 7, 11, 13, 17, 19}; zebin.appendSection(NEO::Elf::SHT_PROGBITS, NEO::Elf::SectionsNamesZebin::dataConst, data); @@ -2678,7 +2691,7 @@ TEST(DecodeSingleDeviceBinaryZebin, GivenConstDataSectionThenSetsUpInitDataAndSi singleBinary.deviceBinary = zebin.storage; std::string decodeErrors; std::string decodeWarnings; - auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings); + auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings, gfxCoreHelper); EXPECT_EQ(NEO::DecodeError::Success, error); EXPECT_TRUE(decodeWarnings.empty()) << decodeWarnings; EXPECT_TRUE(decodeErrors.empty()) << decodeErrors; @@ -2689,6 +2702,8 @@ TEST(DecodeSingleDeviceBinaryZebin, GivenConstDataSectionThenSetsUpInitDataAndSi } TEST(DecodeSingleDeviceBinaryZebin, GivenConstDataStringsSectionThenSetsUpInitDataAndSize) { + NEO::MockExecutionEnvironment mockExecutionEnvironment{}; + auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); ZebinTestData::ValidEmptyProgram zebin; const uint8_t data[] = {'H', 'e', 'l', 'l', 'o', '!'}; zebin.appendSection(NEO::Elf::SHT_PROGBITS, NEO::Elf::SectionsNamesZebin::dataConstString, data); @@ -2698,7 +2713,7 @@ TEST(DecodeSingleDeviceBinaryZebin, GivenConstDataStringsSectionThenSetsUpInitDa singleBinary.deviceBinary = zebin.storage; std::string decodeErrors; std::string decodeWarnings; - auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings); + auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings, gfxCoreHelper); EXPECT_EQ(NEO::DecodeError::Success, error); EXPECT_TRUE(decodeWarnings.empty()) << decodeWarnings; EXPECT_TRUE(decodeErrors.empty()) << decodeErrors; @@ -2758,6 +2773,8 @@ TEST(DecodeSingleDeviceBinaryZebin, GivenNoteSectionDifferentThanIntelGTThenEmit } TEST(DecodeSingleDeviceBinaryZebin, GivenSymtabSectionThenEmitsWarningAndSkipsIt) { + NEO::MockExecutionEnvironment mockExecutionEnvironment{}; + auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); ZebinTestData::ValidEmptyProgram zebin; const uint8_t data[] = {2, 3, 5, 7, 11, 13, 17, 19}; zebin.appendSection(NEO::Elf::SHT_SYMTAB, NEO::Elf::SectionsNamesZebin::symtab, data).entsize = sizeof(NEO::Elf::ElfSymbolEntry); @@ -2767,13 +2784,15 @@ TEST(DecodeSingleDeviceBinaryZebin, GivenSymtabSectionThenEmitsWarningAndSkipsIt singleBinary.deviceBinary = zebin.storage; std::string decodeErrors; std::string decodeWarnings; - auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings); + auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings, gfxCoreHelper); EXPECT_EQ(NEO::DecodeError::Success, error); EXPECT_STREQ("DeviceBinaryFormat::Zebin : Ignoring symbol table\n", decodeWarnings.c_str()); EXPECT_TRUE(decodeErrors.empty()) << decodeErrors; } TEST(DecodeSingleDeviceBinaryZebin, GivenSymtabWithInvalidSymEntriesThenFails) { + NEO::MockExecutionEnvironment mockExecutionEnvironment{}; + auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); ZebinTestData::ValidEmptyProgram zebin; const uint8_t data[] = {2, 3, 5, 7, 11, 13, 17, 19}; zebin.appendSection(NEO::Elf::SHT_SYMTAB, NEO::Elf::SectionsNamesZebin::symtab, data).entsize = sizeof(NEO::Elf::ElfSymbolEntry) - 1; @@ -2783,13 +2802,15 @@ TEST(DecodeSingleDeviceBinaryZebin, GivenSymtabWithInvalidSymEntriesThenFails) { singleBinary.deviceBinary = zebin.storage; std::string decodeErrors; std::string decodeWarnings; - auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings); + auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings, gfxCoreHelper); EXPECT_EQ(NEO::DecodeError::InvalidBinary, error); EXPECT_STREQ("Invalid symbol table entries size - expected : 24, got : 23\n", decodeErrors.c_str()); EXPECT_TRUE(decodeWarnings.empty()) << decodeWarnings; } TEST(DecodeSingleDeviceBinaryZebin, WhenZeInfoSectionIsEmptyThenEmitsWarning) { + NEO::MockExecutionEnvironment mockExecutionEnvironment{}; + auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); ZebinTestData::ValidEmptyProgram zebin; zebin.removeSection(NEO::Elf::SHT_ZEBIN::SHT_ZEBIN_ZEINFO, NEO::Elf::SectionsNamesZebin::zeInfo); @@ -2798,13 +2819,15 @@ TEST(DecodeSingleDeviceBinaryZebin, WhenZeInfoSectionIsEmptyThenEmitsWarning) { singleBinary.deviceBinary = zebin.storage; std::string decodeErrors; std::string decodeWarnings; - auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings); + auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings, gfxCoreHelper); EXPECT_EQ(NEO::DecodeError::Success, error); EXPECT_STREQ("DeviceBinaryFormat::Zebin : Expected at least one .ze_info section, got 0\n", decodeWarnings.c_str()); EXPECT_TRUE(decodeErrors.empty()) << decodeErrors; } TEST(DecodeSingleDeviceBinaryZebin, WhenYamlParserForZeInfoFailsThenDecodingFails) { + NEO::MockExecutionEnvironment mockExecutionEnvironment{}; + auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); ZebinTestData::ValidEmptyProgram zebin; zebin.removeSection(NEO::Elf::SHT_ZEBIN::SHT_ZEBIN_ZEINFO, NEO::Elf::SectionsNamesZebin::zeInfo); auto brokenZeInfo = NEO::ConstStringRef("unterminated_string : \""); @@ -2815,7 +2838,7 @@ TEST(DecodeSingleDeviceBinaryZebin, WhenYamlParserForZeInfoFailsThenDecodingFail singleBinary.deviceBinary = zebin.storage; std::string decodeErrors; std::string decodeWarnings; - auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings); + auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings, gfxCoreHelper); EXPECT_EQ(NEO::DecodeError::InvalidBinary, error); EXPECT_TRUE(decodeWarnings.empty()) << decodeWarnings; @@ -2829,6 +2852,8 @@ TEST(DecodeSingleDeviceBinaryZebin, WhenYamlParserForZeInfoFailsThenDecodingFail } TEST(DecodeSingleDeviceBinaryZebin, GivenEmptyInZeInfoThenEmitsWarning) { + NEO::MockExecutionEnvironment mockExecutionEnvironment{}; + auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); ZebinTestData::ValidEmptyProgram zebin; zebin.removeSection(NEO::Elf::SHT_ZEBIN::SHT_ZEBIN_ZEINFO, NEO::Elf::SectionsNamesZebin::zeInfo); auto brokenZeInfo = NEO::ConstStringRef("#no data\n"); @@ -2839,13 +2864,15 @@ TEST(DecodeSingleDeviceBinaryZebin, GivenEmptyInZeInfoThenEmitsWarning) { singleBinary.deviceBinary = zebin.storage; std::string decodeErrors; std::string decodeWarnings; - auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings); + auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings, gfxCoreHelper); EXPECT_EQ(NEO::DecodeError::Success, error); EXPECT_STREQ("NEO::Yaml : Text has no data\nDeviceBinaryFormat::Zebin : Empty kernels metadata section (.ze_info)\n", decodeWarnings.c_str()); EXPECT_TRUE(decodeErrors.empty()) << decodeErrors; } TEST(DecodeSingleDeviceBinaryZebin, GivenUnknownEntryInZeInfoGlobalScopeThenEmitsWarning) { + NEO::MockExecutionEnvironment mockExecutionEnvironment{}; + auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); ZebinTestData::ValidEmptyProgram zebin; zebin.removeSection(NEO::Elf::SHT_ZEBIN::SHT_ZEBIN_ZEINFO, NEO::Elf::SectionsNamesZebin::zeInfo); auto brokenZeInfo = std::string("some_entry : a\nkernels : \n - name : valid_empty_kernel\n execution_env : \n simd_size : 32\n grf_count : 128\nversion:\'") + versionToString(zeInfoDecoderVersion) + "\'\n"; @@ -2856,13 +2883,15 @@ TEST(DecodeSingleDeviceBinaryZebin, GivenUnknownEntryInZeInfoGlobalScopeThenEmit singleBinary.deviceBinary = zebin.storage; std::string decodeErrors; std::string decodeWarnings; - auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings); + auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings, gfxCoreHelper); EXPECT_EQ(NEO::DecodeError::Success, error); EXPECT_STREQ("DeviceBinaryFormat::Zebin::.ze_info : Unknown entry \"some_entry\" in global scope of .ze_info\n", decodeWarnings.c_str()); EXPECT_TRUE(decodeErrors.empty()) << decodeErrors; } TEST(DecodeSingleDeviceBinaryZebin, WhenZeInfoDoesNotContainKernelsSectionThenEmitsWarning) { + NEO::MockExecutionEnvironment mockExecutionEnvironment{}; + auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); ZebinTestData::ValidEmptyProgram zebin; zebin.removeSection(NEO::Elf::SHT_ZEBIN::SHT_ZEBIN_ZEINFO, NEO::Elf::SectionsNamesZebin::zeInfo); auto brokenZeInfo = std::string("version:\'") + versionToString(zeInfoDecoderVersion) + "\'\na:b\n"; @@ -2873,13 +2902,15 @@ TEST(DecodeSingleDeviceBinaryZebin, WhenZeInfoDoesNotContainKernelsSectionThenEm singleBinary.deviceBinary = zebin.storage; std::string decodeErrors; std::string decodeWarnings; - auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings); + auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings, gfxCoreHelper); EXPECT_EQ(NEO::DecodeError::Success, error); EXPECT_STREQ("DeviceBinaryFormat::Zebin::.ze_info : Unknown entry \"a\" in global scope of .ze_info\nDeviceBinaryFormat::Zebin::.ze_info : Expected one kernels entry in global scope of .ze_info, got : 0\n", decodeWarnings.c_str()); EXPECT_TRUE(decodeErrors.empty()) << decodeErrors; } TEST(DecodeSingleDeviceBinaryZebin, WhenZeInfoContainsMultipleKernelSectionsThenFails) { + NEO::MockExecutionEnvironment mockExecutionEnvironment{}; + auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); ZebinTestData::ValidEmptyProgram zebin; zebin.removeSection(NEO::Elf::SHT_ZEBIN::SHT_ZEBIN_ZEINFO, NEO::Elf::SectionsNamesZebin::zeInfo); auto brokenZeInfo = std::string("version:\'") + versionToString(zeInfoDecoderVersion) + "\'\nkernels : \n - name : valid_empty_kernel\n execution_env : \n simd_size : 32\n grf_count : 128\n" + "\nkernels : \n - name : valid_empty_kernel\n execution_env : \n simd_size : 32\n grf_count : 128\n...\n"; @@ -2890,13 +2921,15 @@ TEST(DecodeSingleDeviceBinaryZebin, WhenZeInfoContainsMultipleKernelSectionsThen singleBinary.deviceBinary = zebin.storage; std::string decodeErrors; std::string decodeWarnings; - auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings); + auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings, gfxCoreHelper); EXPECT_EQ(NEO::DecodeError::InvalidBinary, error); EXPECT_STREQ("DeviceBinaryFormat::Zebin::.ze_info : Expected at most one kernels entry in global scope of .ze_info, got : 2\n", decodeErrors.c_str()); EXPECT_TRUE(decodeWarnings.empty()) << decodeWarnings; } TEST(DecodeSingleDeviceBinaryZebin, WhenZeInfoContainsMultipleVersionSectionsThenFails) { + NEO::MockExecutionEnvironment mockExecutionEnvironment{}; + auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); ZebinTestData::ValidEmptyProgram zebin; zebin.removeSection(NEO::Elf::SHT_ZEBIN::SHT_ZEBIN_ZEINFO, NEO::Elf::SectionsNamesZebin::zeInfo); auto brokenZeInfo = std::string("version:\'") + versionToString(zeInfoDecoderVersion) + "\'\nversion:\'5.4\'\nkernels:\n"; @@ -2907,13 +2940,15 @@ TEST(DecodeSingleDeviceBinaryZebin, WhenZeInfoContainsMultipleVersionSectionsThe singleBinary.deviceBinary = zebin.storage; std::string decodeErrors; std::string decodeWarnings; - auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings); + auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings, gfxCoreHelper); EXPECT_EQ(NEO::DecodeError::InvalidBinary, error); EXPECT_STREQ("DeviceBinaryFormat::Zebin::.ze_info : Expected at most one version entry in global scope of .ze_info, got : 2\n", decodeErrors.c_str()); EXPECT_TRUE(decodeWarnings.empty()) << decodeWarnings; } TEST(DecodeSingleDeviceBinaryZebin, WhenZeInfoDoesNotContainVersionSectionsThenEmitsWarnings) { + NEO::MockExecutionEnvironment mockExecutionEnvironment{}; + auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); ZebinTestData::ValidEmptyProgram zebin; zebin.removeSection(NEO::Elf::SHT_ZEBIN::SHT_ZEBIN_ZEINFO, NEO::Elf::SectionsNamesZebin::zeInfo); auto zeInfo = ConstStringRef("kernels:\n"); @@ -2928,13 +2963,15 @@ TEST(DecodeSingleDeviceBinaryZebin, WhenZeInfoDoesNotContainVersionSectionsThenE singleBinary.deviceBinary = zebin.storage; std::string decodeErrors; std::string decodeWarnings; - auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings); + auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings, gfxCoreHelper); EXPECT_EQ(NEO::DecodeError::Success, error); EXPECT_STREQ(expectedWarning.c_str(), decodeWarnings.c_str()); EXPECT_TRUE(decodeErrors.empty()) << decodeErrors; } TEST(DecodeSingleDeviceBinaryZebin, WhenZeInfoVersionIsInvalidThenFails) { + NEO::MockExecutionEnvironment mockExecutionEnvironment{}; + auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); ZebinTestData::ValidEmptyProgram zebin; zebin.removeSection(NEO::Elf::SHT_ZEBIN::SHT_ZEBIN_ZEINFO, NEO::Elf::SectionsNamesZebin::zeInfo); auto zeInfo = ConstStringRef("version:\'1a\'\nkernels:\n"); @@ -2945,13 +2982,15 @@ TEST(DecodeSingleDeviceBinaryZebin, WhenZeInfoVersionIsInvalidThenFails) { singleBinary.deviceBinary = zebin.storage; std::string decodeErrors; std::string decodeWarnings; - auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings); + auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings, gfxCoreHelper); EXPECT_EQ(NEO::DecodeError::InvalidBinary, error); EXPECT_STREQ("DeviceBinaryFormat::Zebin::.ze_info : Invalid version format - expected 'MAJOR.MINOR' string, got : 1a\n", decodeErrors.c_str()); EXPECT_TRUE(decodeWarnings.empty()) << decodeWarnings; } TEST(DecodeSingleDeviceBinaryZebin, WhenZeInfoMinorVersionIsNewerThenEmitsWarning) { + NEO::MockExecutionEnvironment mockExecutionEnvironment{}; + auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); ZebinTestData::ValidEmptyProgram zebin; zebin.removeSection(NEO::Elf::SHT_ZEBIN::SHT_ZEBIN_ZEINFO, NEO::Elf::SectionsNamesZebin::zeInfo); auto version = NEO::zeInfoDecoderVersion; @@ -2965,13 +3004,15 @@ TEST(DecodeSingleDeviceBinaryZebin, WhenZeInfoMinorVersionIsNewerThenEmitsWarnin singleBinary.deviceBinary = zebin.storage; std::string decodeErrors; std::string decodeWarnings; - auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings); + auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings, gfxCoreHelper); EXPECT_EQ(NEO::DecodeError::Success, error); EXPECT_STREQ(expectedWarning.c_str(), decodeWarnings.c_str()); EXPECT_TRUE(decodeErrors.empty()) << decodeErrors; } TEST(DecodeSingleDeviceBinaryZebin, WhenZeInfoMajorVersionIsMismatchedThenFails) { + NEO::MockExecutionEnvironment mockExecutionEnvironment{}; + auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); { ZebinTestData::ValidEmptyProgram zebin; zebin.removeSection(NEO::Elf::SHT_ZEBIN::SHT_ZEBIN_ZEINFO, NEO::Elf::SectionsNamesZebin::zeInfo); @@ -2985,7 +3026,7 @@ TEST(DecodeSingleDeviceBinaryZebin, WhenZeInfoMajorVersionIsMismatchedThenFails) singleBinary.deviceBinary = zebin.storage; std::string decodeErrors; std::string decodeWarnings; - auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings); + auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings, gfxCoreHelper); EXPECT_EQ(NEO::DecodeError::UnhandledBinary, error); EXPECT_STREQ("DeviceBinaryFormat::Zebin::.ze_info : Unhandled major version : 2, decoder is at : 1\n", decodeErrors.c_str()); EXPECT_TRUE(decodeWarnings.empty()) << decodeWarnings; @@ -3004,7 +3045,7 @@ TEST(DecodeSingleDeviceBinaryZebin, WhenZeInfoMajorVersionIsMismatchedThenFails) singleBinary.deviceBinary = zebin.storage; std::string decodeErrors; std::string decodeWarnings; - auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings); + auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings, gfxCoreHelper); EXPECT_EQ(NEO::DecodeError::UnhandledBinary, error); EXPECT_STREQ("DeviceBinaryFormat::Zebin::.ze_info : Unhandled major version : 0, decoder is at : 1\n", decodeErrors.c_str()); EXPECT_TRUE(decodeWarnings.empty()) << decodeWarnings; @@ -3012,6 +3053,8 @@ TEST(DecodeSingleDeviceBinaryZebin, WhenZeInfoMajorVersionIsMismatchedThenFails) } TEST(DecodeSingleDeviceBinaryZebin, WhenDecodeZeInfoFailsThenDecodingFails) { + NEO::MockExecutionEnvironment mockExecutionEnvironment{}; + auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); std::string brokenZeInfo = "version : \'" + versionToString(zeInfoDecoderVersion) + R"===(' kernels: - @@ -3026,13 +3069,15 @@ kernels: singleBinary.deviceBinary = zebin.storage; std::string decodeErrors; std::string decodeWarnings; - auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings); + auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings, gfxCoreHelper); EXPECT_EQ(NEO::DecodeError::InvalidBinary, error); EXPECT_STREQ("DeviceBinaryFormat::Zebin : Expected exactly 1 of name section, got : 0\nDeviceBinaryFormat::Zebin : Expected exactly 1 of execution_env section, got : 0\n", decodeErrors.c_str()); EXPECT_TRUE(decodeWarnings.empty()) << decodeWarnings; } TEST(DecodeSingleDeviceBinaryZebin, GivenValidZeInfoThenPopulatesKernelDescriptorProperly) { + NEO::MockExecutionEnvironment mockExecutionEnvironment{}; + auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); std::string validZeInfo = std::string("version :\'") + versionToString(zeInfoDecoderVersion) + R"===(' kernels: - name : some_kernel @@ -3053,7 +3098,7 @@ kernels: singleBinary.deviceBinary = zebin.storage; std::string decodeErrors; std::string decodeWarnings; - auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings); + auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings, gfxCoreHelper); EXPECT_EQ(NEO::DecodeError::Success, error); EXPECT_TRUE(decodeErrors.empty()) << decodeErrors; EXPECT_TRUE(decodeWarnings.empty()) << decodeWarnings; @@ -3068,6 +3113,9 @@ kernels: } TEST(DecodeSingleDeviceBinaryZebin, GivenValidZeInfoAndExternalFunctionsMetadataThenPopulatesExternalFunctionMetadataProperly) { + NEO::MockExecutionEnvironment mockExecutionEnvironment{}; + auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); + std::string validZeInfo = std::string("version :\'") + versionToString(zeInfoDecoderVersion) + R"===(' kernels: - name : some_kernel @@ -3091,7 +3139,7 @@ functions: singleBinary.deviceBinary = zebin.storage; std::string decodeErrors; std::string decodeWarnings; - auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings); + auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings, gfxCoreHelper); EXPECT_EQ(NEO::DecodeError::Success, error); EXPECT_TRUE(decodeErrors.empty()) << decodeErrors; EXPECT_TRUE(decodeWarnings.empty()) << decodeWarnings; @@ -3105,6 +3153,8 @@ functions: } TEST(DecodeSingleDeviceBinaryZebin, GivenValidZeInfoAndInvalidExternalFunctionsMetadataThenFail) { + NEO::MockExecutionEnvironment mockExecutionEnvironment{}; + auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); std::string validZeInfo = std::string("version :\'") + versionToString(zeInfoDecoderVersion) + R"===(' kernels: - name : some_kernel @@ -3127,7 +3177,7 @@ functions: singleBinary.deviceBinary = zebin.storage; std::string decodeErrors; std::string decodeWarnings; - auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings); + auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings, gfxCoreHelper); EXPECT_EQ(NEO::DecodeError::InvalidBinary, error); const std::string expectedError = "DeviceBinaryFormat::Zebin::.ze_info : could not read grf_count from : [abc] in context of : external functions\nDeviceBinaryFormat::Zebin::.ze_info : could not read simd_size from : [defgas] in context of : external functions\n"; EXPECT_STREQ(expectedError.c_str(), decodeErrors.c_str()); @@ -3135,6 +3185,8 @@ functions: } TEST(DecodeSingleDeviceBinaryZebin, GivenZeInfoWithTwoExternalFunctionsEntriesThenFail) { + NEO::MockExecutionEnvironment mockExecutionEnvironment{}; + auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); std::string validZeInfo = std::string("version :\'") + versionToString(zeInfoDecoderVersion) + R"===(' kernels: - name : some_kernel @@ -3162,7 +3214,7 @@ functions: singleBinary.deviceBinary = zebin.storage; std::string decodeErrors; std::string decodeWarnings; - auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings); + auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings, gfxCoreHelper); EXPECT_EQ(NEO::DecodeError::InvalidBinary, error); const std::string expectedError = "DeviceBinaryFormat::Zebin::.ze_info : Expected at most one functions entry in global scope of .ze_info, got : 2\n"; EXPECT_STREQ(expectedError.c_str(), decodeErrors.c_str()); @@ -3170,6 +3222,8 @@ functions: } TEST(DecodeSingleDeviceBinaryZebin, givenZeInfoWithKernelsMiscInfoSectionWhenDecodingBinaryThenDoNotParseThisSection) { + NEO::MockExecutionEnvironment mockExecutionEnvironment{}; + auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); std::string zeInfo = std::string("version :\'") + versionToString(zeInfoDecoderVersion) + R"===(' kernels: - name: kernel1 @@ -3199,7 +3253,7 @@ kernels_misc_info: singleBinary.deviceBinary = {zebin.storage.data(), zebin.storage.size()}; std::string decodeErrors; std::string decodeWarnings; - auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings); + auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings, gfxCoreHelper); EXPECT_EQ(NEO::DecodeError::Success, error); EXPECT_TRUE(decodeWarnings.empty()); EXPECT_TRUE(decodeErrors.empty()); @@ -6662,6 +6716,9 @@ TEST(ValidateTargetDeviceTests, givenSteppingBiggerThanMaxHwRevisionWhenValidati } TEST(PopulateGlobalDeviceHostNameMapping, givenValidZebinWithGlobalHostAccessTableSectionThenPopulateHostDeviceNameMapCorrectly) { + NEO::MockExecutionEnvironment mockExecutionEnvironment{}; + auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); + NEO::ConstStringRef zeinfo = R"===( kernels: - name : some_kernel @@ -6684,7 +6741,7 @@ TEST(PopulateGlobalDeviceHostNameMapping, givenValidZebinWithGlobalHostAccessTab singleBinary.deviceBinary = zebin.storage; std::string decodeErrors; std::string decodeWarnings; - auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings); + auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings, gfxCoreHelper); EXPECT_EQ(NEO::DecodeError::Success, error); EXPECT_TRUE(decodeErrors.empty()) << decodeErrors; @@ -6694,6 +6751,9 @@ TEST(PopulateGlobalDeviceHostNameMapping, givenValidZebinWithGlobalHostAccessTab } TEST(PopulateGlobalDeviceHostNameMapping, givenZebinWithGlobalHostAccessTableSectionAndInvalidValuesThenReturnInvalidBinaryError) { + NEO::MockExecutionEnvironment mockExecutionEnvironment{}; + auto &gfxCoreHelper = mockExecutionEnvironment.rootDeviceEnvironments[0]->getHelper(); + std::vector invalidZeInfos{R"===( kernels: - name : some_kernel @@ -6723,7 +6783,7 @@ TEST(PopulateGlobalDeviceHostNameMapping, givenZebinWithGlobalHostAccessTableSec singleBinary.deviceBinary = zebin.storage; std::string decodeErrors; std::string decodeWarnings; - auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings); + auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings, gfxCoreHelper); EXPECT_EQ(NEO::DecodeError::InvalidBinary, error); } }