├── .gitignore ├── CMakeLists.txt ├── CONTRIBUTING.md ├── LICENSE.md ├── README.md ├── SECURITY.md ├── inc └── common │ └── instrumentation │ └── api │ └── metrics_library_api_1_0.h ├── instrumentation ├── metrics_library │ ├── .clang-format │ ├── codegen │ │ ├── ddi │ │ │ ├── inc │ │ │ │ ├── ml_ddi.h │ │ │ │ ├── ml_ddi_gen11.h │ │ │ │ ├── ml_ddi_gen9.h │ │ │ │ ├── ml_ddi_xe2_hpg.h │ │ │ │ ├── ml_ddi_xe3.h │ │ │ │ ├── ml_ddi_xe_hpc.h │ │ │ │ ├── ml_ddi_xe_hpg.h │ │ │ │ └── ml_ddi_xe_lp.h │ │ │ ├── ml_ddi_command_buffer.cpp │ │ │ ├── ml_ddi_configuration.cpp │ │ │ ├── ml_ddi_context.cpp │ │ │ ├── ml_ddi_marker.cpp │ │ │ ├── ml_ddi_override.cpp │ │ │ ├── ml_ddi_query.cpp │ │ │ └── ml_ddi_report.cpp │ │ ├── gpu │ │ │ ├── ml_gpu_commands_gen11.h │ │ │ ├── ml_gpu_commands_gen9.h │ │ │ ├── ml_gpu_commands_include.h │ │ │ ├── ml_gpu_commands_xe2_hpg.h │ │ │ ├── ml_gpu_commands_xe3.h │ │ │ ├── ml_gpu_commands_xe_hpc.h │ │ │ ├── ml_gpu_commands_xe_hpg.h │ │ │ └── ml_gpu_commands_xe_lp.h │ │ ├── library │ │ │ ├── inc │ │ │ │ ├── ml_configuration_api.h │ │ │ │ └── ml_configuration_gpu.h │ │ │ ├── ml_export.cpp │ │ │ └── ml_export.def │ │ └── traits │ │ │ ├── linux │ │ │ └── ml_debug_helper.h │ │ │ ├── ml_traits_gen11.h │ │ │ ├── ml_traits_gen9.h │ │ │ ├── ml_traits_include.h │ │ │ ├── ml_traits_xe2_hpg.h │ │ │ ├── ml_traits_xe3.h │ │ │ ├── ml_traits_xe_hpc.h │ │ │ ├── ml_traits_xe_hpg.h │ │ │ └── ml_traits_xe_lp.h │ ├── ddi │ │ ├── ml_ddi_command_buffer.hpp │ │ ├── ml_ddi_configuration.hpp │ │ ├── ml_ddi_context.hpp │ │ ├── ml_ddi_marker.hpp │ │ ├── ml_ddi_override.hpp │ │ ├── ml_ddi_query.hpp │ │ └── ml_ddi_report.hpp │ ├── library │ │ └── inc │ │ │ ├── linux │ │ │ ├── external │ │ │ │ └── drm │ │ │ │ │ ├── DrmSource.txt │ │ │ │ │ ├── drm.h │ │ │ │ │ ├── drm_mode.h │ │ │ │ │ ├── i915_drm.h │ │ │ │ │ ├── i915_drm_prelim.h │ │ │ │ │ ├── xe_drm.h │ │ │ │ │ └── xf86drm.h │ │ │ ├── ml_driver_store_os.h │ │ │ ├── ml_macros_os.h │ │ │ └── ml_os.h │ │ │ ├── ml_configuration_macros.h │ │ │ ├── ml_export.h │ │ │ ├── ml_library_configuration.h │ │ │ ├── ml_macros.h │ │ │ ├── ml_pch.h │ │ │ └── ml_validation.h │ └── traits │ │ ├── command_buffer │ │ ├── ml_gpu_command_buffer.h │ │ ├── ml_gpu_commands.h │ │ ├── ml_gpu_registers.h │ │ └── ml_gpu_registers_layouts.h │ │ ├── configuration │ │ ├── linux │ │ │ └── ml_configuration_hw_counters_oa.h │ │ ├── ml_configuration_hw_counters_user.h │ │ └── ml_configuration_layouts.h │ │ ├── constants │ │ ├── linux │ │ │ └── ml_constants_os.h │ │ └── ml_constants.h │ │ ├── context │ │ ├── ml_client_options.h │ │ ├── ml_context.h │ │ └── ml_state.h │ │ ├── device │ │ ├── linux │ │ │ └── ml_sub_device.h │ │ └── ml_sub_device_common.h │ │ ├── example │ │ ├── ml_example.h │ │ └── ml_example_gpu.h │ │ ├── function_log │ │ ├── ml_function_log.h │ │ └── ml_function_log_release.h │ │ ├── internal │ │ └── ml_internal_feature.h │ │ ├── kernel_interface │ │ └── linux │ │ │ ├── ml_drm_layouts.h │ │ │ ├── ml_io_control.h │ │ │ ├── ml_kernel_interface.h │ │ │ ├── ml_tbs_interface.h │ │ │ └── ml_tbs_stream.h │ │ ├── marker │ │ ├── linux │ │ │ └── ml_marker_stream_user_extended.h │ │ └── ml_marker_stream_user.h │ │ ├── oa_buffer │ │ ├── ml_oa_buffer_dummy.h │ │ ├── ml_oa_buffer_layouts.h │ │ └── ml_oa_buffer_mapped.h │ │ ├── object │ │ ├── ml_ddi_objects.h │ │ └── ml_object.h │ │ ├── override │ │ ├── linux │ │ │ ├── ml_override_layouts.h │ │ │ ├── ml_override_posh_query.h │ │ │ └── ml_override_user.h │ │ ├── ml_override_flush_caches.h │ │ └── ml_override_null_hardware.h │ │ ├── policy │ │ └── linux │ │ │ ├── ml_policy_oneapi.h │ │ │ └── ml_policy_opencl.h │ │ ├── query │ │ ├── ml_hw_counters_layouts.h │ │ ├── ml_query_hw_counters.h │ │ ├── ml_query_hw_counters_calculator.h │ │ └── ml_query_hw_counters_slot.h │ │ └── tools │ │ ├── linux │ │ └── ml_tools_os.h │ │ └── ml_tools.h └── utils │ ├── common │ ├── inc │ │ ├── iu_debug.h │ │ └── iu_std.h │ └── iu_debug.c │ └── linux │ ├── inc │ └── iu_os.h │ ├── iu_os.cpp │ └── iu_std.cpp ├── libigdml.pc.in └── ml_cmake_adapter.cmake /.gitignore: -------------------------------------------------------------------------------- 1 | # Build 2 | dump/* 3 | libigdml.pc 4 | 5 | # CMake 6 | CMakeFiles/* 7 | CMakeCache.txt 8 | cmake_install.cmake 9 | Makefile 10 | 11 | # Other 12 | .vs/* 13 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to the Metrics Library for MDAPI 2 | 3 | Contributions to the Metrics Library for MDAPI are welcomed and encouraged. Below you can find guidelines 4 | for contributing to the Metrics Library for MDAPI. 5 | 6 | ## How to Report an Issue or Feature Request 7 | 8 | Public GitHub issues are the preferred method for reporting issues and feature 9 | requests. 10 | 11 | ## How to Fix an Issue or Add a Feature 12 | 13 | If you have an idea how to improve the Metrics Library for MDAPI: 14 | 15 | 1. Please share your proposal via a GitHub issue. This lets others know what 16 | you're working on and gives others an opportunity to provide early feedback. 17 | 1. Implement, validate, and document your fix or feature. Be sure it doesn't 18 | break any existing functionality! 19 | 1. Submit a pull request with your changes. 20 | 21 | After submitting a pull request your contribution will be reviewed. Your pull 22 | request may be accepted as-is, or additional fixes or modifications may be 23 | required. 24 | 25 | ## 26 | ___(*) Other names and brands my be claimed as property of others.___ 27 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020-2024, Intel Corporation 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a 6 | copy of this software and associated documentation files (the "Software"), 7 | to deal in the Software without restriction, including without limitation 8 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 | and/or sell copies of the Software, and to permit persons to whom the 10 | Software is furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included 13 | in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 | IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Intel(R) Metrics Library for MDAPI 2 | 3 | ## Introduction 4 | 5 | This software is a user mode driver helper library that provides access to GPU performance counters. 6 | 7 | ## License 8 | 9 | Intel(R) Metrics Library for MDAPI is distributed under the MIT License. 10 | 11 | You may obtain a copy of the License at: 12 | https://opensource.org/licenses/MIT 13 | 14 | ## Supported Platforms 15 | 16 | - Intel(R) Processors with Gen12 graphics devices 17 | - Intel(R) Processors with Gen11 graphics devices 18 | - Intel(R) Processors with Gen9 graphics devices 19 | 20 | ## Supported Operating Systems 21 | 22 | Intel(R) Metrics Library for MDAPI is supported on Linux family operating systems with minimum kernel version 4.14. 23 | 24 | ## Build and Install 25 | Not a stand alone software component. Serves as a helper library for particular Intel drivers. 26 | There is no need to build the library as long as it is an integrated part of those Intel drivers. 27 | 28 | 1\. Download sources. 29 | 30 | 2\. Install libdrm-dev: 31 | 32 | ```shell 33 | sudo apt install libdrm-dev 34 | ``` 35 | 36 | 3\. Run CMake generation: 37 | 38 | ```shell 39 | cmake . 40 | ``` 41 | 42 | 4\. Build: 43 | 44 | ```shell 45 | make -j$(nproc) 46 | ``` 47 | 48 | 5\. Built library will be here (for 64-bit release Linux): 49 | 50 | ```shell 51 | (project_root)/dump/linux64/release/metrics_library/libigdml.so 52 | ``` 53 | 54 | 6\. To prepare an installation package: 55 | 56 | ```shell 57 | make package 58 | ``` 59 | 60 | 7\. Install: 61 | 62 | ```shell 63 | sudo dpkg -i intel-metrics-library*.deb 64 | ``` 65 | 66 | *Note: To clear CMake parameters remove CMakeCache.txt, then regenerate.* 67 | 68 | ## Support 69 | 70 | Please file a GitHub issue to report an issue or ask questions. 71 | 72 | ## How to Contribute 73 | 74 | Contributions to the Metrics Library for MDAPI are welcomed and encouraged. 75 | Please see [CONTRIBUTING](CONTRIBUTING.md) for details how to 76 | contribute to the project. 77 | 78 | ## 79 | ___(*) Other names and brands my be claimed as property of others.___ 80 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | Intel is committed to rapidly addressing security vulnerabilities affecting our 3 | customers and providing clear guidance on the solution, impact, severity and 4 | mitigation. 5 | 6 | ## Reporting a Vulnerability 7 | Please report any security vulnerabilities in this project [utilizing the 8 | guidelines 9 | here](https://www.intel.com/content/www/us/en/security-center/vulnerability-handling-guidelines.html). 10 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/.clang-format: -------------------------------------------------------------------------------- 1 | #=========================== begin_copyright_notice ============================ 2 | # 3 | # Copyright (C) 2020-2024 Intel Corporation 4 | # 5 | # SPDX-License-Identifier: MIT 6 | # 7 | #============================ end_copyright_notice ============================= 8 | 9 | # Clang-format settings. 10 | # '// clang-format off' is used for disabling auto-formatting in some places. 11 | # '// clang-format on' enables auto-formating after disabling it by above comment. 12 | # Clang-format cannot auto-format lambdas, directives, bit fields in structs properly. 13 | 14 | AccessModifierOffset: -4 15 | 16 | AlignAfterOpenBracket: AlwaysBreak 17 | AlignArrayOfStructures: Right 18 | AlignConsecutiveAssignments: 19 | Enabled: true 20 | AlignCompound: true 21 | PadOperators: true 22 | AlignConsecutiveBitFields: AcrossEmptyLinesAndComments 23 | AlignConsecutiveDeclarations: Consecutive 24 | AlignConsecutiveMacros: 25 | Enabled: true 26 | AcrossEmptyLines: true 27 | AcrossComments: true 28 | AlignEscapedNewlinesLeft: Right 29 | AlignOperands: DontAlign 30 | AlignTrailingComments: true 31 | 32 | AllowAllArgumentsOnNextLine: false 33 | AllowAllConstructorInitializersOnNextLine: false 34 | AllowAllParametersOfDeclarationOnNextLine: false 35 | AllowShortBlocksOnASingleLine: false 36 | AllowShortCaseLabelsOnASingleLine: false 37 | AllowShortEnumsOnASingleLine: false 38 | AllowShortFunctionsOnASingleLine: false 39 | AllowShortIfStatementsOnASingleLine: false 40 | AllowShortLambdasOnASingleLine: None 41 | AllowShortLoopsOnASingleLine: false 42 | 43 | AlwaysBreakAfterDefinitionReturnType: None 44 | AlwaysBreakAfterReturnType: None 45 | AlwaysBreakBeforeMultilineStrings: false 46 | AlwaysBreakTemplateDeclarations: Yes 47 | 48 | #AttributeMacros: [''] 49 | 50 | BinPackArguments: true 51 | BinPackParameters: false 52 | 53 | #BitFieldColonSpacing: Both 54 | 55 | BraceWrapping: 56 | AfterCaseLabel: true 57 | AfterClass: true 58 | AfterControlStatement: true 59 | AfterEnum: true 60 | AfterFunction: true 61 | AfterNamespace: true 62 | AfterStruct: true 63 | AfterUnion: true 64 | AfterExternBlock: true 65 | BeforeCatch: true 66 | BeforeElse: true 67 | BeforeLambdaBody: true 68 | BeforeWhile: true 69 | IndentBraces: false 70 | SplitEmptyFunction: true 71 | SplitEmptyRecord: true 72 | SplitEmptyNamespace: true 73 | 74 | BreakBeforeBinaryOperators: None 75 | BreakBeforeBraces: Custom 76 | #BreakBeforeConceptDeclarations: true 77 | BreakBeforeInheritanceComma: false 78 | BreakBeforeTernaryOperators: true 79 | BreakConstructorInitializers: BeforeComma 80 | BreakInheritanceList: BeforeComma 81 | BreakStringLiterals: false 82 | 83 | ColumnLimit: 0 84 | 85 | CompactNamespaces: false 86 | 87 | ConstructorInitializerAllOnOneLineOrOnePerLine: false 88 | ConstructorInitializerIndentWidth: 4 89 | 90 | ContinuationIndentWidth: 4 91 | 92 | Cpp11BracedListStyle: false 93 | 94 | DeriveLineEnding: false 95 | DerivePointerAlignment: false 96 | 97 | #EmptyLineAfterAccessModifier: Never 98 | #EmptyLineBeforeAccessModifier: LogicalBlock 99 | 100 | FixNamespaceComments: true 101 | 102 | #IndentAccessModifiers: false 103 | IndentCaseBlocks: false 104 | IndentCaseLabels: true 105 | IndentExternBlock: true 106 | IndentGotoLabels: true 107 | IndentPPDirectives: BeforeHash 108 | #IndentRequires: true 109 | IndentWidth: 4 110 | IndentWrappedFunctionNames: true 111 | 112 | #InsertTrailingCommas: None 113 | 114 | KeepEmptyLinesAtTheStartOfBlocks: false 115 | 116 | #LambdaBodyIndentation: Signature 117 | 118 | Language: Cpp 119 | 120 | MaxEmptyLinesToKeep: 1 121 | 122 | NamespaceIndentation: All 123 | 124 | #PPIndentWidth: -1 125 | 126 | PointerAlignment: Left 127 | 128 | #QualifierAlignment: Custom 129 | #QualifierOrder: ['volatile', 'inline', 'static', 'const', 'constexpr', 'type'] 130 | 131 | #ReferenceAlignment: Left 132 | 133 | ReflowComments: true 134 | 135 | #ShortNamespaceLines: 0 136 | 137 | SortIncludes: false 138 | SortUsingDeclarations: false 139 | 140 | SpaceAfterCStyleCast: true 141 | SpaceAfterLogicalNot: false 142 | SpaceAfterTemplateKeyword: true 143 | #SpaceAroundPointerQualifiers: Default 144 | SpaceBeforeAssignmentOperators: true 145 | SpaceBeforeCaseColon: false 146 | SpaceBeforeCpp11BracedList: false 147 | SpaceBeforeCtorInitializerColon: true 148 | SpaceBeforeInheritanceColon: true 149 | SpaceBeforeParens: Never 150 | SpaceBeforeRangeBasedForLoopColon: true 151 | SpaceBeforeSquareBrackets: false 152 | SpaceInEmptyBlock: false 153 | SpaceInEmptyParentheses: false 154 | 155 | SpacesBeforeTrailingComments: 1 156 | SpacesInAngles: false 157 | SpacesInCStyleCastParentheses: false 158 | SpacesInConditionalStatement: true 159 | SpacesInContainerLiterals: false 160 | SpacesInParentheses: true 161 | SpacesInSquareBrackets: false 162 | 163 | Standard: Latest 164 | 165 | TabWidth: 4 166 | 167 | UseCRLF: true 168 | UseTab: Never 169 | 170 | #WhitespaceSensitiveMacros: [''] 171 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/codegen/ddi/inc/ml_ddi.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_ddi.h 11 | 12 | @brief Auto-generated file. Prepares a function table that contains Metrics Library 13 | entry points for a given os / gen / api. 14 | 15 | DO NOT EDIT 16 | 17 | Script file: Tools/MetricsLibraryGenerator/generators/generate_umd.py 18 | Script function: generate_umd_tables 19 | Template: Tools/MetricsLibraryGenerator/templates/function_table_base.h 20 | */ 21 | 22 | #pragma once 23 | 24 | namespace ML 25 | { 26 | ////////////////////////////////////////////////////////////////////////// 27 | // @brief DDI function pointers. 28 | ////////////////////////////////////////////////////////////////////////// 29 | struct DdiFunctionTableBase 30 | { 31 | ContextCreateFunction_1_0 pfnContextCreate_1_0; 32 | ContextDeleteFunction_1_0 pfnContextDelete_1_0; 33 | 34 | ////////////////////////////////////////////////////////////////////////// 35 | /// @brief Initializes all function pointers with null functions. 36 | ////////////////////////////////////////////////////////////////////////// 37 | DdiFunctionTableBase() 38 | { 39 | pfnContextCreate_1_0 = nullptr; 40 | pfnContextDelete_1_0 = nullptr; 41 | } 42 | 43 | ////////////////////////////////////////////////////////////////////////// 44 | /// @brief Virtual GetInterface function. 45 | ////////////////////////////////////////////////////////////////////////// 46 | virtual void GetInterface( Interface_1_0& interface ) const = 0; 47 | }; 48 | 49 | const DdiFunctionTableBase* GetDdiFunctionTable( const ClientType_1_0& clientType ); 50 | const DdiFunctionTableBase* GetDdiFunctionTable( const ContextHandle_1_0& handle ); 51 | } // namespace ML 52 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/codegen/ddi/inc/ml_ddi_xe3.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_ddi_xe3.h 11 | 12 | @brief Auto-generated file. Prepares a function table that contains Metrics Library 13 | entry points for a given os / gen / api. 14 | 15 | DO NOT EDIT 16 | 17 | Script file: Tools/MetricsLibraryGenerator/generators/generate_umd.py 18 | Script function: generate_umd_tables 19 | Template: Tools/MetricsLibraryGenerator/templates/function_table.h 20 | */ 21 | 22 | #pragma once 23 | 24 | #if ML_ENABLE_XE3 25 | #include "ml_ddi.h" 26 | 27 | #if ML_ENABLE_OPENCL 28 | namespace ML::XE3::OpenCL 29 | { 30 | ////////////////////////////////////////////////////////////////////////// 31 | /// @brief Function signatures for XE3. 32 | ////////////////////////////////////////////////////////////////////////// 33 | StatusCode ML_STDCALL ContextCreate_1_0( ClientType_1_0, ContextCreateData_1_0*, ContextHandle_1_0* ); 34 | StatusCode ML_STDCALL ContextDelete_1_0( const ContextHandle_1_0 ); 35 | StatusCode ML_STDCALL GetParameter_1_0( const ParameterType, ValueType*, TypedValue_1_0* ); 36 | StatusCode ML_STDCALL CommandBufferGet_1_0( const CommandBufferData_1_0* ); 37 | StatusCode ML_STDCALL CommandBufferGetSize_1_0( const CommandBufferData_1_0*, CommandBufferSize_1_0* ); 38 | StatusCode ML_STDCALL QueryCreate_1_0( const QueryCreateData_1_0*, QueryHandle_1_0* ); 39 | StatusCode ML_STDCALL QueryDelete_1_0( const QueryHandle_1_0 ); 40 | StatusCode ML_STDCALL OverrideCreate_1_0( const OverrideCreateData_1_0*, OverrideHandle_1_0* ); 41 | StatusCode ML_STDCALL OverrideDelete_1_0( const OverrideHandle_1_0 ); 42 | StatusCode ML_STDCALL ConfigurationCreate_1_0( const ConfigurationCreateData_1_0*, ConfigurationHandle_1_0* ); 43 | StatusCode ML_STDCALL ConfigurationActivate_1_0( const ConfigurationHandle_1_0, const ConfigurationActivateData_1_0* ); 44 | StatusCode ML_STDCALL ConfigurationDeactivate_1_0( const ConfigurationHandle_1_0 ); 45 | StatusCode ML_STDCALL ConfigurationDelete_1_0( const ConfigurationHandle_1_0 ); 46 | StatusCode ML_STDCALL GetData_1_0( GetReportData_1_0* ); 47 | StatusCode ML_STDCALL MarkerCreate_1_0( const MarkerCreateData_1_0*, MarkerHandle_1_0* ); 48 | StatusCode ML_STDCALL MarkerDelete_1_0( const MarkerHandle_1_0 ); 49 | 50 | ////////////////////////////////////////////////////////////////////////// 51 | /// @brief DDI function pointers for XE3. 52 | ////////////////////////////////////////////////////////////////////////// 53 | template 54 | struct DdiFunctionTable : DdiFunctionTableBase 55 | { 56 | ////////////////////////////////////////////////////////////////////////// 57 | /// @brief Initializes all function pointers for XE3. 58 | ////////////////////////////////////////////////////////////////////////// 59 | DdiFunctionTable() 60 | { 61 | pfnContextCreate_1_0 = ContextCreate_1_0; 62 | pfnContextDelete_1_0 = ContextDelete_1_0; 63 | } 64 | 65 | void GetInterface( Interface_1_0& interface ) const 66 | { 67 | interface = {}; 68 | interface.GetParameter = GetParameter_1_0; 69 | interface.CommandBufferGet = CommandBufferGet_1_0; 70 | interface.CommandBufferGetSize = CommandBufferGetSize_1_0; 71 | interface.QueryCreate = QueryCreate_1_0; 72 | interface.QueryDelete = QueryDelete_1_0; 73 | interface.OverrideCreate = OverrideCreate_1_0; 74 | interface.OverrideDelete = OverrideDelete_1_0; 75 | interface.ConfigurationCreate = ConfigurationCreate_1_0; 76 | interface.ConfigurationActivate = ConfigurationActivate_1_0; 77 | interface.ConfigurationDeactivate = ConfigurationDeactivate_1_0; 78 | interface.ConfigurationDelete = ConfigurationDelete_1_0; 79 | interface.GetData = GetData_1_0; 80 | interface.MarkerCreate = MarkerCreate_1_0; 81 | interface.MarkerDelete = MarkerDelete_1_0; 82 | } 83 | 84 | ////////////////////////////////////////////////////////////////////////// 85 | /// @brief Returns an instance of DdiFunctionTable object. 86 | /// @return singleton DdiFunctionTable object. 87 | ////////////////////////////////////////////////////////////////////////// 88 | static const DdiFunctionTable& GetInstance() 89 | { 90 | // Instance of ddi function table must be static. 91 | static const DdiFunctionTable instance; 92 | return instance; 93 | } 94 | }; 95 | } // namespace ML::XE3::OpenCL 96 | #endif // ML_ENABLE_OPENCL 97 | 98 | #if ML_ENABLE_ONEAPI 99 | namespace ML::XE3::OneApi 100 | { 101 | ////////////////////////////////////////////////////////////////////////// 102 | /// @brief Function signatures for XE3. 103 | ////////////////////////////////////////////////////////////////////////// 104 | StatusCode ML_STDCALL ContextCreate_1_0( ClientType_1_0, ContextCreateData_1_0*, ContextHandle_1_0* ); 105 | StatusCode ML_STDCALL ContextDelete_1_0( const ContextHandle_1_0 ); 106 | StatusCode ML_STDCALL GetParameter_1_0( const ParameterType, ValueType*, TypedValue_1_0* ); 107 | StatusCode ML_STDCALL CommandBufferGet_1_0( const CommandBufferData_1_0* ); 108 | StatusCode ML_STDCALL CommandBufferGetSize_1_0( const CommandBufferData_1_0*, CommandBufferSize_1_0* ); 109 | StatusCode ML_STDCALL QueryCreate_1_0( const QueryCreateData_1_0*, QueryHandle_1_0* ); 110 | StatusCode ML_STDCALL QueryDelete_1_0( const QueryHandle_1_0 ); 111 | StatusCode ML_STDCALL OverrideCreate_1_0( const OverrideCreateData_1_0*, OverrideHandle_1_0* ); 112 | StatusCode ML_STDCALL OverrideDelete_1_0( const OverrideHandle_1_0 ); 113 | StatusCode ML_STDCALL ConfigurationCreate_1_0( const ConfigurationCreateData_1_0*, ConfigurationHandle_1_0* ); 114 | StatusCode ML_STDCALL ConfigurationActivate_1_0( const ConfigurationHandle_1_0, const ConfigurationActivateData_1_0* ); 115 | StatusCode ML_STDCALL ConfigurationDeactivate_1_0( const ConfigurationHandle_1_0 ); 116 | StatusCode ML_STDCALL ConfigurationDelete_1_0( const ConfigurationHandle_1_0 ); 117 | StatusCode ML_STDCALL GetData_1_0( GetReportData_1_0* ); 118 | StatusCode ML_STDCALL MarkerCreate_1_0( const MarkerCreateData_1_0*, MarkerHandle_1_0* ); 119 | StatusCode ML_STDCALL MarkerDelete_1_0( const MarkerHandle_1_0 ); 120 | 121 | ////////////////////////////////////////////////////////////////////////// 122 | /// @brief DDI function pointers for XE3. 123 | ////////////////////////////////////////////////////////////////////////// 124 | template 125 | struct DdiFunctionTable : DdiFunctionTableBase 126 | { 127 | ////////////////////////////////////////////////////////////////////////// 128 | /// @brief Initializes all function pointers for XE3. 129 | ////////////////////////////////////////////////////////////////////////// 130 | DdiFunctionTable() 131 | { 132 | pfnContextCreate_1_0 = ContextCreate_1_0; 133 | pfnContextDelete_1_0 = ContextDelete_1_0; 134 | } 135 | 136 | void GetInterface( Interface_1_0& interface ) const 137 | { 138 | interface = {}; 139 | interface.GetParameter = GetParameter_1_0; 140 | interface.CommandBufferGet = CommandBufferGet_1_0; 141 | interface.CommandBufferGetSize = CommandBufferGetSize_1_0; 142 | interface.QueryCreate = QueryCreate_1_0; 143 | interface.QueryDelete = QueryDelete_1_0; 144 | interface.OverrideCreate = OverrideCreate_1_0; 145 | interface.OverrideDelete = OverrideDelete_1_0; 146 | interface.ConfigurationCreate = ConfigurationCreate_1_0; 147 | interface.ConfigurationActivate = ConfigurationActivate_1_0; 148 | interface.ConfigurationDeactivate = ConfigurationDeactivate_1_0; 149 | interface.ConfigurationDelete = ConfigurationDelete_1_0; 150 | interface.GetData = GetData_1_0; 151 | interface.MarkerCreate = MarkerCreate_1_0; 152 | interface.MarkerDelete = MarkerDelete_1_0; 153 | } 154 | 155 | ////////////////////////////////////////////////////////////////////////// 156 | /// @brief Returns an instance of DdiFunctionTable object. 157 | /// @return singleton DdiFunctionTable object. 158 | ////////////////////////////////////////////////////////////////////////// 159 | static const DdiFunctionTable& GetInstance() 160 | { 161 | // Instance of ddi function table must be static. 162 | static const DdiFunctionTable instance; 163 | return instance; 164 | } 165 | }; 166 | } // namespace ML::XE3::OneApi 167 | #endif // ML_ENABLE_ONEAPI 168 | 169 | #endif // ML_ENABLE_XE3 170 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/codegen/gpu/ml_gpu_commands_include.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_gpu_commands_include.h 11 | 12 | @brief Auto-generated file. Enables gpu commands structures for a given platform. 13 | 14 | DO NOT EDIT 15 | 16 | Script file: Tools/MetricsLibraryGenerator/generators/generate_gfx.py 17 | Script function: generate_gfx 18 | Template: Tools/MetricsLibraryGenerator/templates/gfx.h 19 | */ 20 | 21 | #pragma once 22 | 23 | 24 | #if ML_ENABLE_GEN9 25 | // GEN9 IGFX Commands 26 | #define __CODEGEN_NAMESPACE_CLOSE }; } 27 | #define __CODEGEN_PLATFORM "GEN9" 28 | #define __CODEGEN_NAMESPACE_OPEN namespace ML::GEN9 { template struct GpuCommandsLayoutsTrait { 29 | #define __CODEGEN_FILE_DIRECTIVES_OPEN ML_STRUCTURE_PACK_BEGIN( 1 ) 30 | #define __CODEGEN_FILE_DIRECTIVES_CLOSE ML_STRUCTURE_PACK_END() 31 | #include "ml_gpu_commands_gen9.h" 32 | #undef __CODEGEN_NAMESPACE_OPEN 33 | #undef __CODEGEN_PLATFORM 34 | #endif // ML_ENABLE_GEN9 35 | 36 | #if ML_ENABLE_GEN11 37 | // GEN11 IGFX Commands 38 | #define __CODEGEN_NAMESPACE_CLOSE }; } 39 | #define __CODEGEN_PLATFORM "GEN11" 40 | #define __CODEGEN_NAMESPACE_OPEN namespace ML::GEN11 { template struct GpuCommandsLayoutsTrait { 41 | #define __CODEGEN_FILE_DIRECTIVES_OPEN ML_STRUCTURE_PACK_BEGIN( 1 ) 42 | #define __CODEGEN_FILE_DIRECTIVES_CLOSE ML_STRUCTURE_PACK_END() 43 | #include "ml_gpu_commands_gen11.h" 44 | #undef __CODEGEN_NAMESPACE_OPEN 45 | #undef __CODEGEN_PLATFORM 46 | #endif // ML_ENABLE_GEN11 47 | 48 | #if ML_ENABLE_XE_LP 49 | // XE_LP IGFX Commands 50 | #define __CODEGEN_NAMESPACE_CLOSE }; } 51 | #define __CODEGEN_PLATFORM "XE_LP" 52 | #define __CODEGEN_NAMESPACE_OPEN namespace ML::XE_LP { template struct GpuCommandsLayoutsTrait { 53 | #define __CODEGEN_FILE_DIRECTIVES_OPEN ML_STRUCTURE_PACK_BEGIN( 1 ) 54 | #define __CODEGEN_FILE_DIRECTIVES_CLOSE ML_STRUCTURE_PACK_END() 55 | #include "ml_gpu_commands_xe_lp.h" 56 | #undef __CODEGEN_NAMESPACE_OPEN 57 | #undef __CODEGEN_PLATFORM 58 | #endif // ML_ENABLE_XE_LP 59 | 60 | #if ML_ENABLE_XE_HPG 61 | // XE_HPG IGFX Commands 62 | #define __CODEGEN_NAMESPACE_CLOSE }; } 63 | #define __CODEGEN_PLATFORM "XE_HPG" 64 | #define __CODEGEN_NAMESPACE_OPEN namespace ML::XE_HPG { template struct GpuCommandsLayoutsTrait { 65 | #define __CODEGEN_FILE_DIRECTIVES_OPEN ML_STRUCTURE_PACK_BEGIN( 1 ) 66 | #define __CODEGEN_FILE_DIRECTIVES_CLOSE ML_STRUCTURE_PACK_END() 67 | #include "ml_gpu_commands_xe_hpg.h" 68 | #undef __CODEGEN_NAMESPACE_OPEN 69 | #undef __CODEGEN_PLATFORM 70 | #endif // ML_ENABLE_XE_HPG 71 | 72 | #if ML_ENABLE_XE_HPC 73 | // XE_HPC IGFX Commands 74 | #define __CODEGEN_NAMESPACE_CLOSE }; } 75 | #define __CODEGEN_PLATFORM "XE_HPC" 76 | #define __CODEGEN_NAMESPACE_OPEN namespace ML::XE_HPC { template struct GpuCommandsLayoutsTrait { 77 | #define __CODEGEN_FILE_DIRECTIVES_OPEN ML_STRUCTURE_PACK_BEGIN( 1 ) 78 | #define __CODEGEN_FILE_DIRECTIVES_CLOSE ML_STRUCTURE_PACK_END() 79 | #include "ml_gpu_commands_xe_hpc.h" 80 | #undef __CODEGEN_NAMESPACE_OPEN 81 | #undef __CODEGEN_PLATFORM 82 | #endif // ML_ENABLE_XE_HPC 83 | 84 | #if ML_ENABLE_XE2_HPG 85 | // XE2_HPG IGFX Commands 86 | #define __CODEGEN_NAMESPACE_CLOSE }; } 87 | #define __CODEGEN_PLATFORM "XE2_HPG" 88 | #define __CODEGEN_NAMESPACE_OPEN namespace ML::XE2_HPG { template struct GpuCommandsLayoutsTrait { 89 | #define __CODEGEN_FILE_DIRECTIVES_OPEN ML_STRUCTURE_PACK_BEGIN( 1 ) 90 | #define __CODEGEN_FILE_DIRECTIVES_CLOSE ML_STRUCTURE_PACK_END() 91 | #include "ml_gpu_commands_xe2_hpg.h" 92 | #undef __CODEGEN_NAMESPACE_OPEN 93 | #undef __CODEGEN_PLATFORM 94 | #endif // ML_ENABLE_XE2_HPG 95 | 96 | #if ML_ENABLE_XE3 97 | // XE3 IGFX Commands 98 | #define __CODEGEN_NAMESPACE_CLOSE }; } 99 | #define __CODEGEN_PLATFORM "XE3" 100 | #define __CODEGEN_NAMESPACE_OPEN namespace ML::XE3 { template struct GpuCommandsLayoutsTrait { 101 | #define __CODEGEN_FILE_DIRECTIVES_OPEN ML_STRUCTURE_PACK_BEGIN( 1 ) 102 | #define __CODEGEN_FILE_DIRECTIVES_CLOSE ML_STRUCTURE_PACK_END() 103 | #include "ml_gpu_commands_xe3.h" 104 | #undef __CODEGEN_NAMESPACE_OPEN 105 | #undef __CODEGEN_PLATFORM 106 | #endif // ML_ENABLE_XE3 107 | 108 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/codegen/library/inc/ml_configuration_api.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_configuration_api.h 11 | 12 | @brief Auto-generated file. Allows to compile a given api. 13 | 14 | DO NOT EDIT 15 | 16 | Script file: Tools/MetricsLibraryGenerator/generators/generate_umd.py 17 | Script function: generate_umd_configuration_api 18 | Template: Tools/MetricsLibraryGenerator/templates/configuration_api.h 19 | */ 20 | 21 | // OpenCL 22 | #if ML_LINUX 23 | #define ML_ENABLE_OPENCL 1 24 | #else 25 | #define ML_ENABLE_OPENCL 0 26 | #endif 27 | 28 | // OneApi 29 | #if ML_LINUX 30 | #define ML_ENABLE_ONEAPI 1 31 | #else 32 | #define ML_ENABLE_ONEAPI 0 33 | #endif 34 | 35 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/codegen/library/inc/ml_configuration_gpu.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_configuration_gpu.h 11 | 12 | @brief Auto-generated file. Allows to compile a given gpu platform. 13 | 14 | DO NOT EDIT 15 | 16 | Script file: Tools/MetricsLibraryGenerator/generators/generate_umd.py 17 | Script function: generate_umd_configuration_gen 18 | Template: Tools/MetricsLibraryGenerator/templates/configuration_gen.h 19 | */ 20 | 21 | // GEN9 22 | #if !defined( ML_ENABLE_GEN9 ) 23 | #if ML_LINUX 24 | #define ML_ENABLE_GEN9 1 25 | #else 26 | #define ML_ENABLE_GEN9 0 27 | #endif 28 | #endif 29 | 30 | // GEN11 31 | #if !defined( ML_ENABLE_GEN11 ) 32 | #if ML_LINUX 33 | #define ML_ENABLE_GEN11 1 34 | #else 35 | #define ML_ENABLE_GEN11 0 36 | #endif 37 | #endif 38 | 39 | // XE_LP 40 | #if !defined( ML_ENABLE_XE_LP ) 41 | #if ML_LINUX 42 | #define ML_ENABLE_XE_LP 1 43 | #else 44 | #define ML_ENABLE_XE_LP 0 45 | #endif 46 | #endif 47 | 48 | // XE_HPG 49 | #if !defined( ML_ENABLE_XE_HPG ) 50 | #if ML_LINUX 51 | #define ML_ENABLE_XE_HPG 1 52 | #else 53 | #define ML_ENABLE_XE_HPG 0 54 | #endif 55 | #endif 56 | 57 | // XE_HPC 58 | #if !defined( ML_ENABLE_XE_HPC ) 59 | #if ML_LINUX 60 | #define ML_ENABLE_XE_HPC 1 61 | #else 62 | #define ML_ENABLE_XE_HPC 0 63 | #endif 64 | #endif 65 | 66 | // XE2_HPG 67 | #if !defined( ML_ENABLE_XE2_HPG ) 68 | #if ML_LINUX 69 | #define ML_ENABLE_XE2_HPG 1 70 | #else 71 | #define ML_ENABLE_XE2_HPG 0 72 | #endif 73 | #endif 74 | 75 | // XE3 76 | #if !defined( ML_ENABLE_XE3 ) 77 | #if ML_LINUX 78 | #define ML_ENABLE_XE3 1 79 | #else 80 | #define ML_ENABLE_XE3 0 81 | #endif 82 | #endif 83 | 84 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/codegen/library/ml_export.def: -------------------------------------------------------------------------------- 1 | ;=========================== begin_copyright_notice ============================ 2 | ; 3 | ; Copyright (C) 2020-2025 Intel Corporation 4 | ; 5 | ; SPDX-License-Identifier: MIT 6 | ; 7 | ;============================ end_copyright_notice ============================= 8 | 9 | ; Auto-generated file. Allows to export a given entry points. 10 | ; 11 | ; DO NOT EDIT 12 | ; 13 | ; Script file: Tools/MetricsLibraryGenerator/generators/generate_umd.py 14 | ; Script function: generate_export 15 | ; Template: Tools/MetricsLibraryGenerator/templates/def.h 16 | ; 17 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 18 | 19 | EXPORTS 20 | ContextCreate_1_0 21 | ContextDelete_1_0 22 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/codegen/traits/ml_traits_include.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_traits_include.h 11 | 12 | @brief Auto-generated file. Creates a single header with all traits header files. 13 | 14 | DO NOT EDIT 15 | 16 | Script file: Tools/MetricsLibraryGenerator/generators/generate_umd.py 17 | Script function: generate_umd_traits_include 18 | Template: Tools/MetricsLibraryGenerator/templates/traits_include.h 19 | */ 20 | 21 | ////////////////////////////////////////////////////////////////////////// 22 | /// @brief Common. 23 | ////////////////////////////////////////////////////////////////////////// 24 | 25 | ////////////////////////////////////////////////////////////////////////// 26 | /// @brief Constants: 27 | ////////////////////////////////////////////////////////////////////////// 28 | #if ML_LINUX 29 | #include "linux/ml_constants_os.h" 30 | #endif 31 | 32 | ////////////////////////////////////////////////////////////////////////// 33 | /// @brief Tools: 34 | ////////////////////////////////////////////////////////////////////////// 35 | #include "ml_tools.h" 36 | #if ML_LINUX 37 | #include "linux/ml_tools_os.h" 38 | #endif 39 | 40 | ////////////////////////////////////////////////////////////////////////// 41 | /// @brief Logs: 42 | ////////////////////////////////////////////////////////////////////////// 43 | #if ML_DEBUG || ML_INTERNAL 44 | #include "ml_function_log.h" 45 | #endif 46 | #if ML_RELEASE 47 | #include "ml_function_log_release.h" 48 | #endif 49 | 50 | ////////////////////////////////////////////////////////////////////////// 51 | /// @brief Library context: 52 | ////////////////////////////////////////////////////////////////////////// 53 | #include "ml_context.h" 54 | #include "ml_client_options.h" 55 | #include "ml_ddi_objects.h" 56 | #include "ml_state.h" 57 | 58 | ////////////////////////////////////////////////////////////////////////// 59 | /// @brief SubDevice: 60 | ////////////////////////////////////////////////////////////////////////// 61 | #include "ml_sub_device_common.h" 62 | #if ML_LINUX 63 | #include "linux/ml_sub_device.h" 64 | #endif 65 | 66 | ////////////////////////////////////////////////////////////////////////// 67 | /// @brief Gpu registers commands / command buffer: 68 | ////////////////////////////////////////////////////////////////////////// 69 | #include "ml_gpu_command_buffer.h" 70 | #include "ml_gpu_commands.h" 71 | #include "ml_gpu_registers.h" 72 | 73 | ////////////////////////////////////////////////////////////////////////// 74 | /// @brief Layouts: 75 | ////////////////////////////////////////////////////////////////////////// 76 | #include "ml_configuration_layouts.h" 77 | #include "ml_oa_buffer_layouts.h" 78 | #include "ml_hw_counters_layouts.h" 79 | #include "ml_gpu_commands_include.h" 80 | #if ML_LINUX 81 | #include "linux/ml_override_layouts.h" 82 | #endif 83 | #include "ml_gpu_registers_layouts.h" 84 | #if ML_LINUX 85 | #include "linux/ml_drm_layouts.h" 86 | #endif 87 | 88 | ////////////////////////////////////////////////////////////////////////// 89 | /// @brief Debug helper: 90 | ////////////////////////////////////////////////////////////////////////// 91 | #if ML_LINUX 92 | #include "linux/ml_debug_helper.h" 93 | #endif 94 | 95 | ////////////////////////////////////////////////////////////////////////// 96 | /// @brief Markers: 97 | ////////////////////////////////////////////////////////////////////////// 98 | #include "ml_marker_stream_user.h" 99 | #if ML_LINUX 100 | #include "linux/ml_marker_stream_user_extended.h" 101 | #endif 102 | 103 | ////////////////////////////////////////////////////////////////////////// 104 | /// @brief Linux kernel interface traits: 105 | ////////////////////////////////////////////////////////////////////////// 106 | #if ML_LINUX 107 | #include "linux/ml_kernel_interface.h" 108 | #endif 109 | #if ML_LINUX 110 | #include "linux/ml_tbs_interface.h" 111 | #endif 112 | #if ML_LINUX 113 | #include "linux/ml_tbs_stream.h" 114 | #endif 115 | #if ML_LINUX 116 | #include "linux/ml_io_control.h" 117 | #endif 118 | 119 | ////////////////////////////////////////////////////////////////////////// 120 | /// @brief Configurations: 121 | ////////////////////////////////////////////////////////////////////////// 122 | #if ML_LINUX 123 | #include "linux/ml_configuration_hw_counters_oa.h" 124 | #endif 125 | #include "ml_configuration_hw_counters_user.h" 126 | 127 | ////////////////////////////////////////////////////////////////////////// 128 | /// @brief Oa buffer support: 129 | ////////////////////////////////////////////////////////////////////////// 130 | #if 0 131 | #include "ml_oa_buffer_dummy.h" 132 | #endif 133 | #include "ml_oa_buffer_mapped.h" 134 | 135 | ////////////////////////////////////////////////////////////////////////// 136 | /// @brief Overrides: 137 | ////////////////////////////////////////////////////////////////////////// 138 | #if ML_LINUX 139 | #include "linux/ml_override_user.h" 140 | #endif 141 | #include "ml_override_null_hardware.h" 142 | #include "ml_override_flush_caches.h" 143 | #if ML_LINUX 144 | #include "linux/ml_override_posh_query.h" 145 | #endif 146 | 147 | ////////////////////////////////////////////////////////////////////////// 148 | /// @brief Queries: 149 | ////////////////////////////////////////////////////////////////////////// 150 | 151 | ////////////////////////////////////////////////////////////////////////// 152 | /// @brief Hw Counters: 153 | ////////////////////////////////////////////////////////////////////////// 154 | #include "ml_query_hw_counters_slot.h" 155 | #include "ml_query_hw_counters.h" 156 | #include "ml_query_hw_counters_calculator.h" 157 | 158 | ////////////////////////////////////////////////////////////////////////// 159 | /// @brief Internal features: 160 | ////////////////////////////////////////////////////////////////////////// 161 | #if ML_LINUX || ML_RELEASE 162 | #include "ml_internal_feature.h" 163 | #endif 164 | 165 | ////////////////////////////////////////////////////////////////////////// 166 | /// @brief OpenCL. 167 | ////////////////////////////////////////////////////////////////////////// 168 | #if ML_ENABLE_OPENCL 169 | #if ML_LINUX 170 | #include "linux/ml_policy_opencl.h" 171 | #endif 172 | #endif 173 | 174 | ////////////////////////////////////////////////////////////////////////// 175 | /// @brief OneApi. 176 | ////////////////////////////////////////////////////////////////////////// 177 | #if ML_ENABLE_ONEAPI 178 | #if ML_LINUX 179 | #include "linux/ml_policy_oneapi.h" 180 | #endif 181 | #endif 182 | 183 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/ddi/ml_ddi_command_buffer.hpp: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_ddi_command_buffer.hpp 11 | 12 | @brief Partially auto-generated file. Provides implementation for Metrics Library 13 | entry points. 14 | 15 | Script file: Tools/MetricsLibraryGenerator/generators/generate_umd.py 16 | Script function: generate_umd_ddi 17 | Template: Tools/MetricsLibraryGenerator/templates/hpp.h 18 | */ 19 | 20 | #pragma once 21 | 22 | namespace ML 23 | { 24 | ////////////////////////////////////////////////////////////////////////// 25 | /// @brief Functions for DdiCommandBuffer. 26 | ////////////////////////////////////////////////////////////////////////// 27 | template 28 | struct DdiCommandBuffer 29 | { 30 | ////////////////////////////////////////////////////////////////////////// 31 | /// @brief Generic implementation for CommandBufferGet_1_0 32 | /// @param data 33 | ////////////////////////////////////////////////////////////////////////// 34 | ML_INLINE static StatusCode ML_STDCALL CommandBufferGet_1_0( 35 | const CommandBufferData_1_0* data ) 36 | { 37 | ML_FUNCTION_CHECK_STATIC( data != nullptr ); 38 | ML_FUNCTION_CHECK_STATIC( T::Context::IsValid( data->HandleContext ) ); 39 | 40 | auto& context = T::Context::FromHandle( data->HandleContext ); 41 | ML_FUNCTION_LOG( StatusCode::Success, &context ); 42 | 43 | // Print input values. 44 | log.Input( *data ); 45 | 46 | TT::GpuCommandBuffer buffer = { data->Data, data->Size, data->Type, data->Allocation, context }; 47 | 48 | switch( data->CommandsType ) 49 | { 50 | case ObjectType::QueryHwCounters: 51 | log.m_Result = T::Queries::HwCounters::Write( buffer, data->Allocation, data->QueryHwCounters ); 52 | break; 53 | 54 | case ObjectType::QueryHwCountersCopyReports: 55 | log.m_Result = T::Queries::HwCounters::CopyReports( buffer, data->QueryHwCountersCopyReports ); 56 | break; 57 | 58 | case ObjectType::OverrideUser: 59 | log.m_Result = T::Overrides::User::Write( buffer, data->Override ); 60 | break; 61 | 62 | case ObjectType::OverrideFlushCaches: 63 | log.m_Result = T::Overrides::FlushCaches::Write( buffer ); 64 | break; 65 | 66 | case ObjectType::OverrideNullHardware: 67 | log.m_Result = T::Overrides::NullHardware::Write( buffer, data->Override.Enable ); 68 | break; 69 | 70 | case ObjectType::MarkerStreamUser: 71 | log.m_Result = T::Markers::StreamUser::Write( buffer, data->MarkerStreamUser ); 72 | break; 73 | 74 | case ObjectType::MarkerStreamUserExtended: 75 | log.m_Result = T::Markers::StreamUserExtended::Write( buffer, data->MarkerStreamUserExtended ); 76 | break; 77 | 78 | default: 79 | ML_ASSERT_ALWAYS(); 80 | log.m_Result = StatusCode::IncorrectObject; 81 | break; 82 | } 83 | 84 | ML_ASSERT( log.m_Result == StatusCode::Success ); 85 | 86 | return log.m_Result; 87 | } 88 | 89 | ////////////////////////////////////////////////////////////////////////// 90 | /// @brief Generic implementation for CommandBufferGetSize_1_0 91 | /// @param data 92 | /// @param size 93 | ////////////////////////////////////////////////////////////////////////// 94 | ML_INLINE static StatusCode ML_STDCALL CommandBufferGetSize_1_0( 95 | const CommandBufferData_1_0* data, 96 | CommandBufferSize_1_0* size ) 97 | { 98 | ML_FUNCTION_CHECK_STATIC( data != nullptr ); 99 | ML_FUNCTION_CHECK_STATIC( size != nullptr ); 100 | ML_FUNCTION_CHECK_STATIC( T::Context::IsValid( data->HandleContext ) ); 101 | 102 | auto& context = T::Context::FromHandle( data->HandleContext ); 103 | ML_FUNCTION_LOG( StatusCode::Success, &context ); 104 | 105 | // Print input values. 106 | log.Input( *data ); 107 | 108 | TT::GpuCommandBufferCalculator buffer = { data->Type, context }; 109 | 110 | switch( data->CommandsType ) 111 | { 112 | case ObjectType::QueryHwCounters: 113 | log.m_Result = T::Queries::HwCounters::Write( buffer, data->Allocation, data->QueryHwCounters ); 114 | break; 115 | 116 | case ObjectType::QueryHwCountersCopyReports: 117 | log.m_Result = T::Queries::HwCounters::CopyReports( buffer, data->QueryHwCountersCopyReports ); 118 | break; 119 | 120 | case ObjectType::OverrideUser: 121 | log.m_Result = T::Overrides::User::Write( buffer, data->Override ); 122 | break; 123 | 124 | case ObjectType::OverrideNullHardware: 125 | log.m_Result = T::Overrides::NullHardware::Write( buffer, data->Override.Enable ); 126 | break; 127 | 128 | case ObjectType::OverrideFlushCaches: 129 | log.m_Result = T::Overrides::FlushCaches::Write( buffer ); 130 | break; 131 | 132 | case ObjectType::MarkerStreamUser: 133 | log.m_Result = T::Markers::StreamUser::Write( buffer, data->MarkerStreamUser ); 134 | break; 135 | 136 | case ObjectType::MarkerStreamUserExtended: 137 | log.m_Result = T::Markers::StreamUserExtended::Write( buffer, data->MarkerStreamUserExtended ); 138 | break; 139 | 140 | default: 141 | ML_ASSERT_ALWAYS(); 142 | log.m_Result = StatusCode::IncorrectObject; 143 | break; 144 | } 145 | 146 | if( ML_SUCCESS( log.m_Result ) ) 147 | { 148 | buffer.GetSizeRequirements( *size ); 149 | 150 | // Print output values. 151 | log.Output( *size ); 152 | } 153 | else 154 | { 155 | ML_ASSERT_ALWAYS(); 156 | } 157 | 158 | return log.m_Result; 159 | } 160 | }; 161 | } // namespace ML 162 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/ddi/ml_ddi_configuration.hpp: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_ddi_configuration.hpp 11 | 12 | @brief Partially auto-generated file. Provides implementation for Metrics Library 13 | entry points. 14 | 15 | Script file: Tools/MetricsLibraryGenerator/generators/generate_umd.py 16 | Script function: generate_umd_ddi 17 | Template: Tools/MetricsLibraryGenerator/templates/hpp.h 18 | */ 19 | 20 | #pragma once 21 | 22 | namespace ML 23 | { 24 | ////////////////////////////////////////////////////////////////////////// 25 | /// @brief Functions for DdiConfiguration. 26 | ////////////////////////////////////////////////////////////////////////// 27 | template 28 | struct DdiConfiguration 29 | { 30 | ////////////////////////////////////////////////////////////////////////// 31 | /// @brief Generic implementation for ConfigurationCreate_1_0 32 | /// @param createData 33 | /// @param handle 34 | ////////////////////////////////////////////////////////////////////////// 35 | ML_INLINE static StatusCode ML_STDCALL ConfigurationCreate_1_0( 36 | const ConfigurationCreateData_1_0* createData, 37 | ConfigurationHandle_1_0* handle ) 38 | { 39 | ML_FUNCTION_CHECK_STATIC( handle != nullptr ); 40 | ML_FUNCTION_CHECK_STATIC( createData != nullptr ); 41 | ML_FUNCTION_CHECK_STATIC( T::Context::IsValid( createData->HandleContext ) ); 42 | 43 | auto& context = T::Context::FromHandle( createData->HandleContext ); 44 | ML_FUNCTION_LOG( StatusCode::Success, &context ); 45 | 46 | // Print input values. 47 | log.Input( *createData ); 48 | 49 | switch( createData->Type ) 50 | { 51 | case ObjectType::ConfigurationHwCountersOa: 52 | log.m_Result = T::Configurations::HwCountersOa::Create( context, *handle ); 53 | break; 54 | 55 | case ObjectType::ConfigurationHwCountersUser: 56 | log.m_Result = T::Configurations::HwCountersUser::Create( context, *handle ); 57 | break; 58 | 59 | default: 60 | ML_ASSERT_ALWAYS(); 61 | log.m_Result = StatusCode::IncorrectParameter; 62 | break; 63 | } 64 | 65 | ML_ASSERT( log.m_Result == StatusCode::Success ); 66 | 67 | // Print output values. 68 | log.Output( *handle ); 69 | 70 | return log.m_Result; 71 | } 72 | 73 | ////////////////////////////////////////////////////////////////////////// 74 | /// @brief Generic implementation for ConfigurationActivate_1_0 75 | /// @param handle 76 | /// @param activateData 77 | ////////////////////////////////////////////////////////////////////////// 78 | ML_INLINE static StatusCode ML_STDCALL ConfigurationActivate_1_0( 79 | const ConfigurationHandle_1_0 handle, 80 | const ConfigurationActivateData_1_0* activateData ) 81 | { 82 | ML_FUNCTION_CHECK_STATIC( activateData != nullptr ); 83 | 84 | switch( BaseObject::GetType( handle ) ) 85 | { 86 | case ObjectType::ConfigurationHwCountersOa: 87 | { 88 | auto& config = T::Configurations::HwCountersOa::FromHandle( handle ); 89 | ML_FUNCTION_LOG( StatusCode::Success, &config.m_Context ); 90 | 91 | // Print input values. 92 | log.Input( handle ); 93 | log.Input( *activateData ); 94 | 95 | log.m_Result = config.Activate( *activateData ); 96 | ML_ASSERT( log.m_Result == StatusCode::Success ); 97 | 98 | return log.m_Result; 99 | } 100 | case ObjectType::ConfigurationHwCountersUser: 101 | { 102 | ML_FUNCTION_LOG_STATIC( StatusCode::Failed ); 103 | 104 | // Print input values. 105 | log.Input( handle ); 106 | log.Input( *activateData ); 107 | 108 | ML_ASSERT( log.m_Result == StatusCode::Success ); 109 | 110 | return log.m_Result; 111 | } 112 | default: 113 | { 114 | ML_FUNCTION_LOG_STATIC( StatusCode::IncorrectObject ); 115 | ML_ASSERT_ALWAYS(); 116 | 117 | // Print input values. 118 | log.Input( handle ); 119 | log.Input( *activateData ); 120 | 121 | return log.m_Result; 122 | } 123 | } 124 | } 125 | 126 | ////////////////////////////////////////////////////////////////////////// 127 | /// @brief Generic implementation for ConfigurationDeactivate_1_0 128 | /// @param handle 129 | ////////////////////////////////////////////////////////////////////////// 130 | ML_INLINE static StatusCode ML_STDCALL ConfigurationDeactivate_1_0( 131 | const ConfigurationHandle_1_0 handle ) 132 | { 133 | switch( BaseObject::GetType( handle ) ) 134 | { 135 | case ObjectType::ConfigurationHwCountersOa: 136 | { 137 | auto& config = T::Configurations::HwCountersOa::FromHandle( handle ); 138 | ML_FUNCTION_LOG( StatusCode::Success, &config.m_Context ); 139 | 140 | // Print input values. 141 | log.Input( handle ); 142 | 143 | log.m_Result = config.Deactivate(); 144 | ML_ASSERT( log.m_Result == StatusCode::Success ); 145 | 146 | return log.m_Result; 147 | } 148 | case ObjectType::ConfigurationHwCountersUser: 149 | { 150 | ML_FUNCTION_LOG_STATIC( StatusCode::Failed ); 151 | 152 | // Print input values. 153 | log.Input( handle ); 154 | 155 | ML_ASSERT( log.m_Result == StatusCode::Success ); 156 | 157 | return log.m_Result; 158 | } 159 | default: 160 | { 161 | ML_FUNCTION_LOG_STATIC( StatusCode::IncorrectObject ); 162 | ML_ASSERT_ALWAYS(); 163 | 164 | // Print input values. 165 | log.Input( handle ); 166 | 167 | return log.m_Result; 168 | } 169 | } 170 | } 171 | 172 | ////////////////////////////////////////////////////////////////////////// 173 | /// @brief Generic implementation for ConfigurationDelete_1_0 174 | /// @param handle 175 | ////////////////////////////////////////////////////////////////////////// 176 | ML_INLINE static StatusCode ML_STDCALL ConfigurationDelete_1_0( 177 | const ConfigurationHandle_1_0 handle ) 178 | { 179 | switch( BaseObject::GetType( handle ) ) 180 | { 181 | case ObjectType::ConfigurationHwCountersOa: 182 | { 183 | auto& context = T::Configurations::HwCountersOa::FromHandle( handle ).m_Context; 184 | ML_FUNCTION_LOG( StatusCode::Success, &context ); 185 | 186 | // Print input values. 187 | log.Input( handle ); 188 | 189 | log.m_Result = T::Configurations::HwCountersOa::Delete( handle ); 190 | ML_ASSERT( log.m_Result == StatusCode::Success ); 191 | 192 | return log.m_Result; 193 | } 194 | case ObjectType::ConfigurationHwCountersUser: 195 | { 196 | auto& context = T::Configurations::HwCountersUser::FromHandle( handle ).m_Context; 197 | ML_FUNCTION_LOG( StatusCode::Success, &context ); 198 | 199 | // Print input values. 200 | log.Input( handle ); 201 | 202 | log.m_Result = T::Configurations::HwCountersUser::Delete( handle ); 203 | ML_ASSERT( log.m_Result == StatusCode::Success ); 204 | 205 | return log.m_Result; 206 | } 207 | default: 208 | { 209 | ML_FUNCTION_LOG_STATIC( StatusCode::IncorrectObject ); 210 | ML_ASSERT_ALWAYS(); 211 | 212 | // Print input values. 213 | log.Input( handle ); 214 | 215 | return log.m_Result; 216 | } 217 | } 218 | } 219 | }; 220 | } // namespace ML 221 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/ddi/ml_ddi_context.hpp: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_ddi_context.hpp 11 | 12 | @brief Partially auto-generated file. Provides implementation for Metrics Library 13 | entry points. 14 | 15 | Script file: Tools/MetricsLibraryGenerator/generators/generate_umd.py 16 | Script function: generate_umd_ddi 17 | Template: Tools/MetricsLibraryGenerator/templates/hpp.h 18 | */ 19 | 20 | #pragma once 21 | 22 | namespace ML 23 | { 24 | ////////////////////////////////////////////////////////////////////////// 25 | /// @brief Functions for DdiContext. 26 | ////////////////////////////////////////////////////////////////////////// 27 | template 28 | struct DdiContext 29 | { 30 | ////////////////////////////////////////////////////////////////////////// 31 | /// @brief Generic implementation for ContextCreate_1_0 32 | /// @param clientType 33 | /// @param createData 34 | /// @param handle 35 | ////////////////////////////////////////////////////////////////////////// 36 | ML_INLINE static StatusCode ML_STDCALL ContextCreate_1_0( 37 | ClientType_1_0 clientType, 38 | ContextCreateData_1_0* createData, 39 | ContextHandle_1_0* handle ) 40 | { 41 | ML_FUNCTION_LOG_STATIC( StatusCode::Success ); 42 | ML_FUNCTION_CHECK( createData != nullptr ); 43 | ML_FUNCTION_CHECK( handle != nullptr ); 44 | 45 | // Print build number. 46 | T::FunctionLogStatic::Traits( "Major number", METRICS_LIBRARY_MAJOR_NUMBER ); 47 | T::FunctionLogStatic::Traits( "Minor number", METRICS_LIBRARY_MINOR_NUMBER ); 48 | T::FunctionLogStatic::Traits( "Build number", METRICS_LIBRARY_BUILD_NUMBER ); 49 | 50 | // Print input values. 51 | log.Input( clientType ); 52 | log.Input( *createData ); 53 | 54 | log.m_Result = T::Context::Create( clientType, *createData, *handle ); 55 | 56 | // Print output values. 57 | log.Output( *createData ); 58 | log.Output( *handle ); 59 | 60 | return log.m_Result; 61 | } 62 | 63 | ////////////////////////////////////////////////////////////////////////// 64 | /// @brief Generic implementation for ContextDelete_1_0 65 | /// @param handle 66 | ////////////////////////////////////////////////////////////////////////// 67 | ML_INLINE static StatusCode ML_STDCALL ContextDelete_1_0( 68 | const ContextHandle_1_0 handle ) 69 | { 70 | ML_FUNCTION_CHECK_STATIC( T::Context::IsValid( handle ) ); 71 | 72 | auto& context = T::Context::FromHandle( handle ); 73 | ML_FUNCTION_LOG( StatusCode::Success, &context ); 74 | 75 | // Print input values. 76 | log.Input( handle ); 77 | 78 | log.m_Result = T::Context::Delete( handle ); 79 | log.m_Context = nullptr; 80 | 81 | ML_ASSERT( log.m_Result == StatusCode::Success ); 82 | 83 | return log.m_Result; 84 | } 85 | 86 | ////////////////////////////////////////////////////////////////////////// 87 | /// @brief Generic implementation for GetParameter_1_0 88 | /// @param parameter 89 | /// @param type 90 | /// @param value 91 | ////////////////////////////////////////////////////////////////////////// 92 | ML_INLINE static StatusCode ML_STDCALL GetParameter_1_0( 93 | const ParameterType parameter, 94 | ValueType* type, 95 | TypedValue_1_0* value ) 96 | { 97 | ML_FUNCTION_LOG_STATIC( StatusCode::Success ); 98 | ML_FUNCTION_CHECK( type != nullptr ); 99 | ML_FUNCTION_CHECK( value != nullptr ); 100 | 101 | // Print input values. 102 | log.Input( parameter ); 103 | 104 | switch( parameter ) 105 | { 106 | case ParameterType::QueryHwCountersReportApiSize: 107 | *type = ValueType::Uint32; 108 | value->ValueUInt32 = sizeof( TT::Layouts::HwCounters::Query::ReportApi ); 109 | break; 110 | 111 | case ParameterType::QueryHwCountersReportGpuSize: 112 | *type = ValueType::Uint32; 113 | value->ValueUInt32 = sizeof( TT::Layouts::HwCounters::Query::ReportGpu ); 114 | break; 115 | 116 | case ParameterType::LibraryBuildNumber: 117 | *type = ValueType::Uint32; 118 | value->ValueUInt32 = METRICS_LIBRARY_BUILD_NUMBER; 119 | break; 120 | 121 | default: 122 | ML_ASSERT_ALWAYS(); 123 | log.m_Result = StatusCode::NotImplemented; 124 | break; 125 | } 126 | 127 | value->Type = *type; 128 | 129 | // Print output values. 130 | log.Output( *type ); 131 | log.Output( *value ); 132 | 133 | ML_ASSERT( log.m_Result == StatusCode::Success ); 134 | 135 | return log.m_Result; 136 | } 137 | }; 138 | } // namespace ML 139 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/ddi/ml_ddi_marker.hpp: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_ddi_marker.hpp 11 | 12 | @brief Partially auto-generated file. Provides implementation for Metrics Library 13 | entry points. 14 | 15 | Script file: Tools/MetricsLibraryGenerator/generators/generate_umd.py 16 | Script function: generate_umd_ddi 17 | Template: Tools/MetricsLibraryGenerator/templates/hpp.h 18 | */ 19 | 20 | #pragma once 21 | 22 | namespace ML 23 | { 24 | ////////////////////////////////////////////////////////////////////////// 25 | /// @brief Functions for DdiMarker. 26 | ////////////////////////////////////////////////////////////////////////// 27 | template 28 | struct DdiMarker 29 | { 30 | ////////////////////////////////////////////////////////////////////////// 31 | /// @brief Generic implementation for MarkerCreate_1_0 32 | /// @param createData 33 | /// @param handle 34 | ////////////////////////////////////////////////////////////////////////// 35 | ML_INLINE static StatusCode ML_STDCALL MarkerCreate_1_0( 36 | const MarkerCreateData_1_0* createData, 37 | MarkerHandle_1_0* handle ) 38 | { 39 | ML_FUNCTION_CHECK_STATIC( handle != nullptr ); 40 | ML_FUNCTION_CHECK_STATIC( createData != nullptr ); 41 | ML_FUNCTION_CHECK_STATIC( T::Context::IsValid( createData->HandleContext ) ); 42 | 43 | auto& context = T::Context::FromHandle( createData->HandleContext ); 44 | ML_FUNCTION_LOG( StatusCode::Success, &context ) 45 | 46 | // Print input values. 47 | log.Input( *createData ); 48 | 49 | switch( createData->Type ) 50 | { 51 | case ObjectType::MarkerStreamUser: 52 | log.m_Result = StatusCode::NotImplemented; 53 | break; 54 | 55 | default: 56 | ML_ASSERT_ALWAYS(); 57 | log.m_Result = StatusCode::IncorrectParameter; 58 | break; 59 | } 60 | 61 | ML_ASSERT( log.m_Result == StatusCode::Success ); 62 | 63 | // Print output values. 64 | log.Output( *handle ); 65 | 66 | return log.m_Result; 67 | } 68 | 69 | ////////////////////////////////////////////////////////////////////////// 70 | /// @brief Generic implementation for MarkerDelete_1_0 71 | /// @param handle 72 | ////////////////////////////////////////////////////////////////////////// 73 | ML_INLINE static StatusCode ML_STDCALL MarkerDelete_1_0( 74 | const MarkerHandle_1_0 handle ) 75 | { 76 | ML_FUNCTION_LOG_STATIC( StatusCode::Success ); 77 | 78 | // Print input values. 79 | log.Input( handle ); 80 | 81 | switch( BaseObject::GetType( handle ) ) 82 | { 83 | case ObjectType::MarkerStreamUser: 84 | log.m_Result = StatusCode::NotImplemented; 85 | break; 86 | 87 | default: 88 | ML_ASSERT_ALWAYS(); 89 | log.m_Result = StatusCode::IncorrectObject; 90 | break; 91 | } 92 | 93 | ML_ASSERT( log.m_Result == StatusCode::Success ); 94 | 95 | return log.m_Result; 96 | } 97 | }; 98 | } // namespace ML 99 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/ddi/ml_ddi_override.hpp: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_ddi_override.hpp 11 | 12 | @brief Partially auto-generated file. Provides implementation for Metrics Library 13 | entry points. 14 | 15 | Script file: Tools/MetricsLibraryGenerator/generators/generate_umd.py 16 | Script function: generate_umd_ddi 17 | Template: Tools/MetricsLibraryGenerator/templates/hpp.h 18 | */ 19 | 20 | #pragma once 21 | 22 | namespace ML 23 | { 24 | ////////////////////////////////////////////////////////////////////////// 25 | /// @brief Functions for DdiOverride. 26 | ////////////////////////////////////////////////////////////////////////// 27 | template 28 | struct DdiOverride 29 | { 30 | ////////////////////////////////////////////////////////////////////////// 31 | /// @brief Generic implementation for OverrideCreate_1_0 32 | /// @param createData 33 | /// @param handle 34 | ////////////////////////////////////////////////////////////////////////// 35 | ML_INLINE static StatusCode ML_STDCALL OverrideCreate_1_0( 36 | const OverrideCreateData_1_0* createData, 37 | OverrideHandle_1_0* handle ) 38 | { 39 | ML_FUNCTION_CHECK_STATIC( handle != nullptr ); 40 | ML_FUNCTION_CHECK_STATIC( createData != nullptr ); 41 | ML_FUNCTION_CHECK_STATIC( T::Context::IsValid( createData->HandleContext ) ); 42 | 43 | auto& context = T::Context::FromHandle( createData->HandleContext ); 44 | ML_FUNCTION_LOG( StatusCode::Success, &context ); 45 | 46 | // Print input values. 47 | log.Input( *createData ); 48 | 49 | switch( createData->Type ) 50 | { 51 | case ObjectType::OverrideUser: 52 | log.m_Result = T::Overrides::User::Create( context, *handle ); 53 | break; 54 | 55 | case ObjectType::OverrideNullHardware: 56 | log.m_Result = StatusCode::NotImplemented; 57 | break; 58 | 59 | case ObjectType::OverrideFlushCaches: 60 | log.m_Result = StatusCode::NotImplemented; 61 | break; 62 | 63 | case ObjectType::OverridePoshQuery: 64 | log.m_Result = T::Overrides::PoshQuery::Create( context, *handle ); 65 | break; 66 | 67 | default: 68 | ML_ASSERT_ALWAYS(); 69 | log.m_Result = StatusCode::IncorrectParameter; 70 | break; 71 | } 72 | 73 | ML_ASSERT( log.m_Result == StatusCode::Success ); 74 | 75 | // Print output values. 76 | log.Output( *handle ); 77 | 78 | return log.m_Result; 79 | } 80 | 81 | ////////////////////////////////////////////////////////////////////////// 82 | /// @brief Generic implementation for OverrideDelete_1_0 83 | /// @param handle 84 | ////////////////////////////////////////////////////////////////////////// 85 | ML_INLINE static StatusCode ML_STDCALL OverrideDelete_1_0( 86 | const OverrideHandle_1_0 handle ) 87 | { 88 | switch( BaseObject::GetType( handle ) ) 89 | { 90 | case ObjectType::OverrideUser: 91 | { 92 | auto& context = T::Overrides::User::FromHandle( handle ).m_Context; 93 | ML_FUNCTION_LOG( StatusCode::Success, &context ); 94 | 95 | // Print input values. 96 | log.Input( handle ); 97 | 98 | log.m_Result = T::Overrides::User::Delete( handle ); 99 | ML_ASSERT( log.m_Result == StatusCode::Success ); 100 | 101 | return log.m_Result; 102 | } 103 | case ObjectType::OverrideNullHardware: 104 | { 105 | ML_FUNCTION_LOG_STATIC( StatusCode::NotImplemented ); 106 | 107 | // Print input values. 108 | log.Input( handle ); 109 | 110 | ML_ASSERT( log.m_Result == StatusCode::Success ); 111 | 112 | return log.m_Result; 113 | } 114 | case ObjectType::OverrideFlushCaches: 115 | { 116 | ML_FUNCTION_LOG_STATIC( StatusCode::NotImplemented ); 117 | 118 | // Print input values. 119 | log.Input( handle ); 120 | 121 | ML_ASSERT( log.m_Result == StatusCode::Success ); 122 | 123 | return log.m_Result; 124 | } 125 | case ObjectType::OverridePoshQuery: 126 | { 127 | auto& context = T::Overrides::PoshQuery::FromHandle( handle ).m_Context; 128 | ML_FUNCTION_LOG( StatusCode::Success, &context ); 129 | 130 | // Print input values. 131 | log.Input( handle ); 132 | 133 | log.m_Result = T::Overrides::PoshQuery::Delete( handle ); 134 | ML_ASSERT( log.m_Result == StatusCode::Success ); 135 | 136 | return log.m_Result; 137 | } 138 | default: 139 | { 140 | ML_FUNCTION_LOG_STATIC( StatusCode::IncorrectObject ); 141 | ML_ASSERT_ALWAYS(); 142 | 143 | // Print input values. 144 | log.Input( handle ); 145 | 146 | return log.m_Result; 147 | } 148 | } 149 | } 150 | }; 151 | } // namespace ML 152 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/ddi/ml_ddi_query.hpp: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_ddi_query.hpp 11 | 12 | @brief Partially auto-generated file. Provides implementation for Metrics Library 13 | entry points. 14 | 15 | Script file: Tools/MetricsLibraryGenerator/generators/generate_umd.py 16 | Script function: generate_umd_ddi 17 | Template: Tools/MetricsLibraryGenerator/templates/hpp.h 18 | */ 19 | 20 | #pragma once 21 | 22 | namespace ML 23 | { 24 | ////////////////////////////////////////////////////////////////////////// 25 | /// @brief Functions for DdiQuery. 26 | ////////////////////////////////////////////////////////////////////////// 27 | template 28 | struct DdiQuery 29 | { 30 | ////////////////////////////////////////////////////////////////////////// 31 | /// @brief Generic implementation for QueryCreate_1_0 32 | /// @param createData 33 | /// @param handle 34 | ////////////////////////////////////////////////////////////////////////// 35 | ML_INLINE static StatusCode ML_STDCALL QueryCreate_1_0( 36 | const QueryCreateData_1_0* createData, 37 | QueryHandle_1_0* handle ) 38 | { 39 | ML_FUNCTION_CHECK_STATIC( handle != nullptr ); 40 | ML_FUNCTION_CHECK_STATIC( createData != nullptr ); 41 | ML_FUNCTION_CHECK_STATIC( T::Context::IsValid( createData->HandleContext ) ); 42 | 43 | auto& context = T::Context::FromHandle( createData->HandleContext ); 44 | ML_FUNCTION_LOG( StatusCode::Success, &context ); 45 | 46 | // Print input values. 47 | log.Input( *createData ); 48 | 49 | switch( createData->Type ) 50 | { 51 | case ObjectType::QueryHwCounters: 52 | log.m_Result = T::Queries::HwCounters::Create( *createData, *handle ); 53 | break; 54 | 55 | default: 56 | ML_ASSERT_ALWAYS(); 57 | log.m_Result = StatusCode::IncorrectParameter; 58 | break; 59 | } 60 | 61 | // Print input values. 62 | log.Output( *handle ); 63 | 64 | return log.m_Result; 65 | } 66 | 67 | ////////////////////////////////////////////////////////////////////////// 68 | /// @brief Generic implementation for QueryDelete_1_0 69 | /// @param handle 70 | ////////////////////////////////////////////////////////////////////////// 71 | ML_INLINE static StatusCode ML_STDCALL QueryDelete_1_0( 72 | const QueryHandle_1_0 handle ) 73 | { 74 | switch( BaseObject::GetType( handle ) ) 75 | { 76 | case ObjectType::QueryHwCounters: 77 | { 78 | auto& context = T::Queries::HwCounters::FromHandle( handle ).m_Context; 79 | ML_FUNCTION_LOG( StatusCode::Success, &context ); 80 | 81 | // Print input values. 82 | log.Input( handle ); 83 | 84 | log.m_Result = T::Queries::HwCounters::Delete( handle ); 85 | ML_ASSERT( log.m_Result == StatusCode::Success ); 86 | 87 | return log.m_Result; 88 | } 89 | default: 90 | { 91 | ML_FUNCTION_LOG_STATIC( StatusCode::IncorrectObject ); 92 | ML_ASSERT_ALWAYS(); 93 | 94 | // Print input values. 95 | log.Input( handle ); 96 | 97 | return log.m_Result; 98 | } 99 | } 100 | } 101 | }; 102 | } // namespace ML 103 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/ddi/ml_ddi_report.hpp: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_ddi_report.hpp 11 | 12 | @brief Partially auto-generated file. Provides implementation for Metrics Library 13 | entry points. 14 | 15 | Script file: Tools/MetricsLibraryGenerator/generators/generate_umd.py 16 | Script function: generate_umd_ddi 17 | Template: Tools/MetricsLibraryGenerator/templates/hpp.h 18 | */ 19 | 20 | #pragma once 21 | 22 | namespace ML 23 | { 24 | ////////////////////////////////////////////////////////////////////////// 25 | /// @brief Functions for DdiReport. 26 | ////////////////////////////////////////////////////////////////////////// 27 | template 28 | struct DdiReport 29 | { 30 | ////////////////////////////////////////////////////////////////////////// 31 | /// @brief Generic implementation for GetData_1_0 32 | /// @param data 33 | ////////////////////////////////////////////////////////////////////////// 34 | ML_INLINE static StatusCode ML_STDCALL GetData_1_0( 35 | GetReportData_1_0* data ) 36 | { 37 | ML_FUNCTION_CHECK_STATIC( data != nullptr ); 38 | 39 | switch( data->Type ) 40 | { 41 | case ObjectType::QueryHwCounters: 42 | { 43 | auto& context = T::Queries::HwCounters::FromHandle( data->Query.Handle ).m_Context; 44 | ML_FUNCTION_LOG( StatusCode::Success, &context ); 45 | 46 | // Print input values. 47 | log.Input( *data ); 48 | 49 | log.m_Result = T::Queries::HwCounters::GetData( data->Query ); 50 | ML_ASSERT( log.m_Result == StatusCode::Success || log.m_Result == StatusCode::ReportNotReady ); 51 | 52 | return log.m_Result; 53 | } 54 | case ObjectType::OverrideUser: 55 | { 56 | auto& context = T::Overrides::User::FromHandle( data->Override.Handle ).m_Context; 57 | ML_FUNCTION_LOG( StatusCode::Success, &context ); 58 | 59 | // Print input values. 60 | log.Input( *data ); 61 | 62 | log.m_Result = T::Overrides::User::GetData( data->Override ); 63 | ML_ASSERT( log.m_Result == StatusCode::Success || log.m_Result == StatusCode::ReportNotReady ); 64 | 65 | return log.m_Result; 66 | } 67 | case ObjectType::OverridePoshQuery: 68 | { 69 | auto& context = T::Overrides::PoshQuery::FromHandle( data->Override.Handle ).m_Context; 70 | ML_FUNCTION_LOG( StatusCode::Success, &context ); 71 | 72 | // Print input values. 73 | log.Input( *data ); 74 | 75 | log.m_Result = T::Overrides::PoshQuery::GetData( data->Override ); 76 | ML_ASSERT( log.m_Result == StatusCode::Success || log.m_Result == StatusCode::ReportNotReady ); 77 | 78 | return log.m_Result; 79 | } 80 | default: 81 | { 82 | ML_FUNCTION_LOG_STATIC( StatusCode::IncorrectObject ); 83 | ML_ASSERT_ALWAYS(); 84 | 85 | // Print input values. 86 | log.Input( *data ); 87 | 88 | return log.m_Result; 89 | } 90 | } 91 | } 92 | }; 93 | } // namespace ML 94 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/library/inc/linux/external/drm/DrmSource.txt: -------------------------------------------------------------------------------- 1 | https://github.com/intel-gpu/drm-uapi-helper/tree/master/drm-uapi 2 | 3 | Base commit: 4 | https://github.com/intel-gpu/drm-uapi-helper/commit/41e61198c19774a1c840c603e43a05133873d602 5 | 6 | Author: Ashutosh Dixit 7 | Date: 12 Nov 2024 23:12:41 +01:00 8 | 9 | Description: 10 | 11 | prelim v2.0-rc27 12 | * Make busyness v3 backwards compatible with v1. Busy v3 broke uABI 13 | compatibility and UMDs complained. Fix it. 14 | 15 | i915_drm_prelim.h: 16 | 17 | Signed-off-by: Ashutosh Dixit 18 | 19 | https://gitlab.freedesktop.org/mesa/drm/ 20 | xf86drm.h updated to 21 | https://gitlab.freedesktop.org/mesa/drm/-/commit/baa4b8cafca0d52189bfd6e7cda9c558a261ae71 22 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/library/inc/linux/ml_driver_store_os.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2021-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_driver_store_os.h 11 | 12 | @brief Implements ddi redirection. 13 | */ 14 | 15 | #pragma once 16 | 17 | namespace ML 18 | { 19 | ////////////////////////////////////////////////////////////////////////// 20 | /// @brief Driver store os. 21 | ////////////////////////////////////////////////////////////////////////// 22 | struct DriverStoreOs 23 | { 24 | ////////////////////////////////////////////////////////////////////////// 25 | /// @brief Returns an address of redirected ddi using function name. 26 | /// Not supported on Linux. 27 | /// @return Null pointer. 28 | ////////////////////////////////////////////////////////////////////////// 29 | ML_INLINE static void* GetRedirectedDdi( const char* ) 30 | { 31 | return nullptr; 32 | } 33 | 34 | ////////////////////////////////////////////////////////////////////////// 35 | /// @brief Free loaded library. 36 | /// Not supported on Linux. 37 | ////////////////////////////////////////////////////////////////////////// 38 | ML_INLINE static void UnloadLibrary() 39 | { 40 | } 41 | }; 42 | } // namespace ML 43 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/library/inc/linux/ml_macros_os.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_macros_os.h 11 | 12 | @brief Os specific macros. 13 | */ 14 | 15 | #pragma once 16 | 17 | ////////////////////////////////////////////////////////////////////////// 18 | /// @brief Pragma definition. 19 | ////////////////////////////////////////////////////////////////////////// 20 | #define ML_PRAGMA( x ) _Pragma( #x ) 21 | 22 | ////////////////////////////////////////////////////////////////////////// 23 | /// @brief Inline macros. 24 | ////////////////////////////////////////////////////////////////////////// 25 | #define ML_INLINE inline 26 | #define ML_FORCE_INLINE __attribute__( ( always_inline ) ) inline 27 | 28 | ////////////////////////////////////////////////////////////////////////// 29 | /// @brief Export definition. 30 | ////////////////////////////////////////////////////////////////////////// 31 | #define ML_EXPORT( RETURN_TYPE ) RETURN_TYPE __attribute__( ( visibility( "default" ) ) ) 32 | 33 | ////////////////////////////////////////////////////////////////////////// 34 | /// @brief ML_LINUX. 35 | ////////////////////////////////////////////////////////////////////////// 36 | #if defined( __linux__ ) 37 | #define ML_LINUX 1 38 | #else 39 | #define ML_LINUX 0 40 | #endif 41 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/library/inc/linux/ml_os.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_os.h 11 | 12 | @brief Os specific headers. 13 | */ 14 | 15 | #pragma once 16 | 17 | ////////////////////////////////////////////////////////////////////////// 18 | /// @brief Standard headers: 19 | ////////////////////////////////////////////////////////////////////////// 20 | #include 21 | 22 | ////////////////////////////////////////////////////////////////////////// 23 | /// @brief Linux utility: 24 | ////////////////////////////////////////////////////////////////////////// 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | ////////////////////////////////////////////////////////////////////////// 34 | /// @brief Drm utility: 35 | ////////////////////////////////////////////////////////////////////////// 36 | #define __user 37 | #include "external/drm/i915_drm.h" 38 | #include "external/drm/xe_drm.h" 39 | #include "external/drm/xf86drm.h" 40 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/library/inc/ml_configuration_macros.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_configuration_macros.h 11 | 12 | @brief Metrics Library configuration macros. 13 | */ 14 | 15 | #pragma once 16 | 17 | ////////////////////////////////////////////////////////////////////////// 18 | /// @brief Configuration macros. 19 | ////////////////////////////////////////////////////////////////////////// 20 | #if defined( _DEBUG ) 21 | #define ML_DEBUG 1 22 | #else 23 | #define ML_DEBUG 0 24 | #endif 25 | 26 | #if defined( _RELEASE_INTERNAL ) 27 | #define ML_INTERNAL 1 28 | #else 29 | #define ML_INTERNAL 0 30 | #endif 31 | 32 | #if !defined( _DEBUG ) && !defined( _RELEASE_INTERNAL ) 33 | #define ML_RELEASE 1 34 | #else 35 | #define ML_RELEASE 0 36 | #endif 37 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/library/inc/ml_export.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_export.h 11 | 12 | @brief Contains a definition of function, which allows to obtain Traits table 13 | for a given os / api / gen. 14 | */ 15 | 16 | #pragma once 17 | 18 | const ML::DdiFunctionTableBase* GetFunctionTable( const ClientType_1_0& clientType ); 19 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/library/inc/ml_library_configuration.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_library_configuration.h 11 | 12 | @brief Initializes iu. Allows to override gen or api. 13 | */ 14 | 15 | #pragma once 16 | 17 | namespace ML 18 | { 19 | ////////////////////////////////////////////////////////////////////////// 20 | /// @brief Metrics Library configuration. 21 | ////////////////////////////////////////////////////////////////////////// 22 | struct LibraryConfiguration 23 | { 24 | ////////////////////////////////////////////////////////////////////////// 25 | /// @brief Initializes log settings. 26 | ////////////////////////////////////////////////////////////////////////// 27 | ML_INLINE static void InitializeLogger() 28 | { 29 | IuLogGetSettings( nullptr ); 30 | } 31 | 32 | ////////////////////////////////////////////////////////////////////////// 33 | /// @brief Overrides api and gen settings provided by client. 34 | /// @return clientType overridden client type. 35 | ////////////////////////////////////////////////////////////////////////// 36 | ML_INLINE static void OverrideClientType( ClientType_1_0& clientType ) 37 | { 38 | GetApiOverride( clientType.Api ); 39 | GetGpuOverride( clientType.Gen ); 40 | } 41 | 42 | private: 43 | ////////////////////////////////////////////////////////////////////////// 44 | /// @brief Returns overridden client api type. 45 | /// @return overridden client api type. 46 | ////////////////////////////////////////////////////////////////////////// 47 | ML_INLINE static void GetApiOverride( ClientApi& clientApi ) 48 | { 49 | ClientApi api = ClientApi::Unknown; 50 | 51 | const bool validApiVariable = ML_SUCCESS( ToolsOsTrait::GetSystemVariable( Constants::Library::m_ApiOverride, api ) ); 52 | const bool validApi = ( api > ClientApi::Unknown && api < ClientApi::Last ); 53 | 54 | if( validApiVariable && validApi ) 55 | { 56 | clientApi = api; 57 | } 58 | } 59 | 60 | ////////////////////////////////////////////////////////////////////////// 61 | /// @brief Returns overridden gpu type. 62 | /// @return overridden gen type. 63 | ////////////////////////////////////////////////////////////////////////// 64 | ML_INLINE static void GetGpuOverride( ClientGen& clientGpu ) 65 | { 66 | ClientGen gpu = ClientGen::Unknown; 67 | 68 | const bool validGpuVariable = ML_SUCCESS( ToolsOsTrait::GetSystemVariable( Constants::Library::m_GpuOverride, gpu ) ); 69 | const bool validGpu = ( gpu > ClientGen::Unknown && gpu < ClientGen::Last ); 70 | 71 | if( validGpuVariable && validGpu ) 72 | { 73 | clientGpu = gpu; 74 | } 75 | } 76 | }; 77 | } // namespace ML 78 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/library/inc/ml_pch.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_pch.h 11 | 12 | @brief Contains precompiled headers. 13 | */ 14 | 15 | #pragma once 16 | 17 | ////////////////////////////////////////////////////////////////////////// 18 | /// @brief Metrics Library common headers. 19 | ////////////////////////////////////////////////////////////////////////// 20 | #include "ml_os.h" 21 | #include "ml_macros_os.h" 22 | 23 | ////////////////////////////////////////////////////////////////////////// 24 | /// @brief Metrics library configuration. 25 | ////////////////////////////////////////////////////////////////////////// 26 | #include "ml_configuration_macros.h" 27 | #include "ml_configuration_api.h" 28 | #include "ml_configuration_gpu.h" 29 | 30 | ////////////////////////////////////////////////////////////////////////// 31 | /// @brief Metrics library api header. 32 | ////////////////////////////////////////////////////////////////////////// 33 | #include "metrics_library_api_1_0.h" 34 | using namespace MetricsLibraryApi; 35 | 36 | ////////////////////////////////////////////////////////////////////////// 37 | /// @brief STL support. 38 | ////////////////////////////////////////////////////////////////////////// 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | 55 | ////////////////////////////////////////////////////////////////////////// 56 | /// @brief Instrumentation utilities framework headers. 57 | ////////////////////////////////////////////////////////////////////////// 58 | #include "iu_debug.h" 59 | #include "iu_std.h" 60 | 61 | ////////////////////////////////////////////////////////////////////////// 62 | /// @brief Metrics library main headers. 63 | ////////////////////////////////////////////////////////////////////////// 64 | #include "ml_macros.h" 65 | #include "ml_constants.h" 66 | #include "ml_validation.h" 67 | #include "ml_gpu_commands_include.h" 68 | #include "ml_ddi.h" 69 | #include "ml_export.h" 70 | #include "ml_object.h" 71 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/library/inc/ml_validation.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_validation.h 11 | 12 | @brief Validates conditions. 13 | */ 14 | 15 | #pragma once 16 | 17 | namespace ML::Validation 18 | { 19 | ////////////////////////////////////////////////////////////////////////// 20 | /// @brief DummyResult structure is required by gcc. Otherwise the generic 21 | /// CheckResult (below) will be compiled and the static assert will be 22 | /// triggered even if generic version was not used at all. 23 | ////////////////////////////////////////////////////////////////////////// 24 | template 25 | struct DummyResult : std::false_type 26 | { 27 | }; 28 | 29 | ////////////////////////////////////////////////////////////////////////// 30 | /// @brief Common validation for all types other than bool/StatusCode. 31 | /// @param result result to check. 32 | /// @return always fail, only bool/StatusCode conditions are supported. 33 | ////////////////////////////////////////////////////////////////////////// 34 | template 35 | ML_INLINE StatusCode CheckResult( const ResultT result ) 36 | { 37 | static_assert( DummyResult::value, "Incorrect condition type (bool/StatusCode are allowed)." ); 38 | return StatusCode::Failed; 39 | } 40 | 41 | ////////////////////////////////////////////////////////////////////////// 42 | /// @brief Validates SatutsCode type condition. 43 | /// @param status condition status. 44 | /// @return just pass input to output. 45 | ////////////////////////////////////////////////////////////////////////// 46 | template <> 47 | ML_INLINE constexpr StatusCode CheckResult( const StatusCode result ) 48 | { 49 | return result; 50 | } 51 | 52 | ////////////////////////////////////////////////////////////////////////// 53 | /// @brief Validates bool type condition. 54 | /// @param result bool type result. 55 | /// @param condition condition code. 56 | /// @return bool converted to StatusCode. 57 | ////////////////////////////////////////////////////////////////////////// 58 | template <> 59 | ML_INLINE constexpr StatusCode CheckResult( const bool result ) 60 | { 61 | return result 62 | ? StatusCode::Success 63 | : StatusCode::Failed; 64 | } 65 | } // namespace ML::Validation 66 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/traits/command_buffer/ml_gpu_registers_layouts.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_gpu_registers_layouts.h 11 | 12 | @brief Layout for gpu registers. 13 | */ 14 | 15 | // clang-format off 16 | 17 | #pragma once 18 | 19 | ML_STRUCTURE_PACK_BEGIN( 1 ); 20 | 21 | namespace ML::BASE 22 | { 23 | ////////////////////////////////////////////////////////////////////////// 24 | /// @brief Base type for GpuRegistersLayoutsTrait object. 25 | ////////////////////////////////////////////////////////////////////////// 26 | template 27 | struct GpuRegistersLayoutsTrait 28 | { 29 | ML_DELETE_DEFAULT_CONSTRUCTOR( GpuRegistersLayoutsTrait ); 30 | ML_DELETE_DEFAULT_COPY_AND_MOVE( GpuRegistersLayoutsTrait ); 31 | 32 | ////////////////////////////////////////////////////////////////////////// 33 | /// @brief Oa report trigger. 34 | ////////////////////////////////////////////////////////////////////////// 35 | struct OaReportTrigger 36 | { 37 | union 38 | { 39 | uint32_t m_Value; 40 | 41 | struct 42 | { 43 | uint32_t m_Reserved1 : ML_BITFIELD_RANGE( 0, 20 ); 44 | uint32_t m_InvertCEnable1 : ML_BITFIELD_BIT ( 21 ); 45 | uint32_t m_InvertDEnable0 : ML_BITFIELD_BIT ( 22 ); 46 | uint32_t m_Reserved2 : ML_BITFIELD_RANGE( 23, 30 ); 47 | uint32_t m_ReportTriggerEnable : ML_BITFIELD_BIT ( 31 ); 48 | }; 49 | }; 50 | 51 | OaReportTrigger( const bool fallingEdge ) 52 | : m_Reserved1( 0 ) 53 | , m_InvertCEnable1( true ) 54 | , m_InvertDEnable0( fallingEdge ) 55 | , m_Reserved2( 0 ) 56 | , m_ReportTriggerEnable( true ) 57 | { 58 | } 59 | }; 60 | }; 61 | } // namespace ML::BASE 62 | 63 | namespace ML::GEN9 64 | { 65 | template 66 | struct GpuRegistersLayoutsTrait : BASE::GpuRegistersLayoutsTrait 67 | { 68 | ML_DECLARE_TRAIT( GpuRegistersLayoutsTrait, BASE ); 69 | }; 70 | } // namespace ML::GEN9 71 | 72 | namespace ML::GEN11 73 | { 74 | template 75 | struct GpuRegistersLayoutsTrait : GEN9::GpuRegistersLayoutsTrait 76 | { 77 | ML_DECLARE_TRAIT( GpuRegistersLayoutsTrait, GEN9 ); 78 | }; 79 | } // namespace ML::GEN11 80 | 81 | namespace ML::XE_LP 82 | { 83 | template 84 | struct GpuRegistersLayoutsTrait : GEN11::GpuRegistersLayoutsTrait 85 | { 86 | ML_DECLARE_TRAIT( GpuRegistersLayoutsTrait, GEN11 ); 87 | }; 88 | } // namespace ML::XE_LP 89 | 90 | namespace ML::XE_HPG 91 | { 92 | template 93 | struct GpuRegistersLayoutsTrait : XE_LP::GpuRegistersLayoutsTrait 94 | { 95 | ML_DECLARE_TRAIT( GpuRegistersLayoutsTrait, XE_LP ); 96 | }; 97 | } // namespace ML::XE_HPG 98 | 99 | namespace ML::XE_HPC 100 | { 101 | template 102 | struct GpuRegistersLayoutsTrait : XE_HPG::GpuRegistersLayoutsTrait 103 | { 104 | ML_DECLARE_TRAIT( GpuRegistersLayoutsTrait, XE_HPG ); 105 | }; 106 | } // namespace ML::XE_HPC 107 | 108 | namespace ML::XE2_HPG 109 | { 110 | template 111 | struct GpuRegistersLayoutsTrait : XE_HPG::GpuRegistersLayoutsTrait 112 | { 113 | ML_DECLARE_TRAIT( GpuRegistersLayoutsTrait, XE_HPG ); 114 | }; 115 | } // namespace ML::XE2_HPG 116 | 117 | namespace ML::XE3 118 | { 119 | template 120 | struct GpuRegistersLayoutsTrait : XE2_HPG::GpuRegistersLayoutsTrait 121 | { 122 | ML_DECLARE_TRAIT( GpuRegistersLayoutsTrait, XE2_HPG ); 123 | }; 124 | } // namespace ML::XE3 125 | 126 | ML_STRUCTURE_PACK_END(); 127 | 128 | // clang-format on 129 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/traits/configuration/linux/ml_configuration_hw_counters_oa.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_configuration_hw_counters_oa.h 11 | 12 | @brief Creates, activates and deactivates oa configuration. 13 | */ 14 | 15 | #pragma once 16 | 17 | namespace ML 18 | { 19 | ////////////////////////////////////////////////////////////////////////// 20 | /// @brief Base type for ConfigurationHwCountersOaTrait object. 21 | ////////////////////////////////////////////////////////////////////////// 22 | template 23 | struct ConfigurationHwCountersOaTrait : DdiObject 24 | { 25 | ML_DELETE_DEFAULT_CONSTRUCTOR( ConfigurationHwCountersOaTrait ); 26 | ML_DELETE_DEFAULT_COPY_AND_MOVE( ConfigurationHwCountersOaTrait ); 27 | 28 | ////////////////////////////////////////////////////////////////////////// 29 | /// @brief Types. 30 | ////////////////////////////////////////////////////////////////////////// 31 | using Base = DdiObject; 32 | using Base::Allocate; 33 | using Base::Delete; 34 | using Base::m_Context; 35 | 36 | ////////////////////////////////////////////////////////////////////////// 37 | /// @brief Base type for HwCounters configuration manager object. 38 | ////////////////////////////////////////////////////////////////////////// 39 | struct ConfigurationManager 40 | { 41 | ////////////////////////////////////////////////////////////////////////// 42 | /// @brief Members. 43 | ////////////////////////////////////////////////////////////////////////// 44 | int32_t m_OaConfigurationReferenceCounter; 45 | 46 | ////////////////////////////////////////////////////////////////////////// 47 | /// @brief ConfigurationManager constructor. 48 | ////////////////////////////////////////////////////////////////////////// 49 | ConfigurationManager() 50 | : m_OaConfigurationReferenceCounter( 0 ) 51 | { 52 | } 53 | }; 54 | 55 | ////////////////////////////////////////////////////////////////////////// 56 | /// @brief Members. 57 | ////////////////////////////////////////////////////////////////////////// 58 | TT::KernelInterface& m_Kernel; 59 | int64_t m_Id; 60 | 61 | ////////////////////////////////////////////////////////////////////////// 62 | /// @brief Configuration hw counters oa constructor. 63 | /// @param context library context. 64 | ////////////////////////////////////////////////////////////////////////// 65 | ConfigurationHwCountersOaTrait( TT::Context& context ) 66 | : Base( context ) 67 | , m_Kernel{ context.m_Kernel } 68 | , m_Id( T::ConstantsOs::Tbs::m_Invalid ) 69 | { 70 | } 71 | 72 | ////////////////////////////////////////////////////////////////////////// 73 | /// @brief Creates oa configuration. 74 | /// @param context library context. 75 | /// @return handle configuration handle. 76 | /// @return operation status. 77 | ////////////////////////////////////////////////////////////////////////// 78 | ML_INLINE static StatusCode Create( 79 | TT::Context& context, 80 | ConfigurationHandle_1_0& handle ) 81 | { 82 | auto configuration = Allocate( context ); 83 | const bool valid = configuration && ML_SUCCESS( configuration->Initialize() ); 84 | 85 | if( valid ) 86 | { 87 | handle = configuration->GetHandle(); 88 | } 89 | else 90 | { 91 | Delete( configuration ); 92 | } 93 | 94 | return valid 95 | ? StatusCode::Success 96 | : StatusCode::Failed; 97 | } 98 | 99 | ////////////////////////////////////////////////////////////////////////// 100 | /// @brief Activates oa configuration. 101 | /// @param activateData oa counter activate data. 102 | /// @return operation status. 103 | ////////////////////////////////////////////////////////////////////////// 104 | ML_INLINE StatusCode Activate( const ConfigurationActivateData_1_0& activateData ) const 105 | { 106 | ML_FUNCTION_LOG( StatusCode::Success, &m_Context ); 107 | ML_FUNCTION_CHECK( activateData.Type == GpuConfigurationActivationType::Tbs ); 108 | 109 | auto& oaBuffer = m_Kernel.m_Tbs.GetOaBufferMapped( T::Layouts::OaBuffer::Type::Oa ); 110 | constexpr bool restartTbs = T::Policy::ConfigurationOa::Activate::m_RestartTbs; 111 | 112 | m_Kernel.m_ConfigurationManager.m_OaConfigurationReferenceCounter++; 113 | 114 | return log.m_Result = ( restartTbs && !oaBuffer.m_Mapped ) 115 | ? m_Kernel.m_Tbs.m_Stream.Restart() 116 | : m_Kernel.LoadOaConfigurationToGpu( m_Id ); 117 | } 118 | 119 | ////////////////////////////////////////////////////////////////////////// 120 | /// @brief Deactivates oa configuration. 121 | /// If oa metric set is in use, reference counter will be decreased. 122 | /// if reference counter will become zero, another metric set will be 123 | /// allowed to be used. 124 | /// @return operation status. 125 | ////////////////////////////////////////////////////////////////////////// 126 | ML_INLINE StatusCode Deactivate() const 127 | { 128 | ML_FUNCTION_LOG( StatusCode::Success, &m_Context ); 129 | 130 | m_Kernel.m_ConfigurationManager.m_OaConfigurationReferenceCounter--; 131 | 132 | return log.m_Result = T::Policy::ConfigurationOa::Activate::m_RestartTbs 133 | ? StatusCode::Success 134 | : m_Kernel.UnloadOaConfigurationFromGpu( m_Id ); 135 | } 136 | 137 | private: 138 | ////////////////////////////////////////////////////////////////////////// 139 | /// @brief Initializes activated oa configuration. 140 | /// @return operation status. 141 | ////////////////////////////////////////////////////////////////////////// 142 | ML_INLINE StatusCode Initialize() 143 | { 144 | return m_Kernel.GetOaConfiguration( m_Id ); 145 | } 146 | 147 | ////////////////////////////////////////////////////////////////////////// 148 | /// @brief Calls flush command buffer callback. 149 | /// @return operation status. 150 | ////////////////////////////////////////////////////////////////////////// 151 | ML_INLINE StatusCode FlushCommandBuffer() const 152 | { 153 | if constexpr( T::Policy::QueryHwCounters::Begin::m_FlushCommandBuffer ) 154 | { 155 | if( const auto callback = m_Context.m_ClientCallbacks.CommandBufferFlush; 156 | callback != nullptr ) 157 | { 158 | return callback( m_Context.m_ClientHandle ); 159 | } 160 | } 161 | 162 | return StatusCode::Success; 163 | } 164 | }; 165 | } // namespace ML 166 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/traits/configuration/ml_configuration_hw_counters_user.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_configuration_hw_counters_user.h 11 | 12 | @brief Creates mmio user configuration. 13 | */ 14 | 15 | #pragma once 16 | 17 | namespace ML 18 | { 19 | ////////////////////////////////////////////////////////////////////////// 20 | /// @brief Base type for ConfigurationHwCountersUserTrait object. 21 | ////////////////////////////////////////////////////////////////////////// 22 | template 23 | struct ConfigurationHwCountersUserTrait : DdiObject 24 | { 25 | ML_DELETE_DEFAULT_CONSTRUCTOR( ConfigurationHwCountersUserTrait ); 26 | ML_DELETE_DEFAULT_COPY_AND_MOVE( ConfigurationHwCountersUserTrait ); 27 | 28 | ////////////////////////////////////////////////////////////////////////// 29 | /// @brief Types. 30 | ////////////////////////////////////////////////////////////////////////// 31 | using Base = DdiObject; 32 | using Base::Allocate; 33 | using Base::Delete; 34 | 35 | ////////////////////////////////////////////////////////////////////////// 36 | /// @brief Members. 37 | ////////////////////////////////////////////////////////////////////////// 38 | const TT::KernelInterface& m_Kernel; 39 | TT::Layouts::Configuration::UserRegisters m_UserRegisters; 40 | 41 | ////////////////////////////////////////////////////////////////////////// 42 | /// @brief Configuration hw counters mmio user constructor. 43 | /// @param context library context. 44 | ////////////////////////////////////////////////////////////////////////// 45 | ConfigurationHwCountersUserTrait( TT::Context& context ) 46 | : Base( context ) 47 | , m_Kernel( context.m_Kernel ) 48 | , m_UserRegisters{} 49 | { 50 | } 51 | 52 | ////////////////////////////////////////////////////////////////////////// 53 | /// @brief Creates mmio user configuration. 54 | /// @param context library context. 55 | /// @return handle configuration handle. 56 | /// @return operation status. 57 | ////////////////////////////////////////////////////////////////////////// 58 | ML_INLINE static StatusCode Create( 59 | TT::Context& context, 60 | ConfigurationHandle_1_0& handle ) 61 | { 62 | auto configuration = Allocate( context ); 63 | const bool valid = configuration && ML_SUCCESS( configuration->Initialize() ); 64 | 65 | if( valid ) 66 | { 67 | handle = configuration->GetHandle(); 68 | } 69 | else 70 | { 71 | Delete( configuration ); 72 | } 73 | 74 | return valid 75 | ? StatusCode::Success 76 | : StatusCode::Failed; 77 | } 78 | 79 | private: 80 | ////////////////////////////////////////////////////////////////////////// 81 | /// @brief Initializes mmio user configuration. 82 | /// @return operation status. 83 | ////////////////////////////////////////////////////////////////////////// 84 | ML_INLINE StatusCode Initialize() 85 | { 86 | return m_Kernel.GetUserConfiguration( m_UserRegisters ); 87 | } 88 | }; 89 | } // namespace ML 90 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/traits/configuration/ml_configuration_layouts.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_configuration_layouts.h 11 | 12 | @brief Layout for gpu configuration. 13 | */ 14 | 15 | #pragma once 16 | 17 | namespace ML 18 | { 19 | ////////////////////////////////////////////////////////////////////////// 20 | /// @brief Base type for ConfigurationLayoutsTrait object. 21 | ////////////////////////////////////////////////////////////////////////// 22 | template 23 | struct ConfigurationLayoutsTrait 24 | { 25 | ML_DELETE_DEFAULT_CONSTRUCTOR( ConfigurationLayoutsTrait ); 26 | ML_DELETE_DEFAULT_COPY_AND_MOVE( ConfigurationLayoutsTrait ); 27 | ML_STRUCTURE_PACK_BEGIN( 4 ); 28 | 29 | ////////////////////////////////////////////////////////////////////////// 30 | /// @brief Timestamp type. 31 | ////////////////////////////////////////////////////////////////////////// 32 | enum class TimestampType : uint32_t 33 | { 34 | Oa = ML_BIT( 0 ), 35 | Cs = ML_BIT( 1 ) 36 | }; 37 | 38 | ////////////////////////////////////////////////////////////////////////// 39 | /// @brief Base type for Register object. 40 | ////////////////////////////////////////////////////////////////////////// 41 | struct Register 42 | { 43 | uint32_t m_Offset; 44 | 45 | union 46 | { 47 | uint32_t m_Value32; 48 | uint64_t m_Value64; 49 | }; 50 | 51 | uint32_t m_Size; 52 | uint32_t m_Flags; 53 | }; 54 | 55 | ////////////////////////////////////////////////////////////////////////// 56 | /// @brief Base type for UserRegisters object. 57 | ////////////////////////////////////////////////////////////////////////// 58 | struct UserRegisters 59 | { 60 | uint32_t m_Handle; // range(0x100-...) - for dynamic configurations id is incremented by each change. 61 | // range(1-0x10) - for static configurations id is constant INSTR_PM_REGS_CFG_INVALID. 62 | Register m_Registers[Constants::Configuration::m_MaxUserRegisters]; // 63 | uint32_t m_RegistersCount; 64 | uint32_t m_StoreRegisterMemoryCount; 65 | }; 66 | 67 | ////////////////////////////////////////////////////////////////////////// 68 | /// @brief Base type for OaRegisters object. 69 | ////////////////////////////////////////////////////////////////////////// 70 | struct OaRegisters 71 | { 72 | uint32_t m_Handle; // range(0x100-...) - for dynamic configurations id is incremented by each change. 73 | // range(1-0x10) - for static configurations id is constant INSTR_PM_REGS_CFG_INVALID. 74 | Register m_Registers[Constants::Configuration::m_MaxRegisters]; // 75 | uint32_t m_RegistersCount; 76 | uint32_t m_PendingRegistersCount; 77 | }; 78 | 79 | ////////////////////////////////////////////////////////////////////////// 80 | /// @brief Base type for GpRegisters object. 81 | ////////////////////////////////////////////////////////////////////////// 82 | struct GpRegisters 83 | { 84 | uint32_t m_Handle; // range(0x100-...) - for dynamic configurations id is incremented by each change. 85 | // range(1-0x10) - for static configurations id is constant INSTR_PM_REGS_CFG_INVALID. 86 | Register m_Registers[Constants::Configuration::m_MaxRegisters]; // 87 | uint32_t m_RegistersCount; 88 | uint32_t m_PendingRegistersCount; 89 | }; 90 | 91 | ////////////////////////////////////////////////////////////////////////// 92 | /// @brief Base type for OverrideRegisters object. 93 | ////////////////////////////////////////////////////////////////////////// 94 | struct OverrideRegisters 95 | { 96 | uint32_t m_Handle; // INSTR_PM_REGS_CFG_INVALID or any positive number. 97 | 98 | struct 99 | { 100 | Register m_Registers[Constants::Configuration::m_MaxOverrideRegisters]; 101 | uint32_t m_RegistersCount; 102 | } m_Enable; 103 | 104 | struct 105 | { 106 | Register m_Registers[Constants::Configuration::m_MaxOverrideRegisters]; 107 | uint32_t m_RegistersCount; 108 | } m_Disable; 109 | }; 110 | 111 | ////////////////////////////////////////////////////////////////////////// 112 | /// @brief Base type for RegisterSettings object. 113 | ////////////////////////////////////////////////////////////////////////// 114 | struct RegisterSettings 115 | { 116 | uint32_t m_Offset; // Read-only. 117 | uint32_t m_EnableValue; // Read-only. 118 | uint32_t m_DisableValue; // Read-only. 119 | bool m_UpperHalfIsMask; // Read-only. 120 | uint32_t m_WriteMask; // Read-only. 121 | uint32_t m_InitialValue; // Read-write - used to revert back original CG settings. 122 | }; 123 | 124 | ////////////////////////////////////////////////////////////////////////// 125 | /// @brief Base type for Initialize object. 126 | ////////////////////////////////////////////////////////////////////////// 127 | struct InitializeRegisters 128 | { 129 | uint32_t m_Pending; 130 | uint32_t m_Count; 131 | RegisterSettings m_Registers[Constants::Configuration::m_MaxInitRegisters]; 132 | }; 133 | 134 | ////////////////////////////////////////////////////////////////////////// 135 | /// @brief Base type for PerformanceMonitoringRegisters object. 136 | ////////////////////////////////////////////////////////////////////////// 137 | struct PerformanceMonitoringRegisters 138 | { 139 | UserRegisters m_User; 140 | OaRegisters m_Oa; 141 | GpRegisters m_Gp; 142 | OverrideRegisters m_Overrides; 143 | union 144 | { 145 | InitializeRegisters m_Initialize; // Not used by Metrics Library, so let's use it as configuration id. 146 | int64_t m_Id; // Additional parameter calculated from oa/gp. 147 | }; // Not compatible with instrumentation, 148 | }; // but should not effect query execution since. 149 | // This is a last element within the structure. 150 | 151 | ////////////////////////////////////////////////////////////////////////// 152 | /// @brief Base type for OverridesState structure. 153 | ////////////////////////////////////////////////////////////////////////// 154 | struct OverridesState 155 | { 156 | uint32_t m_Global[T::Layouts::Override::Type::Last]; 157 | uint32_t m_Query[T::Layouts::Override::Type::Last]; 158 | }; 159 | 160 | ML_STRUCTURE_PACK_END(); 161 | }; 162 | } // namespace ML 163 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/traits/constants/linux/ml_constants_os.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_constants_os.h 11 | 12 | @brief Os specific constants. 13 | */ 14 | 15 | #pragma once 16 | 17 | namespace ML 18 | { 19 | ////////////////////////////////////////////////////////////////////////// 20 | /// @brief Os based constants. 21 | ////////////////////////////////////////////////////////////////////////// 22 | template 23 | struct ConstantsOsTrait : public Constants 24 | { 25 | ML_DELETE_DEFAULT_CONSTRUCTOR( ConstantsOsTrait ); 26 | ML_DELETE_DEFAULT_COPY_AND_MOVE( ConstantsOsTrait ); 27 | 28 | ////////////////////////////////////////////////////////////////////////// 29 | /// @brief Time based sampling constants. 30 | ////////////////////////////////////////////////////////////////////////// 31 | struct Tbs 32 | { 33 | static constexpr bool m_MappingRequired = false; 34 | static constexpr uint32_t m_CacheCapacity = 100; 35 | static constexpr uint32_t m_TimerPeriod = 0xFFFFFFFF; 36 | static constexpr int64_t m_Invalid = -1; 37 | static constexpr const char* m_ActiveMetricSetPath = "/sys/class/drm/card%d/metrics/%s/id"; 38 | static constexpr const char* m_ActiveMetricSetGuid = "2f01b241-7014-42a7-9eb6-a925cad3daba"; 39 | }; 40 | 41 | ////////////////////////////////////////////////////////////////////////// 42 | /// @brief Direct rendering manager constants. 43 | ////////////////////////////////////////////////////////////////////////// 44 | struct Drm 45 | { 46 | //////////////////////////////////////////////////////////////////////// 47 | /// @brief Drm revision. 48 | ////////////////////////////////////////////////////////////////////////// 49 | enum class Revision : uint32_t 50 | { 51 | Unsupported = 0, 52 | OaSupported = 1, 53 | OaConfiguration = 2, 54 | HoldPreemption = 3, 55 | AllowedSsEu = 4, 56 | PollOaPeriod = 5, 57 | TriggerReports = 6, 58 | TriggerWhitelist = 7, 59 | OaBufferMapping = 8, 60 | SubDevices = 10 61 | }; 62 | 63 | static constexpr int32_t m_Invalid = -1; 64 | static constexpr const char* m_Path = "/sys/dev/char/%d:%d/device/drm"; 65 | }; 66 | }; 67 | } // namespace ML 68 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/traits/constants/ml_constants.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_constants.h 11 | 12 | @brief Constants. 13 | */ 14 | 15 | #pragma once 16 | 17 | namespace ML 18 | { 19 | ////////////////////////////////////////////////////////////////////////// 20 | /// @brief Constants object. 21 | ////////////////////////////////////////////////////////////////////////// 22 | struct Constants 23 | { 24 | ML_DELETE_DEFAULT_CONSTRUCTOR( Constants ); 25 | ML_DELETE_DEFAULT_COPY_AND_MOVE( Constants ); 26 | 27 | ////////////////////////////////////////////////////////////////////////// 28 | /// @brief String constants. 29 | ////////////////////////////////////////////////////////////////////////// 30 | struct String 31 | { 32 | static constexpr uint32_t m_MaxLength = 1024; 33 | static constexpr uint32_t m_MaxPath = 260; 34 | using Buffer = char[m_MaxLength]; 35 | using Path = char[m_MaxPath]; 36 | using WideBuffer = wchar_t[m_MaxLength]; 37 | using WidePath = wchar_t[m_MaxPath]; 38 | }; 39 | 40 | ////////////////////////////////////////////////////////////////////////// 41 | /// @brief Time units constants. 42 | ////////////////////////////////////////////////////////////////////////// 43 | struct Time 44 | { 45 | static constexpr uint32_t m_Megahertz = 1000000; 46 | static constexpr uint64_t m_SecondInNanoseconds = 1000000000; 47 | }; 48 | 49 | ////////////////////////////////////////////////////////////////////////// 50 | /// @brief Data sizes. 51 | ////////////////////////////////////////////////////////////////////////// 52 | struct Data 53 | { 54 | static constexpr uint32_t m_Byte = 8; 55 | static constexpr uint64_t m_Megabyte = 1048576; 56 | }; 57 | 58 | ////////////////////////////////////////////////////////////////////////// 59 | /// @brief Combo timestamps constants. 60 | ////////////////////////////////////////////////////////////////////////// 61 | struct ComboTimestamp 62 | { 63 | static constexpr uint32_t m_CpuShift = 32u; 64 | static constexpr uint64_t m_GpuMask56 = 0x00FFFFFFFFFFFFFFLL; // Only 56 bits are available in gpu timestamp in 64-bit counter. 65 | static constexpr uint64_t m_GpuMask32 = 0x00000000FFFFFFFFLL; // Only 32 bits are available in gpu timestamp in 32-bit counter. 66 | static constexpr uint64_t m_GpuMask29 = 0x000000001FFFFFFFLL; // We need to extend the range, thus we use also cpu timestamp to create combo value. 67 | }; 68 | 69 | ////////////////////////////////////////////////////////////////////////// 70 | /// @brief Gpu counters configuration constants. 71 | ////////////////////////////////////////////////////////////////////////// 72 | struct Configuration 73 | { 74 | static constexpr uint32_t m_InvalidHandle = 0; 75 | static constexpr uint32_t m_MaxOaProlog = 3; 76 | static constexpr uint32_t m_MaxOaEpilog = 1; 77 | static constexpr uint32_t m_MaxRegistersBase = 4096; 78 | static constexpr uint32_t m_MaxRegisters = m_MaxRegistersBase + m_MaxOaEpilog + m_MaxOaProlog; 79 | static constexpr uint32_t m_MaxOverrideRegisters = 256; 80 | static constexpr uint32_t m_MaxUserRegisters = 16; 81 | static constexpr uint32_t m_MaxInitRegisters = 20; 82 | }; 83 | 84 | ////////////////////////////////////////////////////////////////////////// 85 | /// @brief Oa buffer constants. 86 | ////////////////////////////////////////////////////////////////////////// 87 | struct OaBuffer 88 | { 89 | static constexpr uint32_t m_InvalidOffset = 0xFFFFFFFF; 90 | }; 91 | 92 | ////////////////////////////////////////////////////////////////////////// 93 | /// @brief Stream marker constants. 94 | ////////////////////////////////////////////////////////////////////////// 95 | struct StreamMarker 96 | { 97 | static constexpr uint32_t m_HighBitsShift = 25; 98 | }; 99 | 100 | ////////////////////////////////////////////////////////////////////////// 101 | /// @brief Query constants. 102 | ////////////////////////////////////////////////////////////////////////// 103 | struct Query 104 | { 105 | static constexpr uint32_t m_DummyContextId = 0xFFFFFFFF; 106 | }; 107 | 108 | ////////////////////////////////////////////////////////////////////////// 109 | /// @brief Log constants. 110 | ////////////////////////////////////////////////////////////////////////// 111 | struct Log 112 | { 113 | static constexpr const char m_ScopeCharacter = ':'; 114 | static constexpr const char* m_EnteredFunctionTag = "Enter:"; 115 | static constexpr const char* m_ExitingFunctionTag = "Exit :"; 116 | static constexpr uint32_t m_IndentSize = 4; 117 | static constexpr bool m_SimplifyFunctionName = false; 118 | static constexpr uint32_t m_SimplifyFunctionNameLevel = 0; 119 | static constexpr uint32_t m_MaxFunctionNameLength = 25; 120 | static constexpr uint32_t m_MaxReportReasonLength = 2; // 64. 121 | static constexpr uint32_t m_MaxReportIdLength = 4; // 4096. 122 | static constexpr uint32_t m_MaxUint32Length = 10; // 4294967295. 123 | static constexpr uint32_t m_MaxUint64Length = 20; // 18446744073709551615. 124 | static constexpr uint32_t m_MaxLength = 4096; 125 | static constexpr uint32_t m_MaxIndent = 10; 126 | static constexpr uint32_t m_MaxMessageLength = m_IndentSize * m_MaxIndent + 50; 127 | static constexpr bool m_ShowDecimal = true; 128 | static constexpr bool m_ShowHexadecimal = true; 129 | static constexpr bool m_FilterEnabled = false; 130 | static constexpr const char* m_FilteredString = ""; 131 | static constexpr uint32_t m_FilteredLines = 0; 132 | static constexpr bool m_FlushEachLog = true; 133 | }; 134 | 135 | ////////////////////////////////////////////////////////////////////////// 136 | /// @brief Library constants. 137 | ////////////////////////////////////////////////////////////////////////// 138 | struct Library 139 | { 140 | static constexpr const char* m_Name = "MetricsLibrary"; 141 | static constexpr const char* m_GpuOverride = "Gpu"; 142 | static constexpr const char* m_ApiOverride = "Api"; 143 | }; 144 | 145 | ////////////////////////////////////////////////////////////////////////// 146 | /// @brief Object constants. 147 | ////////////////////////////////////////////////////////////////////////// 148 | struct Object 149 | { 150 | static constexpr uint32_t m_MagicHeader = 0xF1E2D3C4; 151 | }; 152 | }; 153 | } // namespace ML 154 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/traits/context/ml_client_options.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_client_options.h 11 | 12 | @brief Stores all client's options that have been passed to the library by them. 13 | */ 14 | 15 | #pragma once 16 | 17 | namespace ML 18 | { 19 | ////////////////////////////////////////////////////////////////////////// 20 | /// @brief Base type for ClientOptionsTrait object. 21 | ////////////////////////////////////////////////////////////////////////// 22 | template 23 | struct ClientOptionsTrait 24 | { 25 | ML_DELETE_DEFAULT_CONSTRUCTOR( ClientOptionsTrait ); 26 | ML_DELETE_DEFAULT_COPY_AND_MOVE( ClientOptionsTrait ); 27 | 28 | ////////////////////////////////////////////////////////////////////////// 29 | /// @brief Members. 30 | ////////////////////////////////////////////////////////////////////////// 31 | bool m_PoshEnabled; 32 | bool m_PtbrEnabled; 33 | bool m_TbsEnabled; 34 | bool m_AsynchronousCompute; 35 | bool m_WorkloadPartitionEnabled; 36 | bool m_IsSubDevice; 37 | bool m_SubDeviceDataPresent; 38 | uint32_t m_SubDeviceCount; 39 | uint32_t m_SubDeviceIndex; 40 | 41 | ////////////////////////////////////////////////////////////////////////// 42 | /// @brief ClientOptionsTrait constructor. 43 | /// @param clientData client's data. 44 | /// @param context context. 45 | ////////////////////////////////////////////////////////////////////////// 46 | ClientOptionsTrait( const ClientData_1_0& clientData, TT::Context& context ) 47 | : m_PoshEnabled( false ) 48 | , m_PtbrEnabled( false ) 49 | , m_TbsEnabled( false ) 50 | , m_AsynchronousCompute( false ) 51 | , m_WorkloadPartitionEnabled( false ) 52 | , m_IsSubDevice( false ) 53 | , m_SubDeviceDataPresent( false ) 54 | , m_SubDeviceCount( 0 ) 55 | , m_SubDeviceIndex( 0 ) 56 | { 57 | ML_FUNCTION_LOG( StatusCode::Success, &context ); 58 | 59 | // Copy client's options from the pointer provided by the user. 60 | if( clientData.ClientOptions != nullptr ) 61 | { 62 | for( uint32_t i = 0; i < clientData.ClientOptionsCount; ++i ) 63 | { 64 | switch( const auto& options = clientData.ClientOptions[i]; 65 | options.Type ) 66 | { 67 | case ClientOptionsType::Posh: 68 | m_PoshEnabled = options.Posh.Enabled; 69 | log.Info( "Posh enabled", m_PoshEnabled ); 70 | break; 71 | 72 | case ClientOptionsType::Ptbr: 73 | m_PtbrEnabled = options.Ptbr.Enabled; 74 | log.Info( "Ptbr enabled", m_PtbrEnabled ); 75 | break; 76 | 77 | case ClientOptionsType::Compute: 78 | m_AsynchronousCompute = options.Compute.Asynchronous; 79 | log.Info( "Asynchronous compute", m_AsynchronousCompute ); 80 | break; 81 | 82 | case ClientOptionsType::Tbs: 83 | m_TbsEnabled = options.Tbs.Enabled; 84 | log.Info( "Tbs enabled", m_TbsEnabled ); 85 | break; 86 | 87 | case ClientOptionsType::SubDevice: 88 | m_IsSubDevice = options.SubDevice.Enabled; 89 | m_SubDeviceDataPresent = true; 90 | log.Info( "Subdevice enabled", m_IsSubDevice ); 91 | break; 92 | 93 | case ClientOptionsType::SubDeviceIndex: 94 | m_SubDeviceIndex = options.SubDeviceIndex.Index; 95 | log.Info( "Subdevice index", m_SubDeviceIndex ); 96 | break; 97 | 98 | case ClientOptionsType::SubDeviceCount: 99 | m_SubDeviceCount = options.SubDeviceCount.Count; 100 | log.Info( "Subdevice count", m_SubDeviceCount ); 101 | break; 102 | 103 | case ClientOptionsType::WorkloadPartition: 104 | m_WorkloadPartitionEnabled = options.WorkloadPartition.Enabled; 105 | log.Info( "Workload partition enabled", m_WorkloadPartitionEnabled ); 106 | break; 107 | 108 | default: 109 | log.Warning( "Unknown client option", clientData.ClientOptions[i].Type ); 110 | break; 111 | } 112 | } 113 | } 114 | } 115 | }; 116 | } // namespace ML 117 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/traits/context/ml_context.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_context.h 11 | 12 | @brief Creates metrics library context, which is the main object of the library 13 | and contains all created objects in the library. Initializes kernel 14 | interface and oa buffer. 15 | */ 16 | 17 | #pragma once 18 | 19 | namespace ML 20 | { 21 | ////////////////////////////////////////////////////////////////////////// 22 | /// @brief Base type for ContextTrait object. 23 | ////////////////////////////////////////////////////////////////////////// 24 | template 25 | struct ContextTrait : DdiObject 26 | { 27 | ML_DELETE_DEFAULT_CONSTRUCTOR( ContextTrait ); 28 | ML_DELETE_DEFAULT_COPY_AND_MOVE( ContextTrait ); 29 | 30 | ////////////////////////////////////////////////////////////////////////// 31 | /// @brief Types. 32 | ////////////////////////////////////////////////////////////////////////// 33 | using Base = DdiObject; 34 | using Base::Allocate; 35 | using Base::Delete; 36 | using Base::GetHandle; 37 | 38 | ////////////////////////////////////////////////////////////////////////// 39 | /// @brief Members. 40 | ////////////////////////////////////////////////////////////////////////// 41 | uint32_t m_AdapterId; 42 | TT::Debug m_Debug; 43 | TT::KernelInterface m_Kernel; 44 | TT::OaBuffer m_OaBuffer; 45 | TT::ClientOptions m_ClientOptions; 46 | const ClientHandle_1_0 m_ClientHandle; 47 | const ClientCallbacks_1_0 m_ClientCallbacks; 48 | ClientData_1_0 m_ClientData; 49 | TT::SubDevice m_SubDevice; 50 | TT::DdiObjects m_DdiObjects; 51 | TT::State m_State; 52 | TT::InternalFeature m_Internal; 53 | 54 | ////////////////////////////////////////////////////////////////////////// 55 | /// @brief ContextTrait constructor. 56 | /// @param clientType client type. 57 | /// @param createData context create data. 58 | ////////////////////////////////////////////////////////////////////////// 59 | ContextTrait( 60 | const ClientType_1_0& clientType, 61 | const ContextCreateData_1_0& createData ) 62 | : Base( clientType, *this ) 63 | , m_AdapterId( IU_ADAPTER_ID_UNKNOWN ) 64 | , m_Debug{} 65 | , m_Kernel( *this ) 66 | , m_OaBuffer( m_Kernel ) 67 | , m_ClientOptions( *createData.ClientData, *this ) 68 | , m_ClientHandle( createData.ClientData->Handle ) 69 | , m_ClientCallbacks{ *createData.ClientCallbacks } 70 | , m_ClientData{ *createData.ClientData } 71 | , m_SubDevice( *this ) 72 | , m_DdiObjects( *this ) 73 | , m_State{} 74 | , m_Internal{} 75 | { 76 | } 77 | 78 | ////////////////////////////////////////////////////////////////////////// 79 | /// @brief ContextTrait destructor. 80 | ////////////////////////////////////////////////////////////////////////// 81 | ~ContextTrait() 82 | { 83 | // Release reference to oa buffer. 84 | m_OaBuffer.Release(); 85 | } 86 | 87 | ////////////////////////////////////////////////////////////////////////// 88 | /// @brief Creates context instance. 89 | /// @param clientType api / gen information provided by client. 90 | /// @param createData create context information. 91 | /// @return handle handle to created context instance. 92 | /// @return operation status. 93 | ////////////////////////////////////////////////////////////////////////// 94 | ML_INLINE static StatusCode Create( 95 | const ClientType_1_0& clientType, 96 | ContextCreateData_1_0& createData, 97 | ContextHandle_1_0& handle ) 98 | { 99 | ML_FUNCTION_CHECK_STATIC( createData.Api != nullptr ); 100 | ML_FUNCTION_CHECK_STATIC( createData.ClientData != nullptr ); 101 | ML_FUNCTION_CHECK_STATIC( createData.ClientCallbacks != nullptr ); 102 | 103 | auto context = Allocate( clientType, createData ); 104 | const bool validContext = context && ML_SUCCESS( context->Initialize() ); 105 | ML_FUNCTION_LOG( StatusCode::Success, validContext ? context : nullptr ); 106 | 107 | auto functionTable = GetFunctionTable( clientType ); 108 | const bool validInterface = functionTable != nullptr; 109 | 110 | // Validate context and library interface. 111 | log.m_Result = validContext && validInterface 112 | ? StatusCode::Success 113 | : StatusCode::Failed; 114 | 115 | // Return context handle and library api. 116 | if( ML_SUCCESS( log.m_Result ) ) 117 | { 118 | functionTable->GetInterface( *createData.Api ); 119 | handle = context->GetHandle(); 120 | } 121 | else 122 | { 123 | Delete( context ); 124 | } 125 | 126 | return log.m_Result; 127 | } 128 | 129 | private: 130 | ////////////////////////////////////////////////////////////////////////// 131 | /// @brief Initializes library context. 132 | /// @return operation status. 133 | ////////////////////////////////////////////////////////////////////////// 134 | ML_INLINE StatusCode Initialize() 135 | { 136 | ML_FUNCTION_LOG( StatusCode::Success, this ); 137 | 138 | ML_FUNCTION_CHECK( m_Kernel.Initialize( m_ClientData ) ); 139 | ML_FUNCTION_CHECK( m_Kernel.GetAdapterId( m_AdapterId ) ); 140 | ML_FUNCTION_CHECK( m_OaBuffer.Initialize() ); 141 | 142 | return log.m_Result; 143 | } 144 | }; 145 | } // namespace ML 146 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/traits/context/ml_state.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2021-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_state.h 11 | 12 | @brief Stores library state. 13 | */ 14 | 15 | #pragma once 16 | 17 | namespace ML 18 | { 19 | ////////////////////////////////////////////////////////////////////////// 20 | /// @brief Base type for ExampleTrait object. 21 | ////////////////////////////////////////////////////////////////////////// 22 | template 23 | struct StateTrait 24 | { 25 | ML_DELETE_DEFAULT_COPY_AND_MOVE( StateTrait ); 26 | 27 | ////////////////////////////////////////////////////////////////////////// 28 | /// @brief Query information struct. 29 | ////////////////////////////////////////////////////////////////////////// 30 | struct Query 31 | { 32 | std::atomic_uint m_ReportId; 33 | 34 | ////////////////////////////////////////////////////////////////////////// 35 | /// @brief Query information struct constructor. 36 | ////////////////////////////////////////////////////////////////////////// 37 | Query() 38 | : m_ReportId( 0 ) 39 | { 40 | } 41 | }; 42 | 43 | ////////////////////////////////////////////////////////////////////////// 44 | /// @brief Members. 45 | ////////////////////////////////////////////////////////////////////////// 46 | Query m_Query; 47 | 48 | ////////////////////////////////////////////////////////////////////////// 49 | /// @brief StateTrait constructor. 50 | ////////////////////////////////////////////////////////////////////////// 51 | StateTrait() 52 | : m_Query{} 53 | { 54 | } 55 | }; 56 | } // namespace ML 57 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/traits/device/ml_sub_device_common.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2021-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_sub_device_common.h 11 | 12 | @brief Sub device support. 13 | */ 14 | 15 | #pragma once 16 | 17 | namespace ML 18 | { 19 | ////////////////////////////////////////////////////////////////////////// 20 | /// @brief Base type for SubDeviceCommonTrait object. 21 | ////////////////////////////////////////////////////////////////////////// 22 | template 23 | struct SubDeviceCommonTrait : TraitObject 24 | { 25 | ML_DELETE_DEFAULT_CONSTRUCTOR( SubDeviceCommonTrait ); 26 | ML_DELETE_DEFAULT_COPY_AND_MOVE( SubDeviceCommonTrait ); 27 | 28 | ////////////////////////////////////////////////////////////////////////// 29 | /// @brief Types. 30 | ////////////////////////////////////////////////////////////////////////// 31 | using Base = TraitObject; 32 | 33 | ////////////////////////////////////////////////////////////////////////// 34 | /// @brief Members. 35 | ////////////////////////////////////////////////////////////////////////// 36 | TT::Context& m_Context; 37 | uint32_t m_SubDeviceIndex; 38 | uint32_t m_SubDeviceCount; 39 | bool m_IsSubDevice; 40 | bool m_Enabled; 41 | 42 | ////////////////////////////////////////////////////////////////////////// 43 | /// @brief Device constructor. 44 | /// @param context metrics library context. 45 | ////////////////////////////////////////////////////////////////////////// 46 | SubDeviceCommonTrait( TT::Context& context ) 47 | : Base() 48 | , m_Context( context ) 49 | , m_SubDeviceIndex( context.m_ClientOptions.m_SubDeviceIndex ) 50 | , m_SubDeviceCount( context.m_ClientOptions.m_SubDeviceCount ) 51 | , m_IsSubDevice( context.m_ClientOptions.m_IsSubDevice ) 52 | , m_Enabled( false ) 53 | { 54 | } 55 | 56 | ////////////////////////////////////////////////////////////////////////// 57 | /// @brief Initializes device data. 58 | /// @return operation status. 59 | ////////////////////////////////////////////////////////////////////////// 60 | ML_INLINE StatusCode Initialize() const 61 | { 62 | return StatusCode::Success; 63 | } 64 | }; 65 | } // namespace ML 66 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/traits/example/ml_example.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_example.h 11 | 12 | @brief Example file for creating a new trait. Make sure to change DdiObject 13 | template arguments and update description. 14 | */ 15 | 16 | #pragma once 17 | 18 | namespace ML 19 | { 20 | ////////////////////////////////////////////////////////////////////////// 21 | /// @brief Base type for ExampleTrait object. 22 | ////////////////////////////////////////////////////////////////////////// 23 | template 24 | struct ExampleTrait : DdiObject 25 | { 26 | ML_DELETE_DEFAULT_CONSTRUCTOR( ExampleTrait ); 27 | ML_DELETE_DEFAULT_COPY_AND_MOVE( ExampleTrait ); 28 | }; 29 | } // namespace ML 30 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/traits/example/ml_example_gpu.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2021-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_example_gpu.h 11 | 12 | @brief Example file for creating a new trait that is gpu specific. 13 | Make sure to change DdiObject template arguments and update description. 14 | */ 15 | 16 | #pragma once 17 | 18 | namespace ML::BASE 19 | { 20 | ////////////////////////////////////////////////////////////////////////// 21 | /// @brief Base type for ExampleGpuTrait object. 22 | ////////////////////////////////////////////////////////////////////////// 23 | template 24 | struct ExampleGpuTrait : DdiObject 25 | { 26 | ML_DELETE_DEFAULT_CONSTRUCTOR( ExampleGpuTrait ); 27 | ML_DELETE_DEFAULT_COPY_AND_MOVE( ExampleGpuTrait ); 28 | }; 29 | } // namespace ML::BASE 30 | 31 | namespace ML::GEN9 32 | { 33 | template 34 | struct ExampleGpuTrait : BASE::ExampleGpuTrait 35 | { 36 | ML_DECLARE_TRAIT( ExampleGpuTrait, BASE ); 37 | }; 38 | } // namespace ML::GEN9 39 | 40 | namespace ML::GEN11 41 | { 42 | template 43 | struct ExampleGpuTrait : GEN9::ExampleGpuTrait 44 | { 45 | ML_DECLARE_TRAIT( ExampleGpuTrait, GEN9 ); 46 | }; 47 | } // namespace ML::GEN11 48 | 49 | namespace ML::XE_LP 50 | { 51 | template 52 | struct ExampleGpuTrait : GEN11::ExampleGpuTrait 53 | { 54 | ML_DECLARE_TRAIT( ExampleGpuTrait, GEN11 ); 55 | }; 56 | } // namespace ML::XE_LP 57 | 58 | namespace ML::XE_HPG 59 | { 60 | template 61 | struct ExampleGpuTrait : XE_LP::ExampleGpuTrait 62 | { 63 | ML_DECLARE_TRAIT( ExampleGpuTrait, XE_LP ); 64 | }; 65 | } // namespace ML::XE_HPG 66 | 67 | namespace ML::XE_HPC 68 | { 69 | template 70 | struct ExampleGpuTrait : XE_HPG::ExampleGpuTrait 71 | { 72 | ML_DECLARE_TRAIT( ExampleGpuTrait, XE_HPG ); 73 | }; 74 | } // namespace ML::XE_HPC 75 | 76 | namespace ML::XE2_HPG 77 | { 78 | template 79 | struct ExampleGpuTrait : XE_HPG::ExampleGpuTrait 80 | { 81 | ML_DECLARE_TRAIT( ExampleGpuTrait, XE_HPG ); 82 | }; 83 | } // namespace ML::XE2_HPG 84 | 85 | namespace ML::XE3 86 | { 87 | template 88 | struct ExampleGpuTrait : XE2_HPG::ExampleGpuTrait 89 | { 90 | ML_DECLARE_TRAIT( ExampleGpuTrait, XE2_HPG ); 91 | }; 92 | } // namespace ML::XE3 93 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/traits/function_log/ml_function_log_release.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_function_log_release.h 11 | 12 | @brief Provides functions to print out logs. Allows to log a function 13 | entering and exiting with a result returned by a function. 14 | This file is included in release build type. 15 | */ 16 | 17 | #pragma once 18 | 19 | namespace ML 20 | { 21 | ////////////////////////////////////////////////////////////////////////// 22 | /// @brief A structure that logs function entered/exiting. 23 | ////////////////////////////////////////////////////////////////////////// 24 | template 25 | struct FunctionLogReleaseTrait 26 | { 27 | ML_DELETE_DEFAULT_CONSTRUCTOR( FunctionLogReleaseTrait ); 28 | ML_DELETE_DEFAULT_COPY_AND_MOVE( FunctionLogReleaseTrait ); 29 | 30 | ////////////////////////////////////////////////////////////////////////// 31 | /// @brief Members. 32 | ////////////////////////////////////////////////////////////////////////// 33 | Result m_Result; 34 | TT::Context* m_Context; 35 | 36 | ////////////////////////////////////////////////////////////////////////// 37 | /// @brief FunctionLogReleaseTrait constructor. 38 | /// @param name function name. 39 | /// @param result function initial result value. 40 | ////////////////////////////////////////////////////////////////////////// 41 | FunctionLogReleaseTrait( 42 | const char* /*name*/, 43 | const Result result, 44 | TT::Context* context ) 45 | : m_Result( result ) 46 | , m_Context( context ) 47 | { 48 | } 49 | 50 | ////////////////////////////////////////////////////////////////////////// 51 | /// @brief Logs function input parameter. 52 | /// @param values variable values to print out. 53 | ////////////////////////////////////////////////////////////////////////// 54 | template 55 | ML_INLINE void Input( const Values&... ) const 56 | { 57 | } 58 | 59 | ////////////////////////////////////////////////////////////////////////// 60 | /// @brief Logs function exit parameter. 61 | /// @param values variable values to print out. 62 | ////////////////////////////////////////////////////////////////////////// 63 | template 64 | ML_INLINE void Output( const Values&... ) const 65 | { 66 | } 67 | 68 | ////////////////////////////////////////////////////////////////////////// 69 | /// @brief Logs traits. 70 | /// @param values variable values to print out. 71 | ////////////////////////////////////////////////////////////////////////// 72 | template 73 | ML_INLINE static void Traits( const Values&... ) 74 | { 75 | } 76 | 77 | ////////////////////////////////////////////////////////////////////////// 78 | /// @brief Logs a debug message. 79 | /// @param values variable values to print out. 80 | ////////////////////////////////////////////////////////////////////////// 81 | template 82 | ML_INLINE void Debug( const Values&... ) const 83 | { 84 | } 85 | 86 | ////////////////////////////////////////////////////////////////////////// 87 | /// @brief Logs an information message. 88 | /// @param values variable values to print out. 89 | ////////////////////////////////////////////////////////////////////////// 90 | template 91 | ML_INLINE void Info( const Values&... ) const 92 | { 93 | } 94 | 95 | ////////////////////////////////////////////////////////////////////////// 96 | /// @brief Logs a warning message. 97 | /// @param values variable values to print out. 98 | ////////////////////////////////////////////////////////////////////////// 99 | template 100 | ML_INLINE void Warning( const Values&... values ) const 101 | { 102 | T::Tools::Log( LogType::Warning, "", m_Context, values... ); 103 | } 104 | 105 | ////////////////////////////////////////////////////////////////////////// 106 | /// @brief Logs an error message. 107 | /// @param values variable values to print out. 108 | ////////////////////////////////////////////////////////////////////////// 109 | template 110 | ML_INLINE void Error( const Values&... values ) const 111 | { 112 | T::Tools::Log( LogType::Error, "", m_Context, values... ); 113 | } 114 | 115 | //////////////////////////////////////////////////////////////////////// 116 | /// @brief Logs an error message. Static implementation. 117 | /// @param values variable values to print out. 118 | //////////////////////////////////////////////////////////////////////// 119 | template 120 | ML_INLINE static void ErrorStatic( const Values&... values ) 121 | { 122 | T::Tools::Log( LogType::Error, "", nullptr, values... ); 123 | } 124 | ////////////////////////////////////////////////////////////////////////// 125 | /// @brief Logs a critical error message. 126 | /// @param values variable values to print out. 127 | ////////////////////////////////////////////////////////////////////////// 128 | template 129 | ML_INLINE void Critical( const Values&... values ) const 130 | { 131 | T::Tools::Log( LogType::Critical, "", m_Context, values... ); 132 | } 133 | 134 | ////////////////////////////////////////////////////////////////////////// 135 | /// @brief Logs into a csv file. 136 | /// @param values variable values to print out. 137 | ////////////////////////////////////////////////////////////////////////// 138 | template 139 | ML_INLINE void Csv( [[maybe_unused]] const Values&... values ) const 140 | { 141 | } 142 | }; 143 | } // namespace ML 144 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/traits/internal/ml_internal_feature.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2022-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_internal_feature.h 11 | 12 | @brief A file describing a trait that's intended for internal use (for example debugging) only. 13 | */ 14 | 15 | #pragma once 16 | 17 | namespace ML::BASE 18 | { 19 | ////////////////////////////////////////////////////////////////////////// 20 | /// @brief Base type for InternalFeatureTrait object. 21 | ////////////////////////////////////////////////////////////////////////// 22 | template 23 | struct InternalFeatureTrait 24 | { 25 | ML_DELETE_DEFAULT_COPY_AND_MOVE( InternalFeatureTrait ); 26 | 27 | ////////////////////////////////////////////////////////////////////////// 28 | /// @brief InternalFeatureTrait constructor. 29 | ////////////////////////////////////////////////////////////////////////// 30 | InternalFeatureTrait() 31 | { 32 | } 33 | }; 34 | } // namespace ML::BASE 35 | 36 | namespace ML::GEN9 37 | { 38 | template 39 | struct InternalFeatureTrait : BASE::InternalFeatureTrait 40 | { 41 | ML_DECLARE_TRAIT( InternalFeatureTrait, BASE ); 42 | }; 43 | } // namespace ML::GEN9 44 | 45 | namespace ML::GEN11 46 | { 47 | template 48 | struct InternalFeatureTrait : GEN9::InternalFeatureTrait 49 | { 50 | ML_DECLARE_TRAIT( InternalFeatureTrait, GEN9 ); 51 | }; 52 | } // namespace ML::GEN11 53 | 54 | namespace ML::XE_LP 55 | { 56 | template 57 | struct InternalFeatureTrait : GEN11::InternalFeatureTrait 58 | { 59 | ML_DECLARE_TRAIT( InternalFeatureTrait, GEN11 ); 60 | }; 61 | } // namespace ML::XE_LP 62 | 63 | namespace ML::XE_HPG 64 | { 65 | template 66 | struct InternalFeatureTrait : XE_LP::InternalFeatureTrait 67 | { 68 | ML_DECLARE_TRAIT( InternalFeatureTrait, XE_LP ); 69 | }; 70 | } // namespace ML::XE_HPG 71 | 72 | namespace ML::XE_HPC 73 | { 74 | template 75 | struct InternalFeatureTrait : XE_HPG::InternalFeatureTrait 76 | { 77 | ML_DECLARE_TRAIT( InternalFeatureTrait, XE_HPG ); 78 | }; 79 | } // namespace ML::XE_HPC 80 | 81 | namespace ML::XE2_HPG 82 | { 83 | template 84 | struct InternalFeatureTrait : XE_HPG::InternalFeatureTrait 85 | { 86 | ML_DECLARE_TRAIT( InternalFeatureTrait, XE_HPG ); 87 | 88 | ////////////////////////////////////////////////////////////////////////// 89 | /// @brief Uses provided buffer to override masked pec counters with provided value. 90 | /// @param buffer command buffer. 91 | /// @param type of pec registers to override. 92 | /// @param mask 64-bit mask that dictates what counters will be overwritten 93 | /// lower bytes represent counters at lower offset. 94 | /// @param value value that will be written to the counters. 95 | ////////////////////////////////////////////////////////////////////////// 96 | template 97 | ML_INLINE static void OverridePecCounters( 98 | [[maybe_unused]] CommandBuffer& buffer, 99 | [[maybe_unused]] const TT::Layouts::HwCounters::PecType type, 100 | [[maybe_unused]] const uint64_t mask, 101 | [[maybe_unused]] const uint64_t value ) 102 | { 103 | } 104 | 105 | ////////////////////////////////////////////////////////////////////////// 106 | /// @brief Uses values in the register to override pec counters 107 | /// @param buffer command buffer. 108 | /// @param type of pec registers to override. 109 | ////////////////////////////////////////////////////////////////////////// 110 | template 111 | ML_INLINE void OverridePecCounters( 112 | [[maybe_unused]] CommandBuffer& buffer, 113 | [[maybe_unused]] const TT::Layouts::HwCounters::PecType type ) const 114 | { 115 | } 116 | }; 117 | } // namespace ML::XE2_HPG 118 | 119 | namespace ML::XE3 120 | { 121 | template 122 | struct InternalFeatureTrait : XE2_HPG::InternalFeatureTrait 123 | { 124 | ML_DECLARE_TRAIT( InternalFeatureTrait, XE2_HPG ); 125 | }; 126 | } // namespace ML::XE3 127 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/traits/kernel_interface/linux/ml_drm_layouts.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2021-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_drm_layouts.h 11 | 12 | @brief Contains drm structures and enumerations that are not available in the 13 | official drm files from official linux repository. 14 | */ 15 | 16 | #pragma once 17 | 18 | ML_STRUCTURE_PACK_BEGIN( 1 ); 19 | 20 | namespace ML::BASE 21 | { 22 | ////////////////////////////////////////////////////////////////////////// 23 | /// @brief Base type for DrmLayoutsTrait object. 24 | ////////////////////////////////////////////////////////////////////////// 25 | template 26 | struct DrmLayoutsTrait 27 | { 28 | ML_DELETE_DEFAULT_CONSTRUCTOR( DrmLayoutsTrait ); 29 | ML_DELETE_DEFAULT_COPY_AND_MOVE( DrmLayoutsTrait ); 30 | }; 31 | } // namespace ML::BASE 32 | 33 | namespace ML::GEN9 34 | { 35 | template 36 | struct DrmLayoutsTrait : BASE::DrmLayoutsTrait 37 | { 38 | ML_DECLARE_TRAIT( DrmLayoutsTrait, BASE ); 39 | 40 | ////////////////////////////////////////////////////////////////////////// 41 | /// @brief File constants. 42 | ////////////////////////////////////////////////////////////////////////// 43 | struct File 44 | { 45 | static constexpr const char* m_Name = "i915"; 46 | }; 47 | 48 | ////////////////////////////////////////////////////////////////////////// 49 | /// @brief Stream constants. 50 | ////////////////////////////////////////////////////////////////////////// 51 | struct Stream 52 | { 53 | static constexpr const char* m_ParanoidPath = "/proc/sys/dev/i915/perf_stream_paranoid"; 54 | }; 55 | }; 56 | } // namespace ML::GEN9 57 | 58 | namespace ML::GEN11 59 | { 60 | template 61 | struct DrmLayoutsTrait : GEN9::DrmLayoutsTrait 62 | { 63 | ML_DECLARE_TRAIT( DrmLayoutsTrait, GEN9 ); 64 | }; 65 | } // namespace ML::GEN11 66 | 67 | namespace ML::XE_LP 68 | { 69 | template 70 | struct DrmLayoutsTrait : GEN11::DrmLayoutsTrait 71 | { 72 | ML_DECLARE_TRAIT( DrmLayoutsTrait, GEN11 ); 73 | }; 74 | } // namespace ML::XE_LP 75 | 76 | namespace ML::XE_HPG 77 | { 78 | template 79 | struct DrmLayoutsTrait : XE_LP::DrmLayoutsTrait 80 | { 81 | ML_DECLARE_TRAIT( DrmLayoutsTrait, XE_LP ); 82 | }; 83 | } // namespace ML::XE_HPG 84 | 85 | namespace ML::XE_HPC 86 | { 87 | template 88 | struct DrmLayoutsTrait : XE_HPG::DrmLayoutsTrait 89 | { 90 | ML_DECLARE_TRAIT( DrmLayoutsTrait, XE_HPG ); 91 | }; 92 | } // namespace ML::XE_HPC 93 | 94 | namespace ML::XE2_HPG 95 | { 96 | template 97 | struct DrmLayoutsTrait : BASE::DrmLayoutsTrait 98 | { 99 | ML_DECLARE_TRAIT( DrmLayoutsTrait, BASE ); 100 | 101 | ////////////////////////////////////////////////////////////////////////// 102 | /// @brief File constants. 103 | ////////////////////////////////////////////////////////////////////////// 104 | struct File 105 | { 106 | static constexpr const char* m_Name = "xe"; 107 | }; 108 | 109 | ////////////////////////////////////////////////////////////////////////// 110 | /// @brief Stream constants. 111 | ////////////////////////////////////////////////////////////////////////// 112 | struct Stream 113 | { 114 | static constexpr const char* m_ParanoidPath = "/proc/sys/dev/xe/observation_paranoid"; 115 | }; 116 | }; 117 | } // namespace ML::XE2_HPG 118 | 119 | namespace ML::XE3 120 | { 121 | template 122 | struct DrmLayoutsTrait : XE2_HPG::DrmLayoutsTrait 123 | { 124 | ML_DECLARE_TRAIT( DrmLayoutsTrait, XE2_HPG ); 125 | }; 126 | } // namespace ML::XE3 127 | 128 | ML_STRUCTURE_PACK_END(); 129 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/traits/marker/linux/ml_marker_stream_user_extended.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_marker_stream_user_extended.h 11 | 12 | @brief Allows to create, write marker stream user extended and get data 13 | from the marker. 14 | */ 15 | 16 | #pragma once 17 | 18 | namespace ML 19 | { 20 | ////////////////////////////////////////////////////////////////////////// 21 | /// @brief Base type for MarkerStreamUserExtendedExtendedTrait object. 22 | ////////////////////////////////////////////////////////////////////////// 23 | template 24 | struct MarkerStreamUserExtendedTrait : DdiObject 25 | { 26 | ML_DELETE_DEFAULT_CONSTRUCTOR( MarkerStreamUserExtendedTrait ); 27 | ML_DELETE_DEFAULT_COPY_AND_MOVE( MarkerStreamUserExtendedTrait ); 28 | 29 | ////////////////////////////////////////////////////////////////////////// 30 | /// @brief Types. 31 | ////////////////////////////////////////////////////////////////////////// 32 | using Base = DdiObject; 33 | 34 | ////////////////////////////////////////////////////////////////////////// 35 | /// @brief Writes marker stream user extended commands to command buffer. 36 | /// @param buffer target command buffer. 37 | /// @param data marker stream user extended data. 38 | /// @return operation status. 39 | ////////////////////////////////////////////////////////////////////////// 40 | template 41 | ML_INLINE static StatusCode Write( 42 | CommandBuffer& buffer, 43 | [[maybe_unused]] const CommandBufferMarkerStreamUserExtended_1_0& data ) 44 | { 45 | ML_FUNCTION_LOG( StatusCode::NotImplemented, &buffer.m_Context ); 46 | return log.m_Result; 47 | } 48 | }; 49 | } // namespace ML 50 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/traits/marker/ml_marker_stream_user.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_marker_stream_user.h 11 | 12 | @brief Allows to create, write marker stream user and get data from the marker. 13 | */ 14 | 15 | #pragma once 16 | 17 | namespace ML::BASE 18 | { 19 | ////////////////////////////////////////////////////////////////////////// 20 | /// @brief Base type for MarkerStreamUserTrait object. 21 | ////////////////////////////////////////////////////////////////////////// 22 | template 23 | struct MarkerStreamUserTrait : DdiObject 24 | { 25 | ML_DELETE_DEFAULT_CONSTRUCTOR( MarkerStreamUserTrait ); 26 | ML_DELETE_DEFAULT_COPY_AND_MOVE( MarkerStreamUserTrait ); 27 | 28 | ////////////////////////////////////////////////////////////////////////// 29 | /// @brief Types. 30 | ////////////////////////////////////////////////////////////////////////// 31 | using Base = DdiObject; 32 | 33 | ////////////////////////////////////////////////////////////////////////// 34 | /// @brief Writes marker stream user commands to command buffer. 35 | /// @param buffer target command buffer. 36 | /// @param data marker stream user data. 37 | /// @return operation status. 38 | ////////////////////////////////////////////////////////////////////////// 39 | template 40 | ML_INLINE static StatusCode Write( 41 | CommandBuffer& buffer, 42 | const CommandBufferMarkerStreamUser_1_0& data ) 43 | { 44 | ML_FUNCTION_LOG( StatusCode::Success, &buffer.m_Context ); 45 | 46 | // Load a value to A20 (gen 9) or A19 (gen11+) counter. 47 | ML_FUNCTION_CHECK( T::GpuCommands::LoadRegisterImmediate32( 48 | buffer, 49 | T::GpuRegisters::m_StreamMarker, 50 | data.Value ) ); 51 | 52 | // Trigger report with report reason 4. 53 | ML_FUNCTION_CHECK( T::GpuCommands::TriggerStreamReport( 54 | buffer, 55 | data.Value ) ); 56 | 57 | return log.m_Result; 58 | } 59 | }; 60 | } // namespace ML::BASE 61 | 62 | namespace ML::GEN9 63 | { 64 | template 65 | struct MarkerStreamUserTrait : BASE::MarkerStreamUserTrait 66 | { 67 | ML_DECLARE_TRAIT( MarkerStreamUserTrait, BASE ); 68 | }; 69 | } // namespace ML::GEN9 70 | 71 | namespace ML::GEN11 72 | { 73 | template 74 | struct MarkerStreamUserTrait : GEN9::MarkerStreamUserTrait 75 | { 76 | ML_DECLARE_TRAIT( MarkerStreamUserTrait, GEN9 ); 77 | }; 78 | } // namespace ML::GEN11 79 | 80 | namespace ML::XE_LP 81 | { 82 | template 83 | struct MarkerStreamUserTrait : GEN11::MarkerStreamUserTrait 84 | { 85 | ML_DECLARE_TRAIT( MarkerStreamUserTrait, GEN11 ); 86 | }; 87 | } // namespace ML::XE_LP 88 | 89 | namespace ML::XE_HPG 90 | { 91 | template 92 | struct MarkerStreamUserTrait : XE_LP::MarkerStreamUserTrait 93 | { 94 | ML_DECLARE_TRAIT( MarkerStreamUserTrait, XE_LP ); 95 | 96 | ////////////////////////////////////////////////////////////////////////// 97 | /// @brief Writes marker stream user commands to command buffer. 98 | /// @param buffer target command buffer. 99 | /// @param data marker stream user data. 100 | /// @return operation status. 101 | ////////////////////////////////////////////////////////////////////////// 102 | template 103 | ML_INLINE static StatusCode Write( 104 | CommandBuffer& buffer, 105 | const CommandBufferMarkerStreamUser_1_0& data ) 106 | { 107 | ML_FUNCTION_LOG( StatusCode::Success, &buffer.m_Context ); 108 | 109 | // Trigger report, which will be stored in oa buffer, in oag. 110 | // A given marker value will be inserted into the context id field 111 | // of the generated report. 112 | ML_FUNCTION_CHECK( T::GpuCommands::TriggerStreamReport( 113 | buffer, 114 | data.Value ) ); 115 | 116 | return log.m_Result; 117 | } 118 | }; 119 | } // namespace ML::XE_HPG 120 | 121 | namespace ML::XE_HPC 122 | { 123 | template 124 | struct MarkerStreamUserTrait : XE_HPG::MarkerStreamUserTrait 125 | { 126 | ML_DECLARE_TRAIT( MarkerStreamUserTrait, XE_HPG ); 127 | }; 128 | } // namespace ML::XE_HPC 129 | 130 | namespace ML::XE2_HPG 131 | { 132 | template 133 | struct MarkerStreamUserTrait : XE_HPG::MarkerStreamUserTrait 134 | { 135 | ML_DECLARE_TRAIT( MarkerStreamUserTrait, XE_HPG ); 136 | }; 137 | } // namespace ML::XE2_HPG 138 | 139 | namespace ML::XE3 140 | { 141 | template 142 | struct MarkerStreamUserTrait : XE2_HPG::MarkerStreamUserTrait 143 | { 144 | ML_DECLARE_TRAIT( MarkerStreamUserTrait, XE2_HPG ); 145 | }; 146 | } // namespace ML::XE3 147 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/traits/oa_buffer/ml_oa_buffer_dummy.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_oa_buffer_dummy.h 11 | 12 | @brief Dummy representation of oa buffer. 13 | */ 14 | 15 | #pragma once 16 | 17 | namespace ML 18 | { 19 | ////////////////////////////////////////////////////////////////////////// 20 | /// @brief Base type for OaBufferDummyTrait object. 21 | ////////////////////////////////////////////////////////////////////////// 22 | template 23 | struct OaBufferDummyTrait 24 | { 25 | ML_DELETE_DEFAULT_CONSTRUCTOR( OaBufferDummyTrait ); 26 | ML_DELETE_DEFAULT_COPY_AND_MOVE( OaBufferDummyTrait ); 27 | 28 | private: 29 | ////////////////////////////////////////////////////////////////////////// 30 | /// @brief Members. 31 | ////////////////////////////////////////////////////////////////////////// 32 | TT::Layouts::HwCounters::ReportOa m_OaReportDummy; 33 | TT::Context& m_Context; 34 | 35 | public: 36 | ////////////////////////////////////////////////////////////////////////// 37 | /// @brief OaBufferDummyTrait constructor. 38 | /// @param kernel kernel interface. 39 | ////////////////////////////////////////////////////////////////////////// 40 | OaBufferDummyTrait( const TT::KernelInterface& kernel ) 41 | : m_OaReportDummy{} 42 | , m_Context( kernel.m_Context ) 43 | { 44 | } 45 | 46 | ////////////////////////////////////////////////////////////////////////// 47 | /// @brief Initializes oa buffer. 48 | /// @return operation status. 49 | ////////////////////////////////////////////////////////////////////////// 50 | ML_INLINE StatusCode Initialize() const 51 | { 52 | return StatusCode::Success; 53 | } 54 | 55 | ////////////////////////////////////////////////////////////////////////// 56 | /// @brief Updates oa buffer state kept by hw counters query. 57 | /// @param state oa buffer state. 58 | /// @param reportGpu query report gpu. 59 | /// @return operation status. 60 | ////////////////////////////////////////////////////////////////////////// 61 | ML_INLINE StatusCode UpdateQuery( 62 | [[maybe_unused]] TT::Layouts::OaBuffer::State& state, 63 | [[maybe_unused]] TT::Layouts::HwCounters::Query::ReportGpu& reportGpu ) const 64 | { 65 | return StatusCode::Success; 66 | } 67 | 68 | ////////////////////////////////////////////////////////////////////////// 69 | /// @brief Releases a reference to oa buffer. 70 | /// @return operation status. 71 | ////////////////////////////////////////////////////////////////////////// 72 | ML_INLINE StatusCode Release() const 73 | { 74 | return StatusCode::Success; 75 | } 76 | 77 | ////////////////////////////////////////////////////////////////////////// 78 | /// @brief Checks oa buffer state. 79 | /// @return true if oa buffer has valid state. 80 | ////////////////////////////////////////////////////////////////////////// 81 | ML_INLINE bool IsValid() const 82 | { 83 | return false; 84 | } 85 | 86 | ////////////////////////////////////////////////////////////////////////// 87 | /// @brief Returns oa buffer size in bytes. 88 | /// @return oa buffer size. 89 | ////////////////////////////////////////////////////////////////////////// 90 | ML_INLINE uint32_t GetSize() const 91 | { 92 | return 0; 93 | } 94 | 95 | ////////////////////////////////////////////////////////////////////////// 96 | /// @brief Returns report size in oa buffer in bytes. 97 | /// @return report size. 98 | ////////////////////////////////////////////////////////////////////////// 99 | ML_INLINE uint32_t GetReportSize() const 100 | { 101 | return 0; 102 | } 103 | 104 | ////////////////////////////////////////////////////////////////////////// 105 | /// @brief Finds oa reports between query begin/end reports. 106 | /// @param oaBufferState oa buffer state. 107 | /// @return oa reports count between query begin/end. 108 | ////////////////////////////////////////////////////////////////////////// 109 | ML_INLINE uint32_t FindOaWindow( [[maybe_unused]] const TT::Layouts::OaBuffer::State& oaBufferState ) const 110 | { 111 | return 0; 112 | } 113 | 114 | ////////////////////////////////////////////////////////////////////////// 115 | /// @brief Returns oa report from oa buffer. 116 | /// @param offset oa report offset within oa buffer. 117 | /// @return reference to oa report. 118 | ////////////////////////////////////////////////////////////////////////// 119 | ML_INLINE TT::Layouts::HwCounters::ReportOa& GetReport( [[maybe_unused]] const uint32_t offset ) 120 | { 121 | return m_OaReportDummy; 122 | } 123 | 124 | ////////////////////////////////////////////////////////////////////////// 125 | /// @brief Returns first oa report associated with query begin/end report. 126 | /// @param begin query begin/end. 127 | /// @param reportGpu gpu report collected by query. 128 | /// @return offset oa tail offset. 129 | /// @return operation status. 130 | ////////////////////////////////////////////////////////////////////////// 131 | template 132 | ML_INLINE StatusCode GetPreReportOffset( 133 | [[maybe_unused]] const TT::Layouts::HwCounters::Query::ReportGpu& reportGpu, 134 | [[maybe_unused]] uint32_t& offset ) const 135 | { 136 | ML_ASSERT_ALWAYS_ADAPTER( m_Context.m_AdapterId ); 137 | return StatusCode::Failed; 138 | } 139 | 140 | ////////////////////////////////////////////////////////////////////////// 141 | /// @brief Returns last oa report associated with query begin/end report. 142 | /// @param begin query begin/end. 143 | /// @param reportGpu gpu report collected by query. 144 | /// @return offset oa tail offset. 145 | /// @return operation status. 146 | ////////////////////////////////////////////////////////////////////////// 147 | template 148 | ML_INLINE StatusCode GetPostReportOffset( 149 | [[maybe_unused]] const TT::Layouts::HwCounters::Query::ReportGpu& reportGpu, 150 | [[maybe_unused]] uint32_t& offset ) const 151 | { 152 | ML_ASSERT_ALWAYS_ADAPTER( m_Context.m_AdapterId ); 153 | return StatusCode::Failed; 154 | } 155 | 156 | ////////////////////////////////////////////////////////////////////////// 157 | /// @brief Dumps oa buffer reports between query begin / query end. 158 | /// @param reportGpu gpu query report. 159 | /// @return operation status. 160 | ////////////////////////////////////////////////////////////////////////// 161 | ML_INLINE StatusCode DumpReports( [[maybe_unused]] const TT::Layouts::HwCounters::Query::ReportGpu& reportGpu ) const 162 | { 163 | return StatusCode::Success; 164 | } 165 | 166 | ////////////////////////////////////////////////////////////////////////// 167 | /// @brief Prints out requested report count. 168 | /// @param offset oa report start offset. 169 | /// @param count oa report count. 170 | ////////////////////////////////////////////////////////////////////////// 171 | ML_INLINE void PrintReports( 172 | [[maybe_unused]] const uint32_t offset, 173 | [[maybe_unused]] const uint32_t count ) const 174 | { 175 | } 176 | }; 177 | } // namespace ML 178 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/traits/object/ml_ddi_objects.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2021-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_ddi_objects.h 11 | 12 | @brief Stores created ddi objects. 13 | Warns if there are remaining ddi objects on context deletion. 14 | */ 15 | 16 | #pragma once 17 | 18 | namespace ML 19 | { 20 | ////////////////////////////////////////////////////////////////////////// 21 | /// @brief Base type for DdiObjectsTrait object. 22 | ////////////////////////////////////////////////////////////////////////// 23 | template 24 | struct DdiObjectsTrait 25 | { 26 | ML_DELETE_DEFAULT_CONSTRUCTOR( DdiObjectsTrait ); 27 | ML_DELETE_DEFAULT_COPY_AND_MOVE( DdiObjectsTrait ); 28 | 29 | ////////////////////////////////////////////////////////////////////////// 30 | /// @brief Members. 31 | ////////////////////////////////////////////////////////////////////////// 32 | TT::Context& m_Context; 33 | std::unordered_set m_Objects; 34 | std::mutex m_Mutex; 35 | 36 | ////////////////////////////////////////////////////////////////////////// 37 | /// @brief DdiObjectsTrait constructor. 38 | /// @param context context. 39 | ////////////////////////////////////////////////////////////////////////// 40 | DdiObjectsTrait( TT::Context& context ) 41 | : m_Context( context ) 42 | , m_Objects{} 43 | { 44 | } 45 | 46 | ////////////////////////////////////////////////////////////////////////// 47 | /// @brief DdiObjectsTrait destructor. 48 | ////////////////////////////////////////////////////////////////////////// 49 | ~DdiObjectsTrait() 50 | { 51 | ValidateState(); 52 | } 53 | 54 | ////////////////////////////////////////////////////////////////////////// 55 | /// @brief Adds ddi object to unordered set. 56 | /// @param object an object to be added. 57 | ////////////////////////////////////////////////////////////////////////// 58 | ML_INLINE void AddObject( BaseObject* object ) 59 | { 60 | std::lock_guard guard( m_Mutex ); 61 | 62 | m_Objects.insert( object ); 63 | } 64 | 65 | ////////////////////////////////////////////////////////////////////////// 66 | /// @brief Removes ddi object from unordered set. 67 | /// @param object an object to be removed. 68 | ////////////////////////////////////////////////////////////////////////// 69 | ML_INLINE void RemoveObject( BaseObject* object ) 70 | { 71 | std::lock_guard guard( m_Mutex ); 72 | 73 | m_Objects.erase( object ); 74 | } 75 | 76 | ////////////////////////////////////////////////////////////////////////// 77 | /// @brief Validates undeleted objects. 78 | ////////////////////////////////////////////////////////////////////////// 79 | ML_INLINE void ValidateState() 80 | { 81 | ML_FUNCTION_LOG( StatusCode::Success, &m_Context ); 82 | 83 | if( !m_Objects.empty() ) 84 | { 85 | log.Info( "Some ddi objects should be deleted, count", m_Objects.size() ); 86 | } 87 | } 88 | }; 89 | } // namespace ML 90 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/traits/override/linux/ml_override_layouts.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_override_layouts.h 11 | 12 | @brief Layout for overrides. 13 | */ 14 | 15 | #pragma once 16 | 17 | namespace ML 18 | { 19 | ////////////////////////////////////////////////////////////////////////// 20 | /// @brief Base type for OverrideLayoutsTrait object. 21 | ////////////////////////////////////////////////////////////////////////// 22 | template 23 | struct OverrideLayoutsTrait 24 | { 25 | ML_DELETE_DEFAULT_CONSTRUCTOR( OverrideLayoutsTrait ); 26 | ML_DELETE_DEFAULT_COPY_AND_MOVE( OverrideLayoutsTrait ); 27 | 28 | ////////////////////////////////////////////////////////////////////////// 29 | /// @brief Override posh query. 30 | ////////////////////////////////////////////////////////////////////////// 31 | struct PoshQuery 32 | { 33 | bool m_Enabled; 34 | }; 35 | }; 36 | } // namespace ML 37 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/traits/override/linux/ml_override_posh_query.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_override_posh_query.h 11 | 12 | @brief Enables posh query override. 13 | */ 14 | 15 | #pragma once 16 | 17 | namespace ML 18 | { 19 | ////////////////////////////////////////////////////////////////////////// 20 | /// @brief Base type for OverridePoshQueryTrait object. 21 | ////////////////////////////////////////////////////////////////////////// 22 | template 23 | struct OverridePoshQueryTrait : DdiObject 24 | { 25 | ML_DELETE_DEFAULT_CONSTRUCTOR( OverridePoshQueryTrait ); 26 | ML_DELETE_DEFAULT_COPY_AND_MOVE( OverridePoshQueryTrait ); 27 | 28 | ////////////////////////////////////////////////////////////////////////// 29 | /// @brief Types. 30 | ////////////////////////////////////////////////////////////////////////// 31 | using Base = DdiObject; 32 | 33 | ////////////////////////////////////////////////////////////////////////// 34 | /// @brief Override posh query constructor. 35 | /// @param context library context. 36 | ////////////////////////////////////////////////////////////////////////// 37 | OverridePoshQueryTrait( TT::Context& context ) 38 | : Base( context ) 39 | { 40 | } 41 | 42 | ////////////////////////////////////////////////////////////////////////// 43 | /// @brief Creates posh query override. 44 | /// @param context library context. 45 | /// @return handle override handle. 46 | /// @return operation status. 47 | ////////////////////////////////////////////////////////////////////////// 48 | ML_INLINE static StatusCode Create( 49 | [[maybe_unused]] TT::Context& context, 50 | [[maybe_unused]] OverrideHandle_1_0& handle ) 51 | { 52 | return StatusCode::NotImplemented; 53 | } 54 | 55 | ////////////////////////////////////////////////////////////////////////// 56 | /// @brief Returns state of user overrides. 57 | /// @return getData data requested by client. 58 | /// @return operation status. 59 | ////////////////////////////////////////////////////////////////////////// 60 | ML_INLINE static StatusCode GetData( [[maybe_unused]] GetReportOverride_1_0& getData ) 61 | { 62 | return StatusCode::NotImplemented; 63 | } 64 | }; 65 | } // namespace ML 66 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/traits/override/linux/ml_override_user.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_override_user.h 11 | 12 | @brief Creates, activates and deactivates override by writing configuration 13 | to registers. 14 | */ 15 | 16 | #pragma once 17 | 18 | namespace ML 19 | { 20 | ////////////////////////////////////////////////////////////////////////// 21 | /// @brief Base type for OverrideUserTrait object. 22 | ////////////////////////////////////////////////////////////////////////// 23 | template 24 | struct OverrideUserTrait : DdiObject 25 | { 26 | ML_DELETE_DEFAULT_CONSTRUCTOR( OverrideUserTrait ); 27 | ML_DELETE_DEFAULT_COPY_AND_MOVE( OverrideUserTrait ); 28 | 29 | ////////////////////////////////////////////////////////////////////////// 30 | /// @brief Types. 31 | ////////////////////////////////////////////////////////////////////////// 32 | using Base = DdiObject; 33 | 34 | ////////////////////////////////////////////////////////////////////////// 35 | /// @brief Creates user override configuration. 36 | /// @param context library context. 37 | /// @return handle override handle. 38 | /// @return operation status. 39 | ////////////////////////////////////////////////////////////////////////// 40 | ML_INLINE static StatusCode Create( 41 | [[maybe_unused]] TT::Context& context, 42 | [[maybe_unused]] OverrideHandle_1_0& handle ) 43 | { 44 | return StatusCode::NotImplemented; 45 | } 46 | 47 | ////////////////////////////////////////////////////////////////////////// 48 | /// @brief Writes null hardware override commands to command buffer. 49 | /// @param buffer command buffer. 50 | /// @param data override data. 51 | /// @return operation status. 52 | ////////////////////////////////////////////////////////////////////////// 53 | template 54 | ML_INLINE static StatusCode Write( 55 | [[maybe_unused]] CommandBuffer& buffer, 56 | [[maybe_unused]] const CommandBufferOverride_1_0& data ) 57 | { 58 | return StatusCode::NotImplemented; 59 | } 60 | 61 | //////////////////////////////////////////////////////////////////////// 62 | /// @brief Return override reports. 63 | /// @return getData data requested by client. 64 | /// @return operation status. 65 | ////////////////////////////////////////////////////////////////////////// 66 | ML_INLINE static StatusCode GetData( [[maybe_unused]] const GetReportOverride_1_0& getData ) 67 | { 68 | return StatusCode::NotImplemented; 69 | } 70 | }; 71 | } // namespace ML 72 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/traits/override/ml_override_flush_caches.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_override_flush_caches.h 11 | 12 | @brief Writes gpu commands to flush caches. 13 | */ 14 | 15 | #pragma once 16 | 17 | namespace ML 18 | { 19 | ////////////////////////////////////////////////////////////////////////// 20 | /// @brief Base type for OverrideFlushCachesTrait object. 21 | ////////////////////////////////////////////////////////////////////////// 22 | template 23 | struct OverrideFlushCachesTrait : DdiObject 24 | { 25 | ML_DELETE_DEFAULT_CONSTRUCTOR( OverrideFlushCachesTrait ); 26 | ML_DELETE_DEFAULT_COPY_AND_MOVE( OverrideFlushCachesTrait ); 27 | 28 | ////////////////////////////////////////////////////////////////////////// 29 | /// @brief Types. 30 | ////////////////////////////////////////////////////////////////////////// 31 | using Base = DdiObject; 32 | using Base::m_Context; 33 | 34 | ////////////////////////////////////////////////////////////////////////// 35 | /// @brief Writes flush gpu caches override command to command buffer. 36 | /// @param buffer command buffer. 37 | /// @return operation status. 38 | ////////////////////////////////////////////////////////////////////////// 39 | template 40 | ML_INLINE static StatusCode Write( CommandBuffer& buffer ) 41 | { 42 | ML_FUNCTION_LOG( StatusCode::Success, &buffer.m_Context ); 43 | ML_FUNCTION_CHECK( T::GpuCommands::FlushCaches( buffer ) ); 44 | 45 | return log.m_Result; 46 | } 47 | }; 48 | } // namespace ML 49 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/traits/policy/linux/ml_policy_oneapi.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_policy_openapi.h 11 | 12 | @brief Policies for OneApi. 13 | */ 14 | 15 | #pragma once 16 | 17 | namespace ML::BASE 18 | { 19 | ////////////////////////////////////////////////////////////////////////// 20 | /// @brief Base type for PolicyOneApiTrait object. 21 | ////////////////////////////////////////////////////////////////////////// 22 | template 23 | struct PolicyOneApiTrait 24 | { 25 | ML_DELETE_DEFAULT_CONSTRUCTOR( PolicyOneApiTrait ); 26 | ML_DELETE_DEFAULT_COPY_AND_MOVE( PolicyOneApiTrait ); 27 | 28 | ////////////////////////////////////////////////////////////////////////// 29 | /// @brief Query hw counters policies. 30 | ////////////////////////////////////////////////////////////////////////// 31 | struct QueryHwCounters 32 | { 33 | ////////////////////////////////////////////////////////////////////////// 34 | /// @brief Common query policies. 35 | ////////////////////////////////////////////////////////////////////////// 36 | struct Common 37 | { 38 | static constexpr bool m_PatchGpuMemory = false; 39 | }; 40 | 41 | ////////////////////////////////////////////////////////////////////////// 42 | /// @brief Query creation policies. 43 | ////////////////////////////////////////////////////////////////////////// 44 | struct Create 45 | { 46 | static constexpr uint32_t m_MaxSlotCount = 0xFFFFFFFF; 47 | static constexpr bool m_UserCounters = false; 48 | }; 49 | 50 | ////////////////////////////////////////////////////////////////////////// 51 | /// @brief Query begin policies. 52 | ////////////////////////////////////////////////////////////////////////// 53 | struct Begin 54 | { 55 | static constexpr bool m_FlushCommandBuffer = false; 56 | static constexpr bool m_ClearGpuMemory = true; 57 | }; 58 | 59 | ////////////////////////////////////////////////////////////////////////// 60 | /// @brief Query end policies. 61 | ////////////////////////////////////////////////////////////////////////// 62 | struct End 63 | { 64 | static constexpr bool m_UseEndTagAsCompletionStatus = true; 65 | static constexpr bool m_UseDoubleTriggers = false; 66 | }; 67 | 68 | ////////////////////////////////////////////////////////////////////////// 69 | /// @brief Query get data policies. 70 | ////////////////////////////////////////////////////////////////////////// 71 | struct GetData 72 | { 73 | static constexpr bool m_AllowEmptyContextId = true; 74 | static constexpr bool m_ResetOaBufferState = true; 75 | static constexpr bool m_CheckConfigurationActivation = true; 76 | }; 77 | }; 78 | 79 | ////////////////////////////////////////////////////////////////////////// 80 | /// @brief Configuration oa policies. 81 | ////////////////////////////////////////////////////////////////////////// 82 | struct ConfigurationOa 83 | { 84 | ////////////////////////////////////////////////////////////////////////// 85 | /// @brief Configuration activation policies. 86 | ////////////////////////////////////////////////////////////////////////// 87 | struct Activate 88 | { 89 | static constexpr bool m_RestartTbs = true; 90 | }; 91 | }; 92 | }; 93 | } // namespace ML::BASE 94 | 95 | namespace ML::GEN9 96 | { 97 | template 98 | struct PolicyOneApiTrait : BASE::PolicyOneApiTrait 99 | { 100 | ML_DECLARE_TRAIT( PolicyOneApiTrait, BASE ); 101 | }; 102 | } // namespace ML::GEN9 103 | 104 | namespace ML::GEN11 105 | { 106 | template 107 | struct PolicyOneApiTrait : GEN9::PolicyOneApiTrait 108 | { 109 | ML_DECLARE_TRAIT( PolicyOneApiTrait, GEN9 ); 110 | }; 111 | } // namespace ML::GEN11 112 | 113 | namespace ML::XE_LP 114 | { 115 | template 116 | struct PolicyOneApiTrait : GEN11::PolicyOneApiTrait 117 | { 118 | ML_DECLARE_TRAIT( PolicyOneApiTrait, GEN11 ); 119 | 120 | ////////////////////////////////////////////////////////////////////////// 121 | /// @brief Configuration oa policies. 122 | ////////////////////////////////////////////////////////////////////////// 123 | struct ConfigurationOa : Base::ConfigurationOa 124 | { 125 | ////////////////////////////////////////////////////////////////////////// 126 | /// @brief Configuration activation policies. 127 | ////////////////////////////////////////////////////////////////////////// 128 | struct Activate 129 | { 130 | static constexpr bool m_RestartTbs = false; 131 | }; 132 | }; 133 | }; 134 | } // namespace ML::XE_LP 135 | 136 | namespace ML::XE_HPG 137 | { 138 | template 139 | struct PolicyOneApiTrait : XE_LP::PolicyOneApiTrait 140 | { 141 | ML_DECLARE_TRAIT( PolicyOneApiTrait, XE_LP ); 142 | 143 | ////////////////////////////////////////////////////////////////////////// 144 | /// @brief Sub device policies. 145 | ////////////////////////////////////////////////////////////////////////// 146 | struct SubDevice 147 | { 148 | static constexpr bool m_DriverClientDataRequired = false; 149 | static constexpr bool m_AllowImplicitScaling = true; 150 | }; 151 | }; 152 | } // namespace ML::XE_HPG 153 | 154 | namespace ML::XE_HPC 155 | { 156 | template 157 | struct PolicyOneApiTrait : XE_HPG::PolicyOneApiTrait 158 | { 159 | ML_DECLARE_TRAIT( PolicyOneApiTrait, XE_HPG ); 160 | }; 161 | } // namespace ML::XE_HPC 162 | 163 | namespace ML::XE2_HPG 164 | { 165 | template 166 | struct PolicyOneApiTrait : XE_HPG::PolicyOneApiTrait 167 | { 168 | ML_DECLARE_TRAIT( PolicyOneApiTrait, XE_HPG ); 169 | }; 170 | } // namespace ML::XE2_HPG 171 | 172 | namespace ML::XE3 173 | { 174 | template 175 | struct PolicyOneApiTrait : XE2_HPG::PolicyOneApiTrait 176 | { 177 | ML_DECLARE_TRAIT( PolicyOneApiTrait, XE2_HPG ); 178 | }; 179 | } // namespace ML::XE3 180 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/traits/policy/linux/ml_policy_opencl.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_policy_opencl.h 11 | 12 | @brief Policies for OpenCL. 13 | */ 14 | 15 | #pragma once 16 | 17 | namespace ML::BASE 18 | { 19 | ////////////////////////////////////////////////////////////////////////// 20 | /// @brief Base type for PolicyOpenCLTrait object. 21 | ////////////////////////////////////////////////////////////////////////// 22 | template 23 | struct PolicyOpenCLTrait 24 | { 25 | ML_DELETE_DEFAULT_CONSTRUCTOR( PolicyOpenCLTrait ); 26 | ML_DELETE_DEFAULT_COPY_AND_MOVE( PolicyOpenCLTrait ); 27 | 28 | ////////////////////////////////////////////////////////////////////////// 29 | /// @brief Query hw counters policies. 30 | ////////////////////////////////////////////////////////////////////////// 31 | struct QueryHwCounters 32 | { 33 | ////////////////////////////////////////////////////////////////////////// 34 | /// @brief Common query policies. 35 | ////////////////////////////////////////////////////////////////////////// 36 | struct Common 37 | { 38 | static constexpr bool m_PatchGpuMemory = false; 39 | }; 40 | 41 | ////////////////////////////////////////////////////////////////////////// 42 | /// @brief Query creation policies. 43 | ////////////////////////////////////////////////////////////////////////// 44 | struct Create 45 | { 46 | static constexpr uint32_t m_MaxSlotCount = 1; 47 | static constexpr bool m_UserCounters = false; 48 | }; 49 | 50 | ////////////////////////////////////////////////////////////////////////// 51 | /// @brief Query begin policies. 52 | ////////////////////////////////////////////////////////////////////////// 53 | struct Begin 54 | { 55 | static constexpr bool m_FlushCommandBuffer = false; 56 | static constexpr bool m_ClearGpuMemory = true; 57 | }; 58 | 59 | ////////////////////////////////////////////////////////////////////////// 60 | /// @brief Query end policies. 61 | ////////////////////////////////////////////////////////////////////////// 62 | struct End 63 | { 64 | static constexpr bool m_UseEndTagAsCompletionStatus = true; 65 | static constexpr bool m_UseDoubleTriggers = false; 66 | }; 67 | 68 | ////////////////////////////////////////////////////////////////////////// 69 | /// @brief Query get data policies. 70 | ////////////////////////////////////////////////////////////////////////// 71 | struct GetData 72 | { 73 | static constexpr bool m_AllowEmptyContextId = true; 74 | static constexpr bool m_ResetOaBufferState = false; 75 | static constexpr bool m_CheckConfigurationActivation = false; 76 | }; 77 | }; 78 | 79 | ////////////////////////////////////////////////////////////////////////// 80 | /// @brief Configuration oa policies. 81 | ////////////////////////////////////////////////////////////////////////// 82 | struct ConfigurationOa 83 | { 84 | ////////////////////////////////////////////////////////////////////////// 85 | /// @brief Configuration activation policies. 86 | ////////////////////////////////////////////////////////////////////////// 87 | struct Activate 88 | { 89 | static constexpr bool m_RestartTbs = true; 90 | }; 91 | }; 92 | }; 93 | } // namespace ML::BASE 94 | 95 | namespace ML::GEN9 96 | { 97 | template 98 | struct PolicyOpenCLTrait : BASE::PolicyOpenCLTrait 99 | { 100 | ML_DECLARE_TRAIT( PolicyOpenCLTrait, BASE ); 101 | }; 102 | } // namespace ML::GEN9 103 | 104 | namespace ML::GEN11 105 | { 106 | template 107 | struct PolicyOpenCLTrait : GEN9::PolicyOpenCLTrait 108 | { 109 | ML_DECLARE_TRAIT( PolicyOpenCLTrait, GEN9 ); 110 | }; 111 | } // namespace ML::GEN11 112 | 113 | namespace ML::XE_LP 114 | { 115 | template 116 | struct PolicyOpenCLTrait : GEN11::PolicyOpenCLTrait 117 | { 118 | ML_DECLARE_TRAIT( PolicyOpenCLTrait, GEN11 ); 119 | 120 | ////////////////////////////////////////////////////////////////////////// 121 | /// @brief Configuration oa policies. 122 | ////////////////////////////////////////////////////////////////////////// 123 | struct ConfigurationOa : Base::ConfigurationOa 124 | { 125 | ////////////////////////////////////////////////////////////////////////// 126 | /// @brief Configuration activation policies. 127 | ////////////////////////////////////////////////////////////////////////// 128 | struct Activate 129 | { 130 | static constexpr bool m_RestartTbs = false; 131 | }; 132 | }; 133 | }; 134 | } // namespace ML::XE_LP 135 | 136 | namespace ML::XE_HPG 137 | { 138 | template 139 | struct PolicyOpenCLTrait : XE_LP::PolicyOpenCLTrait 140 | { 141 | ML_DECLARE_TRAIT( PolicyOpenCLTrait, XE_LP ); 142 | 143 | ////////////////////////////////////////////////////////////////////////// 144 | /// @brief Sub device policies. 145 | ////////////////////////////////////////////////////////////////////////// 146 | struct SubDevice 147 | { 148 | static constexpr bool m_DriverClientDataRequired = false; 149 | static constexpr bool m_AllowImplicitScaling = false; 150 | }; 151 | }; 152 | } // namespace ML::XE_HPG 153 | 154 | namespace ML::XE_HPC 155 | { 156 | template 157 | struct PolicyOpenCLTrait : XE_HPG::PolicyOpenCLTrait 158 | { 159 | ML_DECLARE_TRAIT( PolicyOpenCLTrait, XE_HPG ); 160 | }; 161 | } // namespace ML::XE_HPC 162 | 163 | namespace ML::XE2_HPG 164 | { 165 | template 166 | struct PolicyOpenCLTrait : XE_HPG::PolicyOpenCLTrait 167 | { 168 | ML_DECLARE_TRAIT( PolicyOpenCLTrait, XE_HPG ); 169 | }; 170 | } // namespace ML::XE2_HPG 171 | 172 | namespace ML::XE3 173 | { 174 | template 175 | struct PolicyOpenCLTrait : XE2_HPG::PolicyOpenCLTrait 176 | { 177 | ML_DECLARE_TRAIT( PolicyOpenCLTrait, XE2_HPG ); 178 | }; 179 | } // namespace ML::XE3 180 | -------------------------------------------------------------------------------- /instrumentation/metrics_library/traits/tools/linux/ml_tools_os.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2025 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file ml_tools_os.h 11 | 12 | @brief Contains a set of os specific helper functions. 13 | */ 14 | 15 | #pragma once 16 | 17 | namespace ML 18 | { 19 | ////////////////////////////////////////////////////////////////////////// 20 | /// @brief Base type for ToolsOsTrait object. 21 | ////////////////////////////////////////////////////////////////////////// 22 | template 23 | struct ToolsOsTrait 24 | { 25 | ML_DELETE_DEFAULT_CONSTRUCTOR( ToolsOsTrait ); 26 | ML_DELETE_DEFAULT_COPY_AND_MOVE( ToolsOsTrait ); 27 | 28 | ////////////////////////////////////////////////////////////////////////// 29 | /// @brief Returns process id. 30 | /// @return process id. 31 | ////////////////////////////////////////////////////////////////////////// 32 | ML_INLINE static uint32_t GetProcessId() 33 | { 34 | return getpid(); 35 | } 36 | 37 | ////////////////////////////////////////////////////////////////////////// 38 | /// @brief Returns cpu timestamp. 39 | /// @return timestamp value. 40 | ////////////////////////////////////////////////////////////////////////// 41 | ML_INLINE static uint64_t GetCpuTimestamp() 42 | { 43 | struct timespec time = {}; 44 | clock_gettime( CLOCK_MONOTONIC, &time ); 45 | return static_cast( time.tv_nsec ) + static_cast( time.tv_sec ) * Constants::Time::m_SecondInNanoseconds; 46 | } 47 | 48 | ////////////////////////////////////////////////////////////////////////// 49 | /// @brief Gets exact cpu timestamp frequency. 50 | /// @return cpu timestamp frequency. 51 | ////////////////////////////////////////////////////////////////////////// 52 | ML_INLINE static uint64_t GetCpuTimestampFrequency() 53 | { 54 | return Constants::Time::m_SecondInNanoseconds; 55 | } 56 | 57 | ////////////////////////////////////////////////////////////////////////// 58 | /// @brief Reads system settings. 59 | /// @param name system variable name. 60 | /// @return data system variable value. 61 | /// @return operation status. 62 | ////////////////////////////////////////////////////////////////////////// 63 | template 64 | ML_INLINE static StatusCode GetSystemVariable( 65 | const char* name, 66 | Result& data ) 67 | { 68 | const std::string variableName = std::string( Constants::Library::m_Name ) + name; 69 | const char* rawData = std::getenv( variableName.c_str() ); 70 | 71 | if( rawData == nullptr ) 72 | { 73 | return StatusCode::Failed; 74 | } 75 | 76 | data = static_cast( std::atoi( rawData ) ); 77 | 78 | return StatusCode::Success; 79 | } 80 | 81 | ////////////////////////////////////////////////////////////////////////// 82 | /// @brief Returns current time as string. 83 | /// @return current time. 84 | ////////////////////////////////////////////////////////////////////////// 85 | ML_INLINE static std::string GetCurrentTime() 86 | { 87 | std::ostringstream timeOutput; 88 | tm timeLocal; 89 | time_t timeCurrent = time( nullptr ); 90 | 91 | timeLocal = *localtime( &timeCurrent ); 92 | 93 | timeOutput << std::put_time( &timeLocal, "%d-%m-%Y_%H-%M-%S" ); 94 | 95 | return timeOutput.str(); 96 | } 97 | }; 98 | } // namespace ML 99 | -------------------------------------------------------------------------------- /instrumentation/utils/common/inc/iu_std.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2024 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file iu_std.h 11 | 12 | @brief Instrumentation Utils header with OS specific standard functions and macros. 13 | */ 14 | 15 | #pragma once 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | /////////////////////////////////////////////////////////////////////////////// 23 | // 24 | // Description: 25 | // OS dependent standard functions. 26 | // 27 | /////////////////////////////////////////////////////////////////////////////// 28 | #if defined( __cplusplus ) 29 | extern "C" 30 | { 31 | #endif 32 | 33 | // Memory 34 | bool iu_zeromem( void* dest, size_t destSize ); 35 | bool iu_memset( void* dest, int32_t value, size_t count ); 36 | bool iu_memcpy_s( void* dest, size_t destSize, const void* src, size_t count ); 37 | bool iu_memcmp( const void* ptr1, const void* ptr2, size_t bytesToCompare ); 38 | 39 | // C-strings 40 | bool iu_strcpy_s( char* destStr, size_t destSize, const char* srcStr ); 41 | bool iu_strncpy_s( char* destStr, size_t destSize, const char* srcStr, size_t count ); 42 | bool iu_strcat_s( char* destStr, size_t destSize, const char* srcStr ); 43 | char* iu_strtok_s( char* str, const char* delimiters, char** context ); 44 | size_t iu_strnlen_s( const char* str, size_t strSize ); 45 | int32_t iu_strncmp( const char* str1, const char* str2, size_t count ); 46 | 47 | // Wide-char C-strings 48 | bool iu_wstrcat_s( wchar_t* destWstr, size_t destSize, const wchar_t* srcWstr ); 49 | bool iu_wstrncat_s( wchar_t* destWstr, size_t destSize, const wchar_t* srcWstr, size_t maxAppend ); 50 | bool iu_wstrncpy_s( wchar_t* destWstr, size_t destSize, const wchar_t* srcWstr, size_t count ); 51 | size_t iu_wstrnlen( const wchar_t* wstr, size_t wstrSize ); 52 | int32_t iu_wstrncmp( const wchar_t* wstr1, const wchar_t* wstr2, size_t count ); 53 | size_t iu_wstrtombs_s( char* destStr, size_t destSize, const wchar_t* srcWstr, size_t count ); 54 | size_t iu_mbstowstr_s( wchar_t* destWstr, size_t destSize, const char* srcStr, size_t count ); 55 | 56 | // Printing 57 | int32_t iu_sprintf_s( char* destStr, size_t destSize, const char* format, ... ); 58 | bool iu_snprintf( char* str, size_t size, const char* format, ... ); 59 | bool iu_vsnprintf( char* str, size_t size, const char* format, va_list ap ); 60 | 61 | // Debug printing 62 | void iu_log( const char* msg ); 63 | bool iu_log_file( const char* msg ); 64 | void iu_printf( const char* msg, const bool addEOL, const bool flush ); 65 | 66 | // Files 67 | bool iu_fopen_s( FILE** pFile, const char* filename, const char* mode ); 68 | size_t iu_fread_s( void* buff, size_t buffSize, size_t elemSize, size_t count, FILE* stream ); 69 | 70 | // Environment variable 71 | const char* iu_dupenv_s( const char* varName ); 72 | 73 | // System 74 | uint32_t iu_get_thread_id(); 75 | 76 | #if defined( __cplusplus ) 77 | } // extern "C" 78 | #endif 79 | -------------------------------------------------------------------------------- /instrumentation/utils/linux/inc/iu_os.h: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2024 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file iu_os.h 11 | 12 | @brief Instrumentation Utils implementation with OS specific non-standard 13 | functions for Linux. 14 | */ 15 | 16 | #pragma once 17 | 18 | #include 19 | #include 20 | 21 | /////////////////////////////////////////////////////////////////////////////// 22 | // 23 | // Description: 24 | // Defines related to unit conversion. 25 | // 26 | /////////////////////////////////////////////////////////////////////////////// 27 | #define IU_SECOND_IN_NS 1000000000ULL 28 | #define IU_SECOND_IN_US 1000000ULL 29 | 30 | /////////////////////////////////////////////////////////////////////////////// 31 | // 32 | // Description: 33 | // Defines related to reading module and process names functionality. 34 | // 35 | /////////////////////////////////////////////////////////////////////////////// 36 | #define IU_MODULE_NAME_SIZE_MAX 128 37 | 38 | /////////////////////////////////////////////////////////////////////////////// 39 | // 40 | // Description: 41 | // OS dependent non-standard functions. 42 | // 43 | /////////////////////////////////////////////////////////////////////////////// 44 | #if defined( __cplusplus ) 45 | extern "C" 46 | { 47 | #endif 48 | 49 | uint64_t IuOsQueryPerformanceCounter( 50 | uint64_t* outFrequency ); 51 | 52 | const char* IuOsGetModuleInfo( 53 | char** processName ); 54 | 55 | void IuOsLogGetSystemSettings( 56 | void* deviceContext, 57 | bool* assertEnable, 58 | uint32_t* logLayerEnable, 59 | uint32_t* logLevel ); 60 | 61 | void IuOsLogGetLocalSettings( 62 | bool* assertEnable, 63 | uint32_t* logLayerEnable, 64 | uint32_t* logLevel ); 65 | 66 | #if defined( __cplusplus ) 67 | } // extern "C" 68 | #endif 69 | -------------------------------------------------------------------------------- /instrumentation/utils/linux/iu_os.cpp: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2024 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | /* 10 | @file iu_os.cpp 11 | 12 | @brief Instrumentation Utils implementation with OS specific non-standard 13 | functions for Linux 14 | */ 15 | 16 | #include "iu_os.h" 17 | #include "iu_debug.h" 18 | #include "iu_std.h" 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #if defined( __linux ) 25 | #include // for gettimeofday 26 | #endif 27 | 28 | extern "C" 29 | { 30 | /////////////////////////////////////////////////////////////////////////////// 31 | // 32 | // Group: 33 | // Instrumentation Utils Non-Standard OS Specific Functions 34 | // 35 | // Method: 36 | // IuOsQueryPerformanceCounter 37 | // 38 | // Description: 39 | // Retrieves high resolution timestamp (in ticks) and it's frequency. 40 | // 41 | // Input: 42 | // uint64_t* outFrequency - performance counter frequency (ticks per second) 43 | // 44 | // Output: 45 | // uint64_t - performance counter value (timestamp in ticks) 46 | // 47 | /////////////////////////////////////////////////////////////////////////////// 48 | uint64_t IuOsQueryPerformanceCounter( uint64_t* outFrequency ) 49 | { 50 | uint64_t frequency = 0; 51 | uint64_t counter = 0; 52 | 53 | #if defined( __linux__ ) 54 | timeval currentTime; 55 | gettimeofday( ¤tTime, 0 ); 56 | counter = (uint64_t) currentTime.tv_sec * IU_SECOND_IN_US + currentTime.tv_usec; // convert to us 57 | frequency = IU_SECOND_IN_US; // unit is microsecond 58 | #endif 59 | 60 | if( outFrequency ) 61 | { 62 | *outFrequency = frequency; 63 | } 64 | 65 | IU_DBG_FUNCTION_OUTPUT64( IU_DBG_SEV_DEBUG, counter ); 66 | IU_DBG_FUNCTION_OUTPUT64( IU_DBG_SEV_DEBUG, frequency ); 67 | 68 | return counter; 69 | } 70 | 71 | /////////////////////////////////////////////////////////////////////////////// 72 | // 73 | // Group: 74 | // Instrumentation Utils Non-Standard OS Specific Functions 75 | // 76 | // Method: 77 | // IuOsGetModuleInfo 78 | // 79 | // Description: 80 | // Returns information on current module. Used for debug logs. 81 | // 82 | // Input: 83 | // char** processName - (OUT) 84 | // 85 | // Output: 86 | // char* dlName - (OUT) 87 | // 88 | /////////////////////////////////////////////////////////////////////////////// 89 | const char* IuOsGetModuleInfo( char** processName ) 90 | { 91 | if( !processName ) 92 | { 93 | return NULL; 94 | } 95 | 96 | static char fullProcessName[IU_MODULE_NAME_SIZE_MAX] = { 0 }; 97 | 98 | // Get an executable path. If the function fails, it shall return a value of -1. 99 | const int64_t length = readlink( "/proc/self/exe", fullProcessName, IU_MODULE_NAME_SIZE_MAX ); 100 | 101 | if( length == -1 ) 102 | { 103 | IU_DBG_PRINT( IU_DBG_SEV_ERROR, "Couldn't find an executable, exiting" ); 104 | return NULL; 105 | } 106 | 107 | // Null-terminate the string. 108 | fullProcessName[length == IU_MODULE_NAME_SIZE_MAX ? IU_MODULE_NAME_SIZE_MAX - 1 : length] = '\0'; 109 | 110 | *processName = strrchr( fullProcessName, '/' ) + 1; 111 | 112 | return NULL; 113 | } 114 | 115 | /////////////////////////////////////////////////////////////////////////////// 116 | // 117 | // Group: 118 | // Instrumentation Utils Non-Standard OS Specific Functions 119 | // 120 | // Method: 121 | // IuOsLogGetSystemSettings 122 | // 123 | // Description: 124 | // Reads system-wide instrumentation log settings. 125 | // 126 | // Input: 127 | // void* deviceContext - device context 128 | // bool* assertEnable - (OUT) read AssertEnable value 129 | // uint32_t* logLayerEnable - (OUT) read LogLayerEnable value 130 | // uint32_t* logLevel - (OUT) read LogLevel value 131 | // 132 | /////////////////////////////////////////////////////////////////////////////// 133 | void IuOsLogGetSystemSettings( 134 | [[maybe_unused]] void* deviceContext, 135 | [[maybe_unused]] bool* assertEnable, 136 | [[maybe_unused]] uint32_t* logLayerEnable, 137 | [[maybe_unused]] uint32_t* logLevel ) 138 | { 139 | // To be implemented. 140 | } 141 | 142 | /////////////////////////////////////////////////////////////////////////////// 143 | // 144 | // Group: 145 | // Instrumentation Utils Non-Standard OS Specific Functions 146 | // 147 | // Method: 148 | // IuOsLogGetLocalSettings 149 | // 150 | // Description: 151 | // Reads local instrumentation log settings. 152 | // 153 | // Input: 154 | // bool* assertEnable - (OUT) read AssertEnable value 155 | // uint32_t* logLayerEnable - (OUT) read LogLayerEnable value 156 | // uint32_t* logLevel - (OUT) read LogLevel value 157 | // 158 | /////////////////////////////////////////////////////////////////////////////// 159 | void IuOsLogGetLocalSettings( 160 | bool* assertEnable, 161 | uint32_t* logLayerEnable, 162 | uint32_t* logLevel ) 163 | { 164 | // Get an executable path. If the function fails, it shall return a value of -1. 165 | char filePath[IU_CONFIG_FILE_PATH_SIZE_MAX] = { 0 }; 166 | if( readlink( "/proc/self/exe", filePath, IU_CONFIG_FILE_PATH_SIZE_MAX ) == -1 ) 167 | { 168 | IU_DBG_PRINT( IU_DBG_SEV_ERROR, "Couldn't find an executable, exiting" ); 169 | return; 170 | } 171 | 172 | // Remove an executable filename from the path. 173 | const uint32_t filePathSize = (uint32_t) iu_strnlen_s( filePath, IU_CONFIG_FILE_PATH_SIZE_MAX ); 174 | filePath[IU_CONFIG_FILE_PATH_SIZE_MAX - 1] = '\0'; 175 | 176 | for( uint32_t i = filePathSize; i > 0; --i ) 177 | { 178 | if( filePath[i] == '/' ) 179 | { 180 | filePath[i + 1] = '\0'; 181 | break; 182 | } 183 | } 184 | 185 | // Join the config filename and the path. 186 | const char* fileName = IU_CONFIG_FILE_NAME; 187 | if( !iu_strcat_s( filePath, IU_CONFIG_FILE_PATH_SIZE_MAX, fileName ) ) 188 | { 189 | IU_DBG_PRINT( IU_DBG_SEV_ERROR, "Failed to join the configuration filename and the path, exiting" ); 190 | return; 191 | } 192 | 193 | // Open the config file. 194 | FILE* file = NULL; 195 | if( !iu_fopen_s( &file, filePath, "r" ) || !file ) 196 | { 197 | IU_DBG_PRINT( IU_DBG_SEV_INFO, "Failed to open the configuration file, exiting" ); 198 | return; 199 | } 200 | 201 | // Iterate through the config file. 202 | wchar_t line[IU_CONFIG_FILE_LINE_SIZE_MAX] = { 0 }; 203 | wchar_t name[IU_CONFIG_FILE_LINE_SIZE_MAX] = { 0 }; 204 | wchar_t stringValue[IU_CONFIG_FILE_LINE_SIZE_MAX] = { 0 }; 205 | uint32_t intValue = 0; 206 | while( fgetws( line, IU_CONFIG_FILE_LINE_SIZE_MAX, file ) ) 207 | { 208 | // Find a config name and its value. 209 | if( swscanf( line, IU_CONFIG_FILE_LINE_LAYOUT, name, stringValue ) == 2 ) 210 | { 211 | // Convert the string literal to an unsigned integer. 212 | intValue = wcstoul( stringValue, NULL, 16 ); 213 | 214 | // If the config name matches one of the globally defined config names, assign its value to it. 215 | if( wcscmp( name, IU_CONFIG_NAME_ASSERT_ENABLE ) == 0 ) 216 | { 217 | *assertEnable = ( intValue > 0 ) ? true : false; 218 | } 219 | else if( wcscmp( name, IU_CONFIG_NAME_LOG_LAYER_ENABLE ) == 0 ) 220 | { 221 | *logLayerEnable = intValue; 222 | } 223 | else if( wcscmp( name, IU_CONFIG_NAME_LOG_LEVEL ) == 0 ) 224 | { 225 | *logLevel = intValue; 226 | } 227 | } 228 | } 229 | 230 | fclose( file ); 231 | file = NULL; 232 | } 233 | 234 | } // extern "C" 235 | -------------------------------------------------------------------------------- /libigdml.pc.in: -------------------------------------------------------------------------------- 1 | /*========================== begin_copyright_notice ============================ 2 | 3 | Copyright (C) 2020-2024 Intel Corporation 4 | 5 | SPDX-License-Identifier: MIT 6 | 7 | ============================= end_copyright_notice ===========================*/ 8 | 9 | prefix=@CMAKE_INSTALL_PREFIX@ 10 | libdir=@CMAKE_INSTALL_FULL_LIBDIR@ 11 | includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ 12 | 13 | Name: @LIB_NAME@ 14 | Description: Metrics Library for Intel(R) Metrics Discovery API 15 | Version: @LIB_VERSION@ 16 | 17 | Libs: -L${libdir} -l@LIB@ 18 | Cflags: -I${includedir} 19 | -------------------------------------------------------------------------------- /ml_cmake_adapter.cmake: -------------------------------------------------------------------------------- 1 | #=========================== begin_copyright_notice ============================ 2 | # 3 | # Copyright (C) 2020-2024 Intel Corporation 4 | # 5 | # SPDX-License-Identifier: MIT 6 | # 7 | #============================ end_copyright_notice ============================= 8 | 9 | ################################################################################# 10 | # HELPER FUNCTIONS 11 | ################################################################################# 12 | 13 | ################################################################################# 14 | # clearInputVariables 15 | # Clears cached Metrics Library input cmake variables. Needed for e.g. the below command scenario: 16 | # 1. cmake -DCMAKE_BUILD_TYPE=release -DML_ARCH=32 -> ML_ARCH specified to 32 17 | # 2. cmake -DCMAKE_BUILD_TYPE=release -> default ML_ARCH value should be used, 18 | # but without clearing, it will be still ML_ARCH=32 19 | ################################################################################# 20 | function (clearInputVariables) 21 | unset (CMAKE_BUILD_TYPE CACHE) 22 | unset (ML_ARCH CACHE) 23 | endfunction () 24 | 25 | ################################################################################# 26 | # errorExit 27 | # Clears cached input variables and displays the given error message. 28 | ################################################################################# 29 | function (errorExit message) 30 | clearInputVariables () 31 | message (FATAL_ERROR ${message}) 32 | endfunction () 33 | 34 | ################################################################################# 35 | # ADAPTER 36 | ################################################################################# 37 | 38 | if (${CMAKE_VERBOSE_MAKEFILE} STREQUAL ON) 39 | message ("INFO: Input CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}") 40 | message ("INFO: Input ML_ARCH = ${ML_ARCH}") 41 | endif() 42 | 43 | # PLATFORM 44 | if (CMAKE_SYSTEM_NAME STREQUAL "Linux") 45 | set(PLATFORM "linux") 46 | else() 47 | errorExit("ERROR: Project isn't targeted for ${CMAKE_SYSTEM_NAME}. Please run CMake on Linux.") 48 | endif() 49 | 50 | # BUILD_TYPE 51 | if (NOT CMAKE_BUILD_TYPE) 52 | set (CMAKE_BUILD_TYPE "release") 53 | else () 54 | string (TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE) 55 | if (NOT (CMAKE_BUILD_TYPE STREQUAL "release" OR 56 | CMAKE_BUILD_TYPE STREQUAL "release-internal" OR 57 | CMAKE_BUILD_TYPE STREQUAL "releaseinternal" OR 58 | CMAKE_BUILD_TYPE STREQUAL "debug")) 59 | errorExit("ERROR: Specify correct CMAKE_BUILD_TYPE (-DCMAKE_BUILD_TYPE=Release|Release-Internal|ReleaseInternal|Debug)") 60 | endif () 61 | endif () 62 | 63 | # HOST ARCH 64 | if (CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64") # 64 bits Linux 65 | set (HOST_ARCH "64") 66 | else () # 32 bits Linux 67 | set (HOST_ARCH "32") 68 | endif () 69 | 70 | # TARGET ARCH 71 | if (ML_ARCH) 72 | # User defines ARCH through custom variable 73 | if (ML_ARCH STREQUAL "32" OR ML_ARCH STREQUAL "64") 74 | set (TARGET_ARCH ${ML_ARCH}) 75 | else () 76 | errorExit("ERROR: Specify correct ML_ARCH (-DML_ARCH=64|32).") 77 | endif () 78 | else () 79 | # User defines ARCH through compiler flags 80 | set (TARGET_ARCH "64") # 64 bits by default 81 | if (CMAKE_SIZEOF_VOID_P EQUAL 4) 82 | set (TARGET_ARCH "32") 83 | endif () 84 | endif () 85 | 86 | message ("-- using TARGET_ARCH = ${TARGET_ARCH}") 87 | 88 | if (TARGET_ARCH STREQUAL "32") 89 | message ("-- !! Compiling 32bit on 64bit host requires gcc (g++) in multilib version !!") 90 | message (" e.g. sudo apt-get install gcc-4.8-multilib g++-4.8-multilib") 91 | endif () 92 | 93 | # PATHS 94 | set (BS_DIR_INSTRUMENTATION ${CMAKE_CURRENT_SOURCE_DIR}/instrumentation) 95 | set (BS_DIR_INC ${CMAKE_CURRENT_SOURCE_DIR}/inc) 96 | set (BS_DIR_EXTERNAL ${CMAKE_CURRENT_SOURCE_DIR}/external) 97 | set (DUMP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/dump/${PLATFORM}${TARGET_ARCH}/${CMAKE_BUILD_TYPE}/${PROJECT_NAME}) 98 | if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 99 | set (CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "..." FORCE) 100 | endif () 101 | 102 | # OUTPUT 103 | set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${DUMP_DIR}) 104 | set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${DUMP_DIR}) 105 | set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${DUMP_DIR}) 106 | 107 | # Clear input variables to have a 'fresh', non-cached values during next cmake execution 108 | clearInputVariables () 109 | --------------------------------------------------------------------------------