From ff80a02fcbf6974a37d52981a4f2784958218723 Mon Sep 17 00:00:00 2001 From: Bartosz Dunajski Date: Mon, 21 Oct 2024 08:42:46 +0000 Subject: [PATCH] refactor: parse extra zebin params Related-To: NEO-12591 Signed-off-by: Bartosz Dunajski --- shared/offline_compiler/source/CMakeLists.txt | 1 + shared/source/CMakeLists.txt | 2 ++ .../source/device_binary_format/CMakeLists.txt | 4 +++- .../device_binary_format/zebin/CMakeLists.txt | 14 ++++++++++++++ .../source/device_binary_format/zebin/zeinfo.h | 10 ++++++++++ .../zebin/zeinfo_decoder.cpp | 13 ++++++++++++- .../device_binary_format/zebin/zeinfo_decoder.h | 7 ++++++- .../device_binary_format/zebin/zeinfo_extra.cpp | 16 ++++++++++++++++ .../helpers/definitions/command_encoder_args.h | 8 +++++++- shared/source/kernel/kernel_descriptor.h | 4 ++++ .../device_binary_format/CMakeLists.txt | 2 ++ 11 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 shared/source/device_binary_format/zebin/CMakeLists.txt create mode 100644 shared/source/device_binary_format/zebin/zeinfo_extra.cpp diff --git a/shared/offline_compiler/source/CMakeLists.txt b/shared/offline_compiler/source/CMakeLists.txt index 7f4c57257f..e942f43dce 100644 --- a/shared/offline_compiler/source/CMakeLists.txt +++ b/shared/offline_compiler/source/CMakeLists.txt @@ -50,6 +50,7 @@ set(CLOC_LIB_SRCS_LIB ${NEO_SHARED_DIRECTORY}/device_binary_format/zebin/zebin_decoder.h ${NEO_SHARED_DIRECTORY}/device_binary_format/zebin/zeinfo_decoder.cpp ${NEO_SHARED_DIRECTORY}/device_binary_format/zebin/zeinfo_decoder.h + ${NEO_SHARED_DIRECTORY}/device_binary_format/zebin/${BRANCH_DIR_SUFFIX}zeinfo_extra.cpp ${NEO_SHARED_DIRECTORY}/dll/devices${BRANCH_DIR_SUFFIX}devices.inl ${NEO_SHARED_DIRECTORY}/dll/devices/devices_base.inl ${NEO_SHARED_DIRECTORY}/dll/devices${BRANCH_DIR_SUFFIX}/product_config.inl diff --git a/shared/source/CMakeLists.txt b/shared/source/CMakeLists.txt index e30ee6439b..3ba53df68d 100644 --- a/shared/source/CMakeLists.txt +++ b/shared/source/CMakeLists.txt @@ -135,10 +135,12 @@ append_sources_from_properties(CORE_SOURCES NEO_CORE_SRCS_BUILT_IN_KERNELS NEO_CORE_TBX NEO_CORE_UTILITIES + NEO_CORE_ZEINFO_EXTRA NEO_DEVICE_BINARY_FORMAT NEO_UNIFIED_MEMORY NEO_CORE_RELEASE_HELPER NEO_GTPIN + ) if(WIN32) diff --git a/shared/source/device_binary_format/CMakeLists.txt b/shared/source/device_binary_format/CMakeLists.txt index 0ecf28ea8e..f23787cd47 100644 --- a/shared/source/device_binary_format/CMakeLists.txt +++ b/shared/source/device_binary_format/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (C) 2020-2023 Intel Corporation +# Copyright (C) 2020-2024 Intel Corporation # # SPDX-License-Identifier: MIT # @@ -42,3 +42,5 @@ set(NEO_DEVICE_BINARY_FORMAT ${CMAKE_CURRENT_SOURCE_DIR}/zebin/zeinfo_enum_lookup.h ) set_property(GLOBAL PROPERTY NEO_DEVICE_BINARY_FORMAT ${NEO_DEVICE_BINARY_FORMAT}) + +add_subdirectories() diff --git a/shared/source/device_binary_format/zebin/CMakeLists.txt b/shared/source/device_binary_format/zebin/CMakeLists.txt new file mode 100644 index 0000000000..f95b6ea480 --- /dev/null +++ b/shared/source/device_binary_format/zebin/CMakeLists.txt @@ -0,0 +1,14 @@ +# +# Copyright (C) 2024 Intel Corporation +# +# SPDX-License-Identifier: MIT +# + +set(NEO_CORE_ZEINFO_EXTRA + ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/${BRANCH_DIR_SUFFIX}zeinfo_extra.cpp +) + +set_property(GLOBAL APPEND PROPERTY NEO_CORE_ZEINFO_EXTRA ${NEO_CORE_ZEINFO_EXTRA}) + +add_subdirectories() diff --git a/shared/source/device_binary_format/zebin/zeinfo.h b/shared/source/device_binary_format/zebin/zeinfo.h index 997fb64eb7..1ec0fa717a 100644 --- a/shared/source/device_binary_format/zebin/zeinfo.h +++ b/shared/source/device_binary_format/zebin/zeinfo.h @@ -7,6 +7,7 @@ #pragma once +#include "shared/source/device_binary_format/yaml/yaml_parser.h" #include "shared/source/utilities/const_stringref.h" #include @@ -349,6 +350,9 @@ using IndirectStatelessCountT = int32_t; using HasSampleT = bool; using PrivateSizeT = int32_t; using SpillSizeT = int32_t; +using AdditionalSizeT = int32_t; +using WalkOrderT = int32_t; +using PartitionDimT = int32_t; namespace Defaults { inline constexpr BarrierCountT barrierCount = 0; @@ -380,6 +384,9 @@ inline constexpr IndirectStatelessCountT indirectStatelessCount = 0; inline constexpr HasSampleT hasSample = false; inline constexpr PrivateSizeT privateSize = 0; inline constexpr SpillSizeT spillSize = 0; +inline constexpr AdditionalSizeT additionalSize = -1; +inline constexpr WalkOrderT walkOrder = -1; +inline constexpr PartitionDimT partitionDim = -1; } // namespace Defaults inline constexpr ConstStringRef required[] = { @@ -415,6 +422,9 @@ struct ExecutionEnvBaseT { HasSampleT hasSample = Defaults::hasSample; PrivateSizeT privateSize = Defaults::privateSize; SpillSizeT spillSize = Defaults::spillSize; + AdditionalSizeT additionalSize = Defaults::additionalSize; + WalkOrderT walkOrder = Defaults::walkOrder; + PartitionDimT partitionDim = Defaults::partitionDim; }; struct ExperimentalPropertiesBaseT { diff --git a/shared/source/device_binary_format/zebin/zeinfo_decoder.cpp b/shared/source/device_binary_format/zebin/zeinfo_decoder.cpp index be4de94ada..ea3549515c 100644 --- a/shared/source/device_binary_format/zebin/zeinfo_decoder.cpp +++ b/shared/source/device_binary_format/zebin/zeinfo_decoder.cpp @@ -674,7 +674,7 @@ DecodeError readZeInfoExecutionEnvironment(const Yaml::YamlParser &parser, const } else if (Tags::Kernel::ExecutionEnv::spillSize == key) { validExecEnv &= readZeInfoValueChecked(parser, execEnvMetadataNd, outExecEnv.spillSize, context, outErrReason); } else { - encounterUnknownZeInfoAttribute("\"" + key.str() + "\" in context of " + context.str(), outErrReason, outWarning, err); + readZeInfoValueCheckedExtra(parser, execEnvMetadataNd, outExecEnv, context, key, outErrReason, outWarning, validExecEnv, err); } } @@ -717,6 +717,17 @@ void populateKernelExecutionEnvironment(KernelDescriptor &dst, const KernelExecu dst.kernelAttributes.workgroupWalkOrder[2] = static_cast(execEnv.workgroupWalkOrderDimensions[2]); dst.kernelAttributes.hasIndirectStatelessAccess = (execEnv.indirectStatelessCount > 0); dst.kernelAttributes.numThreadsRequired = static_cast(execEnv.euThreadCount); + + if (execEnv.additionalSize != Types::Kernel::ExecutionEnv::Defaults::additionalSize) { + dst.kernelAttributes.additionalSize = static_cast(execEnv.additionalSize); + } + if (execEnv.walkOrder != Types::Kernel::ExecutionEnv::Defaults::walkOrder) { + dst.kernelAttributes.walkOrder = EncodeParamsApiMappings::walkOrder[execEnv.walkOrder]; + } + if (execEnv.partitionDim != Types::Kernel::ExecutionEnv::Defaults::partitionDim) { + dst.kernelAttributes.partitionDim = EncodeParamsApiMappings::partitionDim[execEnv.partitionDim]; + } + if (isScratchMemoryUsageDefinedInExecutionEnvironment(srcZeInfoVersion)) { dst.kernelAttributes.privateScratchMemorySize = static_cast(execEnv.privateSize); dst.kernelAttributes.spillFillScratchMemorySize = static_cast(execEnv.spillSize); diff --git a/shared/source/device_binary_format/zebin/zeinfo_decoder.h b/shared/source/device_binary_format/zebin/zeinfo_decoder.h index a9beb02f76..95edba3b65 100644 --- a/shared/source/device_binary_format/zebin/zeinfo_decoder.h +++ b/shared/source/device_binary_format/zebin/zeinfo_decoder.h @@ -19,10 +19,16 @@ struct ProgramInfo; namespace Zebin::ZeInfo { inline constexpr NEO::Zebin::ZeInfo::Types::Version zeInfoDecoderVersion{1, 39}; +using KernelExecutionEnvBaseT = Types::Kernel::ExecutionEnv::ExecutionEnvBaseT; + +template +bool readZeInfoValueChecked(const NEO::Yaml::YamlParser &parser, const NEO::Yaml::Node &node, T &outValue, ConstStringRef context, std::string &outErrReason); template bool readEnumChecked(ConstStringRef enumString, T &outValue, ConstStringRef kernelName, std::string &outErrReason); template bool readZeInfoEnumChecked(const NEO::Yaml::YamlParser &parser, const NEO::Yaml::Node &node, T &outValue, ConstStringRef kernelName, std::string &outErrReason); +void readZeInfoValueCheckedExtra(const NEO::Yaml::YamlParser &parser, const NEO::Yaml::Node &execEnvMetadataNd, KernelExecutionEnvBaseT &kernelExecEnv, ConstStringRef context, + ConstStringRef key, std::string &outErrReason, std::string &outWarning, bool &validExecEnv, DecodeError &error); using UniqueNode = StackVec; struct ZeInfoSections { @@ -74,7 +80,6 @@ DecodeError decodeZeInfoFunctions(ProgramInfo &dst, Yaml::YamlParser &parser, co DecodeError decodeZeInfoKernels(ProgramInfo &dst, Yaml::YamlParser &parser, const ZeInfoSections &zeInfoSections, std::string &outErrReason, std::string &outWarning, const Types::Version &srcZeInfoVersion); DecodeError decodeZeInfoKernelEntry(KernelDescriptor &dst, Yaml::YamlParser &yamlParser, const Yaml::Node &kernelNd, uint32_t grfSize, uint32_t minScratchSpaceSize, std::string &outErrReason, std::string &outWarning, const Types::Version &srcZeInfoVersion); -using KernelExecutionEnvBaseT = Types::Kernel::ExecutionEnv::ExecutionEnvBaseT; DecodeError decodeZeInfoKernelExecutionEnvironment(KernelDescriptor &dst, Yaml::YamlParser &parser, const ZeInfoKernelSections &kernelSections, std::string &outErrReason, std::string &outWarning, const Types::Version &srcZeInfoVersion); DecodeError readZeInfoExecutionEnvironment(const Yaml::YamlParser &parser, const Yaml::Node &node, KernelExecutionEnvBaseT &outExecEnv, ConstStringRef context, std::string &outErrReason, std::string &outWarning); void populateKernelExecutionEnvironment(KernelDescriptor &dst, const KernelExecutionEnvBaseT &execEnv, const Types::Version &srcZeInfoVersion); diff --git a/shared/source/device_binary_format/zebin/zeinfo_extra.cpp b/shared/source/device_binary_format/zebin/zeinfo_extra.cpp new file mode 100644 index 0000000000..b1564c8da9 --- /dev/null +++ b/shared/source/device_binary_format/zebin/zeinfo_extra.cpp @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2024 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/device_binary_format/zebin/zeinfo_decoder.h" + +namespace NEO::Zebin::ZeInfo { +void readZeInfoValueCheckedExtra(const NEO::Yaml::YamlParser &parser, const NEO::Yaml::Node &execEnvMetadataNd, KernelExecutionEnvBaseT &kernelExecEnv, ConstStringRef context, + ConstStringRef key, std::string &outErrReason, std::string &outWarning, bool &validExecEnv, DecodeError &error) { + + encounterUnknownZeInfoAttribute("\"" + key.str() + "\" in context of " + context.str(), outErrReason, outWarning, error); +} +} // namespace NEO::Zebin::ZeInfo diff --git a/shared/source/helpers/definitions/command_encoder_args.h b/shared/source/helpers/definitions/command_encoder_args.h index bf5d80ff9e..59e04367d8 100644 --- a/shared/source/helpers/definitions/command_encoder_args.h +++ b/shared/source/helpers/definitions/command_encoder_args.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2023 Intel Corporation + * Copyright (C) 2021-2024 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -7,6 +7,7 @@ #pragma once +#include #include #include @@ -44,4 +45,9 @@ enum class RequiredDispatchWalkOrder : uint32_t { static constexpr uint32_t additionalKernelLaunchSizeParamNotSet = 0; +namespace EncodeParamsApiMappings { +static constexpr std::array partitionDim = {{RequiredPartitionDim::x, NEO::RequiredPartitionDim::y, NEO::RequiredPartitionDim::z}}; +static constexpr std::array walkOrder = {{NEO::RequiredDispatchWalkOrder::x, NEO::RequiredDispatchWalkOrder::y, NEO::RequiredDispatchWalkOrder::additional}}; +} // namespace EncodeParamsApiMappings + } // namespace NEO diff --git a/shared/source/kernel/kernel_descriptor.h b/shared/source/kernel/kernel_descriptor.h index c780b8331b..48241dfb24 100644 --- a/shared/source/kernel/kernel_descriptor.h +++ b/shared/source/kernel/kernel_descriptor.h @@ -9,6 +9,7 @@ #include "shared/source/command_stream/thread_arbitration_policy.h" #include "shared/source/device_binary_format/device_binary_formats.h" +#include "shared/source/helpers/definitions/command_encoder_args.h" #include "shared/source/kernel/debug_data.h" #include "shared/source/kernel/grf_config.h" #include "shared/source/kernel/kernel_arg_descriptor.h" @@ -56,6 +57,9 @@ struct KernelDescriptor { uint32_t numThreadsRequired = 0u; uint32_t spillFillScratchMemorySize = 0u; uint32_t privateScratchMemorySize = 0u; + uint32_t additionalSize = NEO::additionalKernelLaunchSizeParamNotSet; + NEO::RequiredDispatchWalkOrder walkOrder = NEO::RequiredDispatchWalkOrder::none; + NEO::RequiredPartitionDim partitionDim = NEO::RequiredPartitionDim::none; ThreadArbitrationPolicy threadArbitrationPolicy = NotPresent; uint16_t requiredWorkgroupSize[3] = {0U, 0U, 0U}; uint16_t crossThreadDataSize = 0U; diff --git a/shared/test/unit_test/device_binary_format/CMakeLists.txt b/shared/test/unit_test/device_binary_format/CMakeLists.txt index bc5b7770ba..7cbed51666 100644 --- a/shared/test/unit_test/device_binary_format/CMakeLists.txt +++ b/shared/test/unit_test/device_binary_format/CMakeLists.txt @@ -24,3 +24,5 @@ target_sources(neo_shared_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/zebin_debug_binary_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/zebin_decoder_tests.cpp ) + +add_subdirectories()