From ee0d183cf9ca54956a6b4939bc389b427c51a6b8 Mon Sep 17 00:00:00 2001 From: Krystian Chmielewski Date: Mon, 11 Apr 2022 14:34:06 +0000 Subject: [PATCH] Handle legacy hasBarriers properly Previous change regarding NEO-6785 added encoding of number of barriers to specific value representation depending on hardware that we program for. In patch token format encoding of number of barriers is sent via hasBarriers field in a token. In zebin true number of barriers is sent via barrier_count field in zeInfo. To remove this discrepancy, translate encoded number of barriers into true number of barriers in legacy format. Resolves: NEO-6785 Signed-off-by: Krystian Chmielewski --- opencl/test/unit_test/helpers/hw_helper_tests.cpp | 6 ++++++ .../xe_hpc_core/hw_helper_tests_xe_hpc_core.cpp | 13 +++++++++++++ .../device_binary_format_patchtokens.cpp | 12 +++++++++++- shared/source/helpers/hw_helper.h | 3 +++ shared/source/helpers/hw_helper_base.inl | 5 +++++ .../source/xe_hpc_core/hw_helper_xe_hpc_core.cpp | 15 +++++++++++++++ .../xe_hpg_core/command_encoder_xe_hpg_core.cpp | 2 +- .../device_binary_format_patchtokens_tests.cpp | 3 ++- .../device_binary_formats_tests.cpp | 3 ++- 9 files changed, 58 insertions(+), 4 deletions(-) diff --git a/opencl/test/unit_test/helpers/hw_helper_tests.cpp b/opencl/test/unit_test/helpers/hw_helper_tests.cpp index 5f467f6bf1..5c5e8a1c91 100644 --- a/opencl/test/unit_test/helpers/hw_helper_tests.cpp +++ b/opencl/test/unit_test/helpers/hw_helper_tests.cpp @@ -950,6 +950,12 @@ HWTEST_F(HwHelperTest, WhenIsBankOverrideRequiredIsCalledThenFalseIsReturned) { EXPECT_FALSE(hwHelper.isBankOverrideRequired(hardwareInfo)); } +HWCMDTEST_F(IGFX_GEN8_CORE, HwHelperTest, GivenBarrierEncodingWhenCallingGetBarriersCountFromHasBarrierThenNumberOfBarriersIsReturned) { + auto &hwHelper = HwHelper::get(hardwareInfo.platform.eRenderCoreFamily); + EXPECT_EQ(0u, hwHelper.getBarriersCountFromHasBarriers(0u)); + EXPECT_EQ(1u, hwHelper.getBarriersCountFromHasBarriers(1u)); +} + HWCMDTEST_F(IGFX_GEN8_CORE, HwHelperTest, GivenVariousValuesWhenCallingCalculateAvailableThreadCountThenCorrectValueIsReturned) { auto &hwHelper = HwHelper::get(hardwareInfo.platform.eRenderCoreFamily); auto result = hwHelper.calculateAvailableThreadCount( diff --git a/opencl/test/unit_test/xe_hpc_core/hw_helper_tests_xe_hpc_core.cpp b/opencl/test/unit_test/xe_hpc_core/hw_helper_tests_xe_hpc_core.cpp index 71b29daf73..a6d77cea4a 100644 --- a/opencl/test/unit_test/xe_hpc_core/hw_helper_tests_xe_hpc_core.cpp +++ b/opencl/test/unit_test/xe_hpc_core/hw_helper_tests_xe_hpc_core.cpp @@ -154,6 +154,19 @@ XE_HPC_CORETEST_F(HwHelperTestsXeHpcCore, whenQueryingMaxNumSamplersThenReturnZe EXPECT_EQ(0u, helper.getMaxNumSamplers()); } +XE_HPC_CORETEST_F(HwHelperTestsXeHpcCore, GivenBarrierEncodingWhenCallingGetBarriersCountFromHasBarrierThenNumberOfBarriersIsReturned) { + auto &hwHelper = HwHelper::get(hardwareInfo.platform.eRenderCoreFamily); + + EXPECT_EQ(0u, hwHelper.getBarriersCountFromHasBarriers(0u)); + EXPECT_EQ(1u, hwHelper.getBarriersCountFromHasBarriers(1u)); + EXPECT_EQ(2u, hwHelper.getBarriersCountFromHasBarriers(2u)); + EXPECT_EQ(4u, hwHelper.getBarriersCountFromHasBarriers(3u)); + EXPECT_EQ(8u, hwHelper.getBarriersCountFromHasBarriers(4u)); + EXPECT_EQ(16u, hwHelper.getBarriersCountFromHasBarriers(5u)); + EXPECT_EQ(24u, hwHelper.getBarriersCountFromHasBarriers(6u)); + EXPECT_EQ(32u, hwHelper.getBarriersCountFromHasBarriers(7u)); +} + XE_HPC_CORETEST_F(HwHelperTestsXeHpcCore, givenRevisionEnumAndPlatformFamilyTypeThenProperValueForIsWorkaroundRequiredIsReturned) { uint32_t steppings[] = { REVISION_A0, 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 81a96322b8..d5d40dec11 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-2021 Intel Corporation + * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -10,6 +10,8 @@ #include "shared/source/device_binary_format/patchtokens_dumper.h" #include "shared/source/device_binary_format/patchtokens_validator.h" #include "shared/source/helpers/debug_helpers.h" +#include "shared/source/helpers/hw_helper.h" +#include "shared/source/program/kernel_info.h" #include "shared/source/program/program_info_from_patchtokens.h" #include "shared/source/utilities/logger.h" @@ -57,6 +59,14 @@ 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 &hwHelper = NEO::HwHelper::get(src.targetDevice.coreFamily); + for (auto &ki : dst.kernelInfos) { + auto &kd = ki->kernelDescriptor; + kd.kernelAttributes.barrierCount = hwHelper.getBarriersCountFromHasBarriers(kd.kernelAttributes.barrierCount); + } + return DecodeError::Success; } diff --git a/shared/source/helpers/hw_helper.h b/shared/source/helpers/hw_helper.h index 92401f8e62..7bbc675b83 100644 --- a/shared/source/helpers/hw_helper.h +++ b/shared/source/helpers/hw_helper.h @@ -87,6 +87,7 @@ class HwHelper { virtual uint32_t getMetricsLibraryGenId() const = 0; virtual uint32_t getMocsIndex(const GmmHelper &gmmHelper, bool l3enabled, bool l1enabled) const = 0; virtual bool tilingAllowed(bool isSharedContext, bool isImage1d, bool forceLinearStorage) = 0; + virtual uint8_t getBarriersCountFromHasBarriers(uint8_t hasBarriers) const = 0; virtual uint32_t calculateAvailableThreadCount(PRODUCT_FAMILY family, uint32_t grfCount, uint32_t euCount, uint32_t threadsPerEu) = 0; virtual uint32_t alignSlmSize(uint32_t slmSize) = 0; @@ -286,6 +287,8 @@ class HwHelperHw : public HwHelper { bool tilingAllowed(bool isSharedContext, bool isImage1d, bool forceLinearStorage) override; + uint8_t getBarriersCountFromHasBarriers(uint8_t hasBarriers) const override; + uint32_t calculateAvailableThreadCount(PRODUCT_FAMILY family, uint32_t grfCount, uint32_t euCount, uint32_t threadsPerEu) override; uint32_t alignSlmSize(uint32_t slmSize) override; diff --git a/shared/source/helpers/hw_helper_base.inl b/shared/source/helpers/hw_helper_base.inl index 088f52b36a..a8044143ac 100644 --- a/shared/source/helpers/hw_helper_base.inl +++ b/shared/source/helpers/hw_helper_base.inl @@ -446,6 +446,11 @@ uint32_t HwHelperHw::computeSlmValues(const HardwareInfo &hwInfo, uin return value * !!slmSize; } +template +uint8_t HwHelperHw::getBarriersCountFromHasBarriers(uint8_t hasBarriers) const { + return hasBarriers; +} + template inline bool HwHelperHw::isOffsetToSkipSetFFIDGPWARequired(const HardwareInfo &hwInfo) const { return false; diff --git a/shared/source/xe_hpc_core/hw_helper_xe_hpc_core.cpp b/shared/source/xe_hpc_core/hw_helper_xe_hpc_core.cpp index d243e18619..c807ed7455 100644 --- a/shared/source/xe_hpc_core/hw_helper_xe_hpc_core.cpp +++ b/shared/source/xe_hpc_core/hw_helper_xe_hpc_core.cpp @@ -23,6 +23,21 @@ namespace NEO { template <> const AuxTranslationMode HwHelperHw::defaultAuxTranslationMode = AuxTranslationMode::Blit; +template <> +uint8_t HwHelperHw::getBarriersCountFromHasBarriers(uint8_t hasBarriers) const { + static constexpr uint8_t possibleBarriersCounts[] = { + 0u, // 0 + 1u, // 1 + 2u, // 2 + 4u, // 3 + 8u, // 4 + 16u, // 5 + 24u, // 6 + 32u, // 7 + }; + return possibleBarriersCounts[hasBarriers]; +} + template <> bool HwHelperHw::isCooperativeEngineSupported(const HardwareInfo &hwInfo) const { return (HwInfoConfig::get(hwInfo.platform.eProductFamily)->getSteppingFromHwRevId(hwInfo) >= REVISION_B); diff --git a/shared/source/xe_hpg_core/command_encoder_xe_hpg_core.cpp b/shared/source/xe_hpg_core/command_encoder_xe_hpg_core.cpp index 125a1bfd6e..27ebc83b7e 100644 --- a/shared/source/xe_hpg_core/command_encoder_xe_hpg_core.cpp +++ b/shared/source/xe_hpg_core/command_encoder_xe_hpg_core.cpp @@ -104,7 +104,7 @@ void EncodeDispatchKernel::adjustInterfaceDescriptorData(INTERFACE_DESCR template <> void EncodeDispatchKernel::programBarrierEnable(INTERFACE_DESCRIPTOR_DATA &interfaceDescriptor, uint32_t value, const HardwareInfo &hwInfo) { using BARRIERS = INTERFACE_DESCRIPTOR_DATA::NUMBER_OF_BARRIERS; - static const LookupArray barrierLookupArray({{{0, BARRIERS::NUMBER_OF_BARRIERS_NONE}, + static const LookupArray barrierLookupArray({{{0, BARRIERS::NUMBER_OF_BARRIERS_NONE}, {1, BARRIERS::NUMBER_OF_BARRIERS_B1}}}); BARRIERS numBarriers = barrierLookupArray.lookUp(value); interfaceDescriptor.setNumberOfBarriers(numBarriers); 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 58f36c5869..dadac9b102 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-2021 Intel Corporation + * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -145,6 +145,7 @@ TEST(DecodeSingleDeviceBinaryPatchtokens, GivenValidBinaryThenOutputIsProperlyPo NEO::ProgramInfo programInfo; NEO::SingleDeviceBinary singleBinary; singleBinary.deviceBinary = programTokens.storage; + singleBinary.targetDevice.coreFamily = static_cast(programTokens.header->Device); std::string decodeErrors; std::string decodeWarnings; auto error = NEO::decodeSingleDeviceBinary(programInfo, singleBinary, decodeErrors, decodeWarnings); 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 4878b72447..cde313e036 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-2021 Intel Corporation + * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -255,6 +255,7 @@ TEST(DecodeSingleDeviceBinary, GivenPatchTokensFormatThenDecodingSucceeds) { std::string decodeWarnings; NEO::SingleDeviceBinary bin; bin.deviceBinary = patchtokensProgram.storage; + bin.targetDevice.coreFamily = static_cast(patchtokensProgram.header->Device); NEO::DecodeError status; NEO::DeviceBinaryFormat format; std::tie(status, format) = NEO::decodeSingleDeviceBinary(programInfo, bin, decodeErrors, decodeWarnings);