├── .github ├── docker │ ├── rhel.Dockerfile │ ├── sles.Dockerfile │ ├── ubuntu.Dockerfile │ └── windows.Dockerfile └── workflows │ ├── build-msi-package.yml │ ├── build-multi-static.yml │ ├── build-multi.yml │ ├── build-quick-static.yml │ ├── build-quick.yml │ ├── check-abi.yml │ ├── scorecard.yml │ └── update-spec.yml ├── .gitignore ├── CHANGELOG.md ├── CMakeLists.txt ├── CONTRIBUTING.md ├── LICENSE ├── LICENSES ├── Apache-2.0.txt └── MIT.txt ├── PRODUCT_GUID.txt ├── README.md ├── SECURITY.md ├── doc └── loader_api.md ├── icons ├── oneapi-icon-left-aligned.png └── oneapi-icon-right-aligned.png ├── include ├── layers │ ├── zel_tracing_api.h │ ├── zel_tracing_ddi.h │ └── zel_tracing_register_cb.h ├── loader │ └── ze_loader.h ├── ze.py ├── ze_api.h ├── ze_ddi.h ├── ze_ddi_common.h ├── zes.py ├── zes_api.h ├── zes_ddi.h ├── zet.py ├── zet_api.h └── zet_ddi.h ├── os_release_info.cmake ├── samples ├── CMakeLists.txt ├── include │ ├── zello_init.h │ └── zello_log.h └── zello_world │ ├── CMakeLists.txt │ └── zello_world.cpp ├── scripts ├── generate_checker.py ├── generate_code.py ├── generate_wix_guid.py ├── json2src.py ├── level_zero_sdk_setup.ps1 ├── templates │ ├── checker │ │ ├── template.cmake.mako │ │ ├── template.cpp.mako │ │ └── template.h.mako │ ├── ddi.h.mako │ ├── helper.py │ ├── ldrddi.cpp.mako │ ├── ldrddi.h.mako │ ├── libapi.cpp.mako │ ├── libddi.cpp.mako │ ├── nullddi.cpp.mako │ ├── tracing │ │ ├── trc_cb_struct.h.mako │ │ ├── trc_register_cb_libapi.cpp.mako │ │ ├── trc_setters.cpp.mako │ │ ├── trc_setters.h.mako │ │ └── trcddi.cpp.mako │ ├── validation │ │ ├── entry_points.h.mako │ │ ├── handle_lifetime.cpp.mako │ │ ├── handle_lifetime.h.mako │ │ ├── param.cpp.mako │ │ ├── param.h.mako │ │ └── valddi.cpp.mako │ └── ze_loader_internal.h.mako ├── util.py └── wix_env_installation.wxs ├── source ├── CMakeLists.txt ├── ZeLoaderVersion.rc.in ├── drivers │ ├── CMakeLists.txt │ └── null │ │ ├── CMakeLists.txt │ │ ├── ze_null.cpp │ │ ├── ze_null.h │ │ ├── ze_nullddi.cpp │ │ ├── zes_nullddi.cpp │ │ └── zet_nullddi.cpp ├── inc │ ├── ze_singleton.h │ └── ze_util.h ├── layers │ ├── CMakeLists.txt │ ├── tracing │ │ ├── CMakeLists.txt │ │ ├── README.md │ │ ├── ZeTracingLayerVersion.rc.in │ │ ├── linux │ │ │ └── tracing_init.cpp │ │ ├── tracing.h │ │ ├── tracing_imp.cpp │ │ ├── tracing_imp.h │ │ ├── windows │ │ │ └── tracing_init.cpp │ │ ├── ze_tracing.cpp │ │ ├── ze_tracing_cb_structs.h │ │ ├── ze_tracing_layer.cpp │ │ ├── ze_tracing_layer.h │ │ ├── ze_tracing_register_cb.cpp │ │ └── ze_trcddi.cpp │ └── validation │ │ ├── CMakeLists.txt │ │ ├── CONTRIBUTING.md │ │ ├── README.md │ │ ├── ZeValidationLayerVersion.rc.in │ │ ├── checkers │ │ ├── CMakeLists.txt │ │ ├── basic_leak │ │ │ ├── CMakeLists.txt │ │ │ ├── zel_basic_leak_checker.cpp │ │ │ └── zel_basic_leak_checker.h │ │ ├── events_checker │ │ │ ├── CMakeLists.txt │ │ │ ├── DESIGN.md │ │ │ ├── zel_events_checker.cpp │ │ │ └── zel_events_checker.h │ │ ├── parameter_validation │ │ │ ├── CMakeLists.txt │ │ │ ├── extension_validation.inl │ │ │ ├── param_validation.h │ │ │ ├── ze_parameter_validation.cpp │ │ │ ├── ze_parameter_validation.h │ │ │ ├── zes_parameter_validation.cpp │ │ │ ├── zes_parameter_validation.h │ │ │ ├── zet_parameter_validation.cpp │ │ │ └── zet_parameter_validation.h │ │ └── template │ │ │ ├── CMakeLists.txt │ │ │ ├── zel_template_checker.cpp │ │ │ └── zel_template_checker.h │ │ ├── common │ │ ├── ze_entry_points.h │ │ ├── zes_entry_points.h │ │ └── zet_entry_points.h │ │ ├── handle_lifetime_tracking │ │ ├── CMakeLists.txt │ │ ├── handle_lifetime.h │ │ ├── ze_handle_lifetime.cpp │ │ ├── ze_handle_lifetime.h │ │ ├── zes_handle_lifetime.cpp │ │ ├── zes_handle_lifetime.h │ │ ├── zet_handle_lifetime.cpp │ │ └── zet_handle_lifetime.h │ │ ├── ze_valddi.cpp │ │ ├── ze_validation_layer.cpp │ │ ├── ze_validation_layer.h │ │ ├── zes_valddi.cpp │ │ └── zet_valddi.cpp ├── level-zero.pc.in ├── lib │ ├── CMakeLists.txt │ ├── linux │ │ └── lib_init.cpp │ ├── windows │ │ └── lib_init.cpp │ ├── ze_lib.cpp │ ├── ze_lib.h │ ├── ze_libapi.cpp │ ├── ze_libddi.cpp │ ├── ze_tracing_register_cb_libapi.cpp │ ├── zel_tracing_libapi.cpp │ ├── zel_tracing_libddi.cpp │ ├── zes_libapi.cpp │ ├── zes_libddi.cpp │ ├── zet_libapi.cpp │ └── zet_libddi.cpp ├── libze_loader.pc.in ├── loader │ ├── CMakeLists.txt │ ├── driver_discovery.h │ ├── linux │ │ ├── driver_discovery_lin.cpp │ │ └── loader_init.cpp │ ├── windows │ │ ├── driver_discovery_win.cpp │ │ └── loader_init.cpp │ ├── ze_ldrddi.cpp │ ├── ze_ldrddi.h │ ├── ze_loader.cpp │ ├── ze_loader_api.cpp │ ├── ze_loader_api.h │ ├── ze_loader_internal.h │ ├── ze_object.h │ ├── zel_tracing_ldrddi.cpp │ ├── zes_ldrddi.cpp │ ├── zes_ldrddi.h │ ├── zet_ldrddi.cpp │ └── zet_ldrddi.h └── utils │ ├── CMakeLists.txt │ ├── logging.cpp │ └── logging.h ├── test ├── CMakeLists.txt ├── loader_api.cpp └── loader_validation_layer.cpp └── third_party ├── spdlog_headers ├── .version ├── LICENSE ├── README.md └── spdlog │ ├── common-inl.h │ ├── common.h │ ├── details │ ├── backtracer-inl.h │ ├── backtracer.h │ ├── circular_q.h │ ├── console_globals.h │ ├── file_helper-inl.h │ ├── file_helper.h │ ├── fmt_helper.h │ ├── log_msg-inl.h │ ├── log_msg.h │ ├── log_msg_buffer-inl.h │ ├── log_msg_buffer.h │ ├── null_mutex.h │ ├── os-inl.h │ ├── os.h │ ├── periodic_worker-inl.h │ ├── periodic_worker.h │ ├── registry-inl.h │ ├── registry.h │ ├── synchronous_factory.h │ └── windows_include.h │ ├── fmt │ ├── bundled │ │ ├── core.h │ │ ├── format-inl.h │ │ └── format.h │ └── fmt.h │ ├── formatter.h │ ├── logger-inl.h │ ├── logger.h │ ├── mdc.h │ ├── pattern_formatter-inl.h │ ├── pattern_formatter.h │ ├── sinks │ ├── ansicolor_sink-inl.h │ ├── ansicolor_sink.h │ ├── base_sink-inl.h │ ├── base_sink.h │ ├── basic_file_sink-inl.h │ ├── basic_file_sink.h │ ├── sink-inl.h │ ├── sink.h │ ├── wincolor_sink-inl.h │ └── wincolor_sink.h │ ├── spdlog-inl.h │ ├── spdlog.h │ ├── tweakme.h │ └── version.h └── xla ├── LICENSE ├── README.md ├── graphcycles.cc ├── graphcycles.h └── ordered_set.h /.github/docker/rhel.Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1.4 2 | 3 | ARG VMAJ 4 | ARG VMIN 5 | 6 | FROM ghcr.io/oneapi-src/level-zero-linux-compute/rhel:${VMAJ}.${VMIN} 7 | 8 | SHELL ["/bin/bash", "-e", "-c"] -------------------------------------------------------------------------------- /.github/docker/sles.Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1.4 2 | 3 | ARG VMAJ 4 | ARG VMIN 5 | 6 | FROM ghcr.io/oneapi-src/level-zero-linux-compute/sles:${VMAJ}.${VMIN} 7 | 8 | SHELL ["/bin/bash", "-e", "-c"] -------------------------------------------------------------------------------- /.github/docker/ubuntu.Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1.4 2 | 3 | ARG VMAJ 4 | ARG VMIN 5 | FROM ghcr.io/oneapi-src/level-zero-linux-compute/ubuntu:${VMAJ}.${VMIN} 6 | 7 | ARG VMAJ 8 | ARG VMIN 9 | 10 | SHELL ["/bin/bash", "-e", "-c"] 11 | 12 | RUN <> /etc/apt/sources.list <> /etc/apt/sources.list.d/ubuntu.sources <(wc -l) >&2) == 0)); then 73 | echo "::warning::No changes were made to files" 74 | else 75 | git config user.email "sys-lzdev@intel.com" 76 | git config user.name "sys-lzdev" 77 | spec_ver=$(sed -n 's/^.*version v.*-r\([0-9]*\.[0-9]*\.[0-9]*\)/\1/p' include/ze_api.h) 78 | git add -u 79 | git commit -m "Update to spec ${spec_ver}" 80 | fi 81 | - name: Push changes to develop branch 82 | if: ${{ github.event_name == 'workflow_dispatch' }} 83 | run: git push origin ${{ inputs.branch }} -f 84 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | /scripts/__pycache__/ 3 | /scripts/templates/__pycache__/ 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (C) 2019-2021 Intel Corporation 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | 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 THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /LICENSES/MIT.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (C) 2019-2025 Intel Corporation 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | 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 THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /PRODUCT_GUID.txt: -------------------------------------------------------------------------------- 1 | 1.22.4 2 | 55e69860-8ae7-4f60-8ad9-728c1ed2a2e7 -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Report a Vulnerability 4 | 5 | Please report security issues or vulnerabilities to the [Intel Security Center]. 6 | 7 | For more information on how Intel works to resolve security issues, see [Vulnerability Handling Guidelines]. 8 | 9 | [Intel Security Center]:https://www.intel.com/security 10 | 11 | [Vulnerability Handling Guidelines]:https://www.intel.com/content/www/us/en/security-center/vulnerability-handling-guidelines.html 12 | -------------------------------------------------------------------------------- /doc/loader_api.md: -------------------------------------------------------------------------------- 1 | # Level Zero Loader APIs 2 | 3 | ## Introduction 4 | The Level Zero Loader will expose some additional APIs beyond what is defined in the Level Zero spec. The purpose of these APIs will generally be to access and set various loader configuration components. 5 | 6 | This document does not cover APIs specific to individual layers (ie. tracing) or APIs defined in the Level Zero spec. 7 | 8 | ## API Reference 9 | 10 | Exposed Loader APIs will be defined in header files located in this repository at `include/loader`, and installed to `/include/level_zero/loader` 11 | 12 | ### zelLoaderGetVersions 13 | 14 | This API is used to retreive the version information of the loader itself and of any layers that are enabled. 15 | 16 | - __*num_elems__ Is a pointer to the number of version components to get. 17 | - __*versions__ Pointer to address to write version components to. If set to `nullptr`, `num_elems` will be set to the total number of version components available. 18 | 19 | There are currently 3 versioned components assigned the following name strings: 20 | - `"tracing layer"` 21 | - `"validation layer"` 22 | - `"loader"` 23 | 24 | 25 | ### zelLoaderTranslateHandle 26 | 27 | When a system has multiple L0 drivers, raw handles returned from the L0 drivers are modified by the loader before being returned to the application. This allows the loader to determine which handles belong to which driver and forward API calls appropriately. In most cases the loader will perform this handle translation completely transparently to the application and no manual translation is ever needed. 28 | 29 | In some rare cases when the application needs to occasionally bypass the loader, handle conflicts can arise. One such case is when an application wants to call a driver extension function whose address has been retreived with `zeDriverGetExtensionFunctionAddress` 30 | 31 | To solve this issue, `zelLoaderTranslateHandle` is used to retrieve the raw driver handle associated with a loader handle. 32 | 33 | - __handleType__ Type of the L0 handle to translate 34 | - __*handleIn__ Input handle to translate 35 | - __**handleOut__ Output location to store the translated handle 36 | 37 | 38 | ### zelEnableTracingLayer 39 | 40 | When a user wants to enable the Tracing Layer for API Tracing, one usually set `ZE_ENABLE_TRACING_LAYER=1` before the call to zeInit(), however if one wanted to enable and disable tracing during runtime, the only way previously would be to enable tracing with the tracers disabled. This causes a performance hit due to the tracing layer intercepts. 41 | 42 | To resolve this, the tracing layer additionally can be enabled thru this new api `zelEnableTracingLayer`. This will enable the api tracing layer until the program exits or the user calls `zelDisableTracingLayer`. 43 | 44 | This call enables the tracing layer for all calls to the Loader after this call completes for all initialized drivers. 45 | 46 | ### zelDisableTracingLayer 47 | 48 | Disables the tracing layer intercepts at runtime by restoring the previous call path thru the loader before tracing was enabled. 49 | 50 | This does not unload the tracing layer library such that one can call `zelEnableTracingLayer` and `zelDisableTracingLayer` as many times one needs to during the application. 51 | 52 | NOTE: The each call to `zelEnableTracingLayer` tracks a reference count of how many calls to enable have been seen. The Tracing Layer intercepts will not be removed until the reference count has reached 0 indicating that all users of the tracing layer have called `zelDisableTracingLayer`. 53 | -------------------------------------------------------------------------------- /icons/oneapi-icon-left-aligned.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oneapi-src/level-zero/e3b6efdd91d67bb03024b266094afabd39e213bf/icons/oneapi-icon-left-aligned.png -------------------------------------------------------------------------------- /icons/oneapi-icon-right-aligned.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/oneapi-src/level-zero/e3b6efdd91d67bb03024b266094afabd39e213bf/icons/oneapi-icon-right-aligned.png -------------------------------------------------------------------------------- /include/layers/zel_tracing_ddi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Intel Corporation 3 | * 4 | * SPDX-License-Identifier: MIT 5 | * 6 | * @file zel_tracing_ddi.h 7 | * 8 | * This file has been manually generated. 9 | * There is no "spec" for this loader layer "tracer" API. 10 | */ 11 | 12 | #ifndef _ZEL_TRACING_DDI_H 13 | #define _ZEL_TRACING_DDI_H 14 | #if defined(__cplusplus) 15 | #pragma once 16 | #endif 17 | #include "layers/zel_tracing_api.h" 18 | 19 | #if defined(__cplusplus) 20 | extern "C" { 21 | #endif 22 | 23 | /////////////////////////////////////////////////////////////////////////////// 24 | /// @brief Function-pointer for zelTracerCreate 25 | typedef ze_result_t (ZE_APICALL *zel_pfnTracerCreate_t)( 26 | const zel_tracer_desc_t*, 27 | zel_tracer_handle_t* 28 | ); 29 | 30 | /////////////////////////////////////////////////////////////////////////////// 31 | /// @brief Function-pointer for zetTracerDestroy 32 | typedef ze_result_t (ZE_APICALL *zel_pfnTracerDestroy_t)( 33 | zel_tracer_handle_t 34 | ); 35 | 36 | /////////////////////////////////////////////////////////////////////////////// 37 | /// @brief Function-pointer for zetTracerSetPrologues 38 | typedef ze_result_t (ZE_APICALL *zel_pfnTracerSetPrologues_t)( 39 | zel_tracer_handle_t, 40 | zel_core_callbacks_t* 41 | ); 42 | 43 | /////////////////////////////////////////////////////////////////////////////// 44 | /// @brief Function-pointer for zetTracerSetEpilogues 45 | typedef ze_result_t (ZE_APICALL *zel_pfnTracerSetEpilogues_t)( 46 | zel_tracer_handle_t, 47 | zel_core_callbacks_t* 48 | ); 49 | 50 | /////////////////////////////////////////////////////////////////////////////// 51 | /// @brief Function-pointer for zetTracerSetEnabled 52 | typedef ze_result_t (ZE_APICALL *zel_pfnTracerSetEnabled_t)( 53 | zel_tracer_handle_t, 54 | ze_bool_t 55 | ); 56 | 57 | 58 | /////////////////////////////////////////////////////////////////////////////// 59 | /// @brief Table of Tracer functions pointers 60 | typedef struct _zel_tracer_dditable_t 61 | { 62 | zel_pfnTracerCreate_t pfnCreate; 63 | zel_pfnTracerDestroy_t pfnDestroy; 64 | zel_pfnTracerSetPrologues_t pfnSetPrologues; 65 | zel_pfnTracerSetEpilogues_t pfnSetEpilogues; 66 | zel_pfnTracerSetEnabled_t pfnSetEnabled; 67 | } zel_tracer_dditable_t; 68 | 69 | 70 | /////////////////////////////////////////////////////////////////////////////// 71 | /// @brief Exported function for filling application's Tracer table 72 | /// with current process' addresses 73 | /// 74 | /// @returns 75 | /// - ::ZE_RESULT_SUCCESS 76 | /// - ::ZE_RESULT_ERROR_UNINITIALIZED 77 | /// - ::ZE_RESULT_ERROR_INVALID_NULL_POINTER 78 | /// - ::ZE_RESULT_ERROR_UNSUPPORTED_VERSION 79 | ZE_DLLEXPORT ze_result_t ZE_APICALL 80 | zelGetTracerApiProcAddrTable( 81 | ze_api_version_t version, ///< [in] API version requested 82 | zel_tracer_dditable_t* pDdiTable ///< [in,out] pointer to table of DDI function pointers 83 | ); 84 | 85 | /////////////////////////////////////////////////////////////////////////////// 86 | /// @brief Function-pointer for zelGetTracerApiProcAddrTable 87 | typedef ze_result_t (ZE_APICALL *zel_pfnGetTracerApiProcAddrTable_t)( 88 | ze_api_version_t, 89 | zel_tracer_dditable_t* 90 | ); 91 | 92 | /////////////////////////////////////////////////////////////////////////////// 93 | /// @brief Container for tracing DDI tables 94 | typedef struct _zel_tracing_dditable_t 95 | { 96 | zel_tracer_dditable_t Tracer; 97 | } zel_tracing_dditable_t; 98 | 99 | #if defined(__cplusplus) 100 | } // extern "C" 101 | #endif 102 | 103 | #endif // _ZEL_TRACING_DDI_H 104 | -------------------------------------------------------------------------------- /include/ze_ddi_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2024 Intel Corporation 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * @file ze_ddi_common.h 8 | * @version v1.13-r1.13.1 9 | * 10 | */ 11 | #ifndef _ZE_DDI_COMMON_H 12 | #define _ZE_DDI_COMMON_H 13 | #if defined(__cplusplus) 14 | #pragma once 15 | #endif 16 | #include "ze_ddi.h" 17 | #include "zet_ddi.h" 18 | #include "zes_ddi.h" 19 | 20 | #if defined(__cplusplus) 21 | extern "C" { 22 | #endif 23 | 24 | /// @brief Handle with pointers to Dispatch Tables allocated by the driver at the beginning of every L0 object handle. 25 | typedef struct _ze_handle_t 26 | { 27 | ze_dditable_driver_t *pCore; // [in] pointer to _ze_dditable_t_ object related to this handle 28 | zet_dditable_driver_t *pTools; // [in] pointer to _zet_dditable_t_ object related to this handle 29 | zes_dditable_driver_t *pSysman; // [in] pointer to _zes_dditable_t_ object related to this handle 30 | } ze_handle_t; 31 | 32 | #if defined(__cplusplus) 33 | } // extern "C" 34 | #endif 35 | 36 | #endif // _ZE_DDI_COMMON_H -------------------------------------------------------------------------------- /samples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) 2 | 3 | add_subdirectory(zello_world) 4 | -------------------------------------------------------------------------------- /samples/zello_world/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(TARGET_NAME zello_world) 2 | 3 | add_executable(${TARGET_NAME} 4 | ${CMAKE_CURRENT_SOURCE_DIR}/zello_world.cpp 5 | ) 6 | 7 | if(MSVC) 8 | set_target_properties(${TARGET_NAME} 9 | PROPERTIES 10 | VS_DEBUGGER_COMMAND_ARGUMENTS "" 11 | VS_DEBUGGER_WORKING_DIRECTORY "$(OutDir)" 12 | ) 13 | endif() 14 | 15 | target_link_libraries(${TARGET_NAME} PRIVATE 16 | ${TARGET_LOADER_NAME} 17 | ${CMAKE_DL_LIBS} 18 | ) 19 | -------------------------------------------------------------------------------- /scripts/generate_checker.py: -------------------------------------------------------------------------------- 1 | """ 2 | Copyright (C) 2024 Intel Corporation 3 | 4 | SPDX-License-Identifier: MIT 5 | 6 | """ 7 | import os 8 | import re 9 | import util 10 | import argparse 11 | 12 | templates_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "templates/checker/") 13 | 14 | """ 15 | generates checker files from the templates 16 | """ 17 | if __name__ == '__main__': 18 | parser = argparse.ArgumentParser() 19 | parser.add_argument("name", type=str, help="Name of your Validation Layer checker in the form of 'CheckerName'.") 20 | parser.add_argument("out_dir", type=str, help="Root of the loader repository.") 21 | args = parser.parse_args() 22 | name = args.name 23 | env_name = name.upper() 24 | srcpath = os.path.join(args.out_dir, "source/layers/validation/checkers/") 25 | srcpath = os.path.join(srcpath, name) 26 | if not os.path.exists(srcpath): 27 | os.makedirs(srcpath) 28 | print("Generating Checker Template for %s\n" %(name)) 29 | loc = 0 30 | template = "template.h.mako" 31 | fin = os.path.join(templates_dir, template) 32 | 33 | filename = "zel_%s_checker.h"%(name) 34 | fout = os.path.join(srcpath, filename) 35 | 36 | print("Generating %s..."%fout) 37 | loc += util.makoWrite( 38 | fin, fout, 39 | name=name) 40 | 41 | template = "template.cpp.mako" 42 | fin = os.path.join(templates_dir, template) 43 | 44 | filename = "zel_%s_checker.cpp"%(name) 45 | fout = os.path.join(srcpath, filename) 46 | 47 | print("Generating %s..."%fout) 48 | loc += util.makoWrite( 49 | fin, fout, 50 | name=name, 51 | env_name=env_name) 52 | 53 | template = "template.cmake.mako" 54 | fin = os.path.join(templates_dir, template) 55 | 56 | filename = "CMakeLists.txt" 57 | fout = os.path.join(srcpath, filename) 58 | 59 | print("Generating %s..."%fout) 60 | loc += util.makoWrite( 61 | fin, fout, 62 | name=name, 63 | TARGET_NAME="${TARGET_NAME}", 64 | CMAKE_CURRENT_LIST_DIR="${CMAKE_CURRENT_LIST_DIR}") -------------------------------------------------------------------------------- /scripts/generate_wix_guid.py: -------------------------------------------------------------------------------- 1 | """ 2 | Copyright (C) 2025 Intel Corporation 3 | 4 | SPDX-License-Identifier: MIT 5 | 6 | """ 7 | import uuid 8 | print(str(uuid.uuid4())) -------------------------------------------------------------------------------- /scripts/level_zero_sdk_setup.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | Copyright (C) 2025 Intel Corporation 3 | SPDX-License-Identifier: MIT 4 | #> 5 | 6 | param ( 7 | [string]$sdkVersion, 8 | [string]$installPath, 9 | [string]$removeSdkEnvVar 10 | ) 11 | 12 | if ($removeSdkEnvVar) { 13 | if ($removeSdkEnvVar -eq "1" -or $removeSdkEnvVar -eq "true") { 14 | Write-Output "true" 15 | $removeSdkEnvVarValue = $true 16 | } elseif ($removeSdkEnvVar -eq "0" -or $removeSdkEnvVar -eq "false") { 17 | $removeSdkEnvVarValue = $false 18 | } else { 19 | Write-Error "Invalid value for 'removeSdkEnvVar'. Must be a boolean value 0,1,true,false." 20 | Write-Output "Usage: .\level_zero_sdk_setup.ps1 -sdkVersion 1.21.1 -installPath C:\ -removeSdkEnvVar 1" 21 | exit 1 22 | } 23 | } else { 24 | $removeSdkEnvVarValue = $false 25 | } 26 | 27 | if (-not $sdkVersion) { 28 | Write-Error "Parameter 'sdkVersion' is required. Example: 1.21.1" 29 | Write-Output "Usage: .\level_zero_sdk_setup.ps1 -sdkVersion 1.21.1 -installPath C:\ -[optional]removeSdkEnvVar 1" 30 | Write-Output "Usage: .\level_zero_sdk_setup.ps1 -sdkVersion 1.21.1 -installPath C:\" 31 | exit 1 32 | } 33 | 34 | if (-not $installPath) { 35 | Write-Error "Parameter 'installPath' is required. Example: C:\Users\user\LevelZeroSDK, where LevelZeroSDK is the root directory. Default is SYSTEM_DRIVE:\" 36 | Write-Output "Usage: .\level_zero_sdk_setup.ps1 -sdkVersion 1.21.1 -installPath C:\Users\user\LevelZeroSDK -[optional]removeSdkEnvVar 1" 37 | Write-Output "Usage: .\level_zero_sdk_setup.ps1 -sdkVersion 1.21.1 -installPath C:\Users\user\LevelZeroSDK" 38 | exit 1 39 | } 40 | 41 | # Update or set the LEVEL_ZERO_SDK_V_PATH environment variable 42 | $majorVersion = $sdkVersion.Split('.')[0] 43 | $envVarName = "LEVEL_ZERO_V${majorVersion}_SDK_PATH" 44 | 45 | if ($removeSdkEnvVarValue -eq $true) { 46 | if (-not [System.Environment]::GetEnvironmentVariable($envVarName, [System.EnvironmentVariableTarget]::Machine)) { 47 | Write-Error "Environment variable does not exist: $envVarName" 48 | exit 1 49 | } 50 | [System.Environment]::SetEnvironmentVariable($envVarName, $null, [System.EnvironmentVariableTarget]::Machine) 51 | Write-Output "Environment variable removed: $envVarName" 52 | } else { 53 | # Define the paths 54 | $sdkPath = Join-Path -Path $installPath -ChildPath "LevelZeroSDK\$sdkVersion\" 55 | 56 | # Check if the SDK path exists 57 | if (-not (Test-Path -Path $sdkPath)) { 58 | Write-Error "The Level Zero SDK path '$sdkPath' does not exist." 59 | exit 1 60 | } 61 | $currentEnvPath = [System.Environment]::GetEnvironmentVariable($envVarName, [System.EnvironmentVariableTarget]::Machine) 62 | if ($null -eq $currentEnvPath -or $currentEnvPath -notcontains $sdkPath) { 63 | [System.Environment]::SetEnvironmentVariable($envVarName, $sdkPath, [System.EnvironmentVariableTarget]::Machine) 64 | } 65 | Write-Output "Level Zero SDK Path Setup completed successfully." 66 | Write-Output "Environment variable changed: $envVarName" 67 | Write-Output "Updated SDK Version: $sdkVersion" 68 | Write-Output "Updated SDK Path: $sdkPath" 69 | } -------------------------------------------------------------------------------- /scripts/templates/checker/template.cmake.mako: -------------------------------------------------------------------------------- 1 | target_sources(${TARGET_NAME} 2 | PRIVATE 3 | ${CMAKE_CURRENT_LIST_DIR}/zel_${name}_checker.h 4 | ${CMAKE_CURRENT_LIST_DIR}/zel_${name}_checker.cpp 5 | ) -------------------------------------------------------------------------------- /scripts/templates/checker/template.cpp.mako: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2024 Intel Corporation 3 | * 4 | * SPDX-License-Identifier: MIT 5 | * 6 | * @file zel_${name}_checker.cpp 7 | * 8 | */ 9 | #include "zel_${name}_checker.h" 10 | 11 | namespace validation_layer 12 | { 13 | class ${name}Checker ${name}_checker; 14 | 15 | ${name}Checker::${name}Checker() { 16 | enable${name} = getenv_tobool( "ZEL_ENABLE_${env_name}_CHECKER" ); 17 | if(enable${name}) { 18 | ${name}Checker::ZE${name}Checker *zeChecker = new ${name}Checker::ZE${name}Checker; 19 | ${name}Checker::ZES${name}Checker *zesChecker = new ${name}Checker::ZES${name}Checker; 20 | ${name}Checker::ZET${name}Checker *zetChecker = new ${name}Checker::ZET${name}Checker; 21 | ${name}_checker.zeValidation = zeChecker; 22 | ${name}_checker.zetValidation = zetChecker; 23 | ${name}_checker.zesValidation = zesChecker; 24 | validation_layer::context.validationHandlers.push_back(&${name}_checker); 25 | } 26 | } 27 | 28 | ${name}Checker::~${name}Checker() { 29 | if(enable${name}) { 30 | delete ${name}_checker.zeValidation; 31 | delete ${name}_checker.zetValidation; 32 | delete ${name}_checker.zesValidation; 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /scripts/templates/checker/template.h.mako: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2024 Intel Corporation 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * @file zel_${name}_checker.h 8 | * 9 | */ 10 | 11 | #pragma once 12 | 13 | #include 14 | #include "ze_api.h" 15 | #include "ze_validation_layer.h" 16 | 17 | namespace validation_layer 18 | { 19 | class __zedlllocal ${name}Checker : public validationChecker{ 20 | public: 21 | ${name}Checker(); 22 | ~${name}Checker(); 23 | 24 | class ZE${name}Checker : public ZEValidationEntryPoints {}; 25 | class ZES${name}Checker : public ZESValidationEntryPoints {}; 26 | class ZET${name}Checker : public ZETValidationEntryPoints {}; 27 | bool enable${name} = false; 28 | }; 29 | extern class ${name}Checker ${name}_checker; 30 | } -------------------------------------------------------------------------------- /scripts/templates/ddi.h.mako: -------------------------------------------------------------------------------- 1 | <% 2 | import re 3 | from templates import helper as th 4 | %><% 5 | n=namespace 6 | N=n.upper() 7 | 8 | x=tags['$x'] 9 | X=x.upper() 10 | %>/* 11 | * 12 | * Copyright (C) 2019-2024 Intel Corporation 13 | * 14 | * SPDX-License-Identifier: MIT 15 | * 16 | * @file ${n}_ddi.h 17 | * 18 | */ 19 | #ifndef _${N}_DDI_H 20 | #define _${N}_DDI_H 21 | #if defined(__cplusplus) 22 | #pragma once 23 | #endif 24 | #include "${n}_api.h" 25 | 26 | #if defined(__cplusplus) 27 | extern "C" { 28 | #endif 29 | 30 | %for tbl in th.get_pfntables(specs, meta, n, tags): 31 | %for obj in tbl['functions']: 32 | /////////////////////////////////////////////////////////////////////////////// 33 | /// @brief Function-pointer for ${th.make_func_name(n, tags, obj)} 34 | %if 'condition' in obj: 35 | #if ${th.subt(n, tags, obj['condition'])} 36 | %endif 37 | typedef ${x}_result_t (${X}_APICALL *${th.make_pfn_type(n, tags, obj)})( 38 | %for line in th.make_param_lines(n, tags, obj, format=["type", "delim"]): 39 | ${line} 40 | %endfor 41 | ); 42 | %if 'condition' in obj: 43 | #endif // ${th.subt(n, tags, obj['condition'])} 44 | %endif 45 | 46 | %endfor 47 | /////////////////////////////////////////////////////////////////////////////// 48 | /// @brief Table of ${tbl['name']} functions pointers 49 | typedef struct _${tbl['type']} 50 | { 51 | %for obj in tbl['functions']: 52 | %if 'condition' in obj: 53 | #if ${th.subt(n, tags, obj['condition'])} 54 | %endif 55 | ${th.append_ws(th.make_pfn_type(n, tags, obj), 59)} ${th.make_pfn_name(n, tags, obj)}; 56 | %if 'condition' in obj: 57 | #else 58 | ${th.append_ws("void*", 59)} ${th.make_pfn_name(n, tags, obj)}; 59 | #endif // ${th.subt(n, tags, obj['condition'])} 60 | %endif 61 | %endfor 62 | } ${tbl['type']}; 63 | 64 | /////////////////////////////////////////////////////////////////////////////// 65 | /// @brief Exported function for filling application's ${tbl['name']} table 66 | /// with current process' addresses 67 | /// 68 | /// @returns 69 | /// - ::${X}_RESULT_SUCCESS 70 | /// - ::${X}_RESULT_ERROR_UNINITIALIZED 71 | /// - ::${X}_RESULT_ERROR_INVALID_NULL_POINTER 72 | /// - ::${X}_RESULT_ERROR_UNSUPPORTED_VERSION 73 | ${X}_DLLEXPORT ${x}_result_t ${X}_APICALL 74 | ${tbl['export']['name']}( 75 | %for line in th.make_param_lines(n, tags, tbl['export']): 76 | ${line} 77 | %endfor 78 | ); 79 | 80 | /////////////////////////////////////////////////////////////////////////////// 81 | /// @brief Function-pointer for ${tbl['export']['name']} 82 | typedef ${x}_result_t (${X}_APICALL *${tbl['pfn']})( 83 | %for line in th.make_param_lines(n, tags, tbl['export'], format=["type", "delim"]): 84 | ${line} 85 | %endfor 86 | ); 87 | 88 | %endfor 89 | /////////////////////////////////////////////////////////////////////////////// 90 | /// @brief Container for all DDI tables 91 | typedef struct _${n}_dditable_t 92 | { 93 | %for tbl in th.get_pfntables(specs, meta, n, tags): 94 | ${th.append_ws(tbl['type'], 35)} ${tbl['name']}; 95 | %endfor 96 | } ${n}_dditable_t; 97 | 98 | #if defined(__cplusplus) 99 | } // extern "C" 100 | #endif 101 | 102 | #endif // _${N}_DDI_H -------------------------------------------------------------------------------- /scripts/templates/ldrddi.h.mako: -------------------------------------------------------------------------------- 1 | <%! 2 | import re 3 | from templates import helper as th 4 | %><% 5 | n=namespace 6 | N=n.upper() 7 | 8 | x=tags['$x'] 9 | X=x.upper() 10 | %>/* 11 | * 12 | * Copyright (C) 2019-2024 Intel Corporation 13 | * 14 | * SPDX-License-Identifier: MIT 15 | * 16 | * @file ${name}.h 17 | * 18 | */ 19 | #pragma once 20 | 21 | namespace loader 22 | { 23 | /////////////////////////////////////////////////////////////////////////////// 24 | %for obj in th.extract_objs(specs, r"handle"): 25 | %if 'class' in obj: 26 | <% 27 | _handle_t = th.subt(n, tags, obj['name']) 28 | _object_t = re.sub(r"(\w+)_handle_t", r"\1_object_t", _handle_t) 29 | _factory_t = re.sub(r"(\w+)_handle_t", r"\1_factory_t", _handle_t) 30 | %>using ${th.append_ws(_object_t, 35)} = object_t < ${_handle_t} >; 31 | using ${th.append_ws(_factory_t, 35)} = singleton_factory_t < ${_object_t}, ${_handle_t} >; 32 | 33 | %endif 34 | %endfor 35 | } 36 | -------------------------------------------------------------------------------- /scripts/templates/libddi.cpp.mako: -------------------------------------------------------------------------------- 1 | <%! 2 | import re 3 | from templates import helper as th 4 | %><% 5 | n=namespace 6 | N=n.upper() 7 | 8 | x=tags['$x'] 9 | X=x.upper() 10 | %>/* 11 | * 12 | * Copyright (C) 2019-2024 Intel Corporation 13 | * 14 | * SPDX-License-Identifier: MIT 15 | * 16 | * @file ${name}.cpp 17 | * 18 | */ 19 | #include "${x}_lib.h" 20 | #ifndef L0_STATIC_LOADER_BUILD 21 | #include "${n}_ddi.h" 22 | #endif 23 | 24 | namespace ${x}_lib 25 | { 26 | /////////////////////////////////////////////////////////////////////////////// 27 | 28 | #ifdef L0_STATIC_LOADER_BUILD 29 | __zedlllocal ${x}_result_t context_t::${n}DdiTableInit(ze_api_version_t version) 30 | { 31 | ${x}_result_t result = ${X}_RESULT_SUCCESS; 32 | 33 | %for tbl in th.get_pfntables(specs, meta, n, tags): 34 | if( ${X}_RESULT_SUCCESS == result ) 35 | { 36 | %if tbl['optional'] == True: 37 | // Optional 38 | auto getTable = reinterpret_cast<${tbl['pfn']}>( 39 | GET_FUNCTION_PTR(loader, "${tbl['export']['name']}") ); 40 | getTableWithCheck(getTable, version, &initial${n}DdiTable.${tbl['name']} ); 41 | %else: 42 | auto getTable = reinterpret_cast<${tbl['pfn']}>( 43 | GET_FUNCTION_PTR(loader, "${tbl['export']['name']}") ); 44 | result = getTableWithCheck(getTable, version, &initial${n}DdiTable.${tbl['name']} ); 45 | %endif 46 | %for obj in tbl['functions']: 47 | initial${n}DdiTable.${tbl['name']}.${th.make_pfn_name(n, tags, obj)} = reinterpret_cast<${th.make_pfn_type(n, tags, obj)}>( 48 | GET_FUNCTION_PTR(loader, "${th.make_func_name(n, tags, obj)}") ); 49 | %endfor 50 | } 51 | 52 | %endfor 53 | return result; 54 | } 55 | #else 56 | __zedlllocal ${x}_result_t context_t::${n}DdiTableInit(ze_api_version_t version) 57 | { 58 | ${x}_result_t result = ${X}_RESULT_SUCCESS; 59 | 60 | %for tbl in th.get_pfntables(specs, meta, n, tags): 61 | if( ${X}_RESULT_SUCCESS == result ) 62 | { 63 | %if tbl['optional'] == True: 64 | // Optional 65 | ${tbl['export']['name']}( version, &initial${n}DdiTable.${tbl['name']} ); 66 | %else: 67 | result = ${tbl['export']['name']}( version, &initial${n}DdiTable.${tbl['name']} ); 68 | %endif 69 | } 70 | 71 | %endfor 72 | return result; 73 | } 74 | #endif 75 | 76 | } // namespace ${x}_lib 77 | -------------------------------------------------------------------------------- /scripts/templates/tracing/trc_cb_struct.h.mako: -------------------------------------------------------------------------------- 1 | <% 2 | import re 3 | from templates import helper as th 4 | %><% 5 | n=namespace 6 | N=n.upper() 7 | 8 | x=tags['$x'] 9 | X=x.upper() 10 | %>/* 11 | * 12 | * Copyright (C) 2021-2022 Intel Corporation 13 | * 14 | * SPDX-License-Identifier: MIT 15 | * 16 | * @file ${name}.h 17 | * 18 | */ 19 | #ifndef ${name}_H 20 | #define ${name}_H 21 | #if defined(__cplusplus) 22 | #pragma once 23 | #endif 24 | 25 | #include "${x}_api.h" 26 | #include "layers/zel_tracing_register_cb.h" 27 | 28 | 29 | 30 | %for tbl in th.get_zel_pfncbtables(specs, meta, n, tags): 31 | /////////////////////////////////////////////////////////////////////////////// 32 | /// @brief Table of ${tbl['name']} callback functions pointers 33 | typedef struct _${tbl['type']} 34 | { 35 | %for obj in tbl['functions']: 36 | ${th.append_ws(th.make_pfncb_type(n, tags, obj), 63)} ${th.make_pfncb_name(n, tags, obj)}; 37 | %endfor 38 | } ${tbl['type']}; 39 | 40 | %endfor 41 | /////////////////////////////////////////////////////////////////////////////// 42 | /// @brief Container for all callbacks 43 | typedef struct _zel_all_core_callbacks_t 44 | { 45 | %for tbl in th.get_zel_pfncbtables(specs, meta, n, tags): 46 | ${th.append_ws(tbl['type'], 35)} ${tbl['name']}; 47 | %endfor 48 | } zel_all_core_callbacks_t; 49 | 50 | 51 | 52 | #endif // ${name}_H 53 | -------------------------------------------------------------------------------- /scripts/templates/tracing/trc_register_cb_libapi.cpp.mako: -------------------------------------------------------------------------------- 1 | <% 2 | import re 3 | from templates import helper as th 4 | %><% 5 | n=namespace 6 | N=n.upper() 7 | 8 | x=tags['$x'] 9 | X=x.upper() 10 | %>/* 11 | * 12 | * Copyright (C) 2021-2022 Intel Corporation 13 | * 14 | * SPDX-License-Identifier: MIT 15 | * 16 | * @file ${name}.cpp 17 | * 18 | */ 19 | 20 | #include "ze_lib.h" 21 | #include "layers/zel_tracing_api.h" 22 | #include "layers/zel_tracing_ddi.h" 23 | #include "layers/zel_tracing_register_cb.h" 24 | #include "${x}_api.h" 25 | 26 | extern "C" { 27 | 28 | /// APIs to register callbacks for each core API 29 | %for s in specs: 30 | %for obj in th.filter_items(s['objects'], 'type', 'function'): 31 | 32 | ${X}_APIEXPORT ${x}_result_t ${X}_APICALL 33 | ${th.make_tracing_func_name(n, tags, obj)}( 34 | zel_tracer_handle_t hTracer, 35 | zel_tracer_reg_t callback_type, 36 | ${th.make_pfncb_type(n, tags, obj)} ${th.make_pfncb_name(n, tags, obj)} 37 | ) { 38 | 39 | if(!ze_lib::context->tracing_lib) 40 | return ZE_RESULT_ERROR_UNINITIALIZED; 41 | typedef ze_result_t (ZE_APICALL *ze_pfnSetCallback_t)( 42 | zel_tracer_handle_t hTracer, 43 | zel_tracer_reg_t callback_type, 44 | ${th.make_pfncb_type(n, tags, obj)} ${th.make_pfncb_name(n, tags, obj)} 45 | ); 46 | 47 | auto func = reinterpret_cast( 48 | GET_FUNCTION_PTR(ze_lib::context->tracing_lib, "${th.make_tracing_func_name(n, tags, obj)}") ); 49 | 50 | if(func) 51 | return func(hTracer, callback_type, ${th.make_pfncb_name(n, tags, obj)}); 52 | 53 | return ZE_RESULT_ERROR_UNINITIALIZED; 54 | } 55 | 56 | %endfor 57 | %endfor #s in specs: 58 | 59 | } //Extern C -------------------------------------------------------------------------------- /scripts/templates/tracing/trc_setters.cpp.mako: -------------------------------------------------------------------------------- 1 | <% 2 | import re 3 | from templates import helper as th 4 | %><% 5 | n=namespace 6 | N=n.upper() 7 | 8 | x=tags['$x'] 9 | X=x.upper() 10 | %>/* 11 | * 12 | * Copyright (C) 2021-2022 Intel Corporation 13 | * 14 | * SPDX-License-Identifier: MIT 15 | * 16 | * @file ${name}.h 17 | * 18 | */ 19 | 20 | #include "tracing.h" 21 | #include "ze_tracing_layer.h" 22 | #include "layers/zel_tracing_api.h" 23 | #include "layers/zel_tracing_ddi.h" 24 | #include "layers/zel_tracing_register_cb.h" 25 | #include "${x}_api.h" 26 | 27 | extern "C" { 28 | 29 | /// APIs to register callbacks for each core API 30 | %for s in specs: 31 | %for obj in th.filter_items(s['objects'], 'type', 'function'): 32 | 33 | ${X}_DLLEXPORT ${x}_result_t ${X}_APICALL 34 | ${th.make_tracing_func_name(n, tags, obj)}( 35 | zel_tracer_handle_t hTracer, 36 | zel_tracer_reg_t callback_type, 37 | ${th.make_pfncb_type(n, tags, obj)} ${th.make_pfncb_name(n, tags, obj)} 38 | ) { 39 | 40 | ze_result_t result; 41 | auto& cbs = tracing_layer::APITracer::fromHandle(hTracer)->getProEpilogues(callback_type, result); 42 | if (result == ZE_RESULT_SUCCESS) 43 | cbs.${th.get_callback_table_name(n, tags, obj)}.${th.make_pfncb_name(n, tags, obj)} = ${th.make_pfncb_name(n, tags, obj)}; 44 | 45 | return result; 46 | } 47 | 48 | %endfor 49 | %endfor #s in specs: 50 | 51 | 52 | } //extern C -------------------------------------------------------------------------------- /scripts/templates/tracing/trc_setters.h.mako: -------------------------------------------------------------------------------- 1 | <% 2 | import re 3 | from templates import helper as th 4 | %><% 5 | n=namespace 6 | N=n.upper() 7 | 8 | x=tags['$x'] 9 | X=x.upper() 10 | %>/* 11 | * 12 | * Copyright (C) 2021-2022 Intel Corporation 13 | * 14 | * SPDX-License-Identifier: MIT 15 | * 16 | * @file ${name}.h 17 | * 18 | */ 19 | #ifndef ${name}_H 20 | #define ${name}_H 21 | #if defined(__cplusplus) 22 | #pragma once 23 | #endif 24 | 25 | #include "../${x}_api.h" 26 | 27 | 28 | #if defined(__cplusplus) 29 | extern "C" { 30 | #endif 31 | 32 | /////////////////////////////////////////////////////////////////////////////// 33 | /// @brief Handle of tracer object 34 | typedef struct _zel_tracer_handle_t *zel_tracer_handle_t; 35 | 36 | /// Callback definitions for all API released in LevelZero spec 1.1 or newer 37 | /// Callbacks for APIs included in spec 1.0 are contained in ze_api.helper 38 | 39 | %for tbl in th.get_new_pfncbtables(specs, meta, n, tags): 40 | %for obj in tbl['functions']: 41 | /////////////////////////////////////////////////////////////////////////////// 42 | /// @brief Callback function parameters for ${th.make_func_name(n, tags, obj)} 43 | /// @details Each entry is a pointer to the parameter passed to the function; 44 | /// allowing the callback the ability to modify the parameter's value 45 | 46 | typedef struct _${th.make_pfncb_param_type(n, tags, obj)} 47 | { 48 | %for line in th.make_param_lines(n, tags, obj, format=["type*", "name"]): 49 | ${line}; 50 | %endfor 51 | } ${th.make_pfncb_param_type(n, tags, obj)}; 52 | 53 | 54 | /////////////////////////////////////////////////////////////////////////////// 55 | /// @brief Callback function-pointer for ${th.make_func_name(n, tags, obj)} 56 | /// @param[in] params Parameters passed to this instance 57 | /// @param[in] result Return value 58 | /// @param[in] pTracerUserData Per-Tracer user data 59 | /// @param[in,out] ppTracerInstanceUserData Per-Tracer, Per-Instance user data 60 | 61 | typedef void (${X}_APICALL *${th.make_pfncb_type(n, tags, obj)})( 62 | ${th.make_pfncb_param_type(n, tags, obj)}* params, 63 | ${x}_result_t result, 64 | void* pTracerUserData, 65 | void** ppTracerInstanceUserData 66 | ); 67 | 68 | %endfor 69 | %endfor 70 | 71 | typedef enum _zel_tracer_reg_t 72 | { 73 | ZEL_REGISTER_PROLOGUE = 0, 74 | ZEL_REGISTER_EPILOGUE = 1 75 | } zel_tracer_reg_t; 76 | 77 | /// APIs to register callbacks for each core API 78 | %for s in specs: 79 | %for obj in th.filter_items(s['objects'], 'type', 'function'): 80 | 81 | ${X}_APIEXPORT ${x}_result_t ${X}_APICALL 82 | ${th.make_tracing_func_name(n, tags, obj)}( 83 | zel_tracer_handle_t hTracer, 84 | zel_tracer_reg_t callback_type, 85 | ${th.make_pfncb_type(n, tags, obj)} ${th.make_pfncb_name(n, tags, obj)} 86 | ); 87 | 88 | %endfor 89 | %endfor #s in specs: 90 | 91 | ${X}_APIEXPORT ${x}_result_t ${X}_APICALL 92 | zelTracerResetAllCallbacks(zel_tracer_handle_t hTracer); 93 | 94 | 95 | #if defined(__cplusplus) 96 | } // extern "C" 97 | #endif 98 | 99 | #endif // ${name}_H 100 | -------------------------------------------------------------------------------- /scripts/templates/tracing/trcddi.cpp.mako: -------------------------------------------------------------------------------- 1 | <%! 2 | import re 3 | from templates import helper as th 4 | %><% 5 | n=namespace 6 | N=n.upper() 7 | 8 | x=tags['$x'] 9 | X=x.upper() 10 | %>/* 11 | * 12 | * Copyright (C) 2020-2022 Intel Corporation 13 | * 14 | * SPDX-License-Identifier: MIT 15 | * 16 | * @file ${name}.cpp 17 | * 18 | */ 19 | 20 | #include 21 | #include "${x}_tracing_layer.h" 22 | 23 | namespace tracing_layer 24 | { 25 | %for obj in th.extract_objs(specs, r"function"): 26 | /////////////////////////////////////////////////////////////////////////////// 27 | /// @brief Intercept function for ${th.make_func_name(n, tags, obj)} 28 | %if 'condition' in obj: 29 | #if ${th.subt(n, tags, obj['condition'])} 30 | %endif 31 | __${x}dlllocal ${x}_result_t ${X}_APICALL 32 | ${th.make_func_name(n, tags, obj)}( 33 | %for line in th.make_param_lines(n, tags, obj): 34 | ${line} 35 | %endfor 36 | ) 37 | { 38 | auto ${th.make_pfn_name(n, tags, obj)} = context.${n}DdiTable.${th.get_table_name(n, tags, obj)}.${th.make_pfn_name(n, tags, obj)}; 39 | 40 | if( nullptr == ${th.make_pfn_name(n, tags, obj)}) 41 | return ${X}_RESULT_ERROR_UNSUPPORTED_FEATURE; 42 | 43 | ZE_HANDLE_TRACER_RECURSION(context.${n}DdiTable.${th.get_table_name(n, tags, obj)}.${th.make_pfn_name(n, tags, obj)}, ${", ".join(th.make_param_lines(n, tags, obj, format=["name"]))}); 44 | 45 | // capture parameters 46 | ${th.make_pfncb_param_type(n, tags, obj)} tracerParams = { 47 | &${",\n &".join(th.make_param_lines(n, tags, obj, format=["name"]))} 48 | }; 49 | 50 | tracing_layer::APITracerCallbackDataImp<${th.make_pfncb_type(n, tags, obj)}> apiCallbackData; 51 | 52 | ZE_GEN_PER_API_CALLBACK_STATE(apiCallbackData, ${th.make_pfncb_type(n, tags, obj)}, ${th.get_callback_table_name(n, tags, obj)}, ${th.make_pfncb_name(n, tags, obj)}); 53 | 54 | 55 | return tracing_layer::APITracerWrapperImp(context.${n}DdiTable.${th.get_table_name(n, tags, obj)}.${th.make_pfn_name(n, tags, obj)}, 56 | &tracerParams, 57 | apiCallbackData.apiOrdinal, 58 | apiCallbackData.prologCallbacks, 59 | apiCallbackData.epilogCallbacks, 60 | *tracerParams.p${",\n *tracerParams.p".join(th.make_param_lines(n, tags, obj, format=["name"]))}); 61 | } 62 | %if 'condition' in obj: 63 | #endif // ${th.subt(n, tags, obj['condition'])} 64 | %endif 65 | 66 | %endfor 67 | } // namespace tracing_layer 68 | 69 | #if defined(__cplusplus) 70 | extern "C" { 71 | #endif 72 | 73 | %for tbl in th.get_pfntables(specs, meta, n, tags): 74 | /////////////////////////////////////////////////////////////////////////////// 75 | /// @brief Exported function for filling application's ${tbl['name']} table 76 | /// with current process' addresses 77 | /// 78 | /// @returns 79 | /// - ::${X}_RESULT_SUCCESS 80 | /// - ::${X}_RESULT_ERROR_INVALID_NULL_POINTER 81 | /// - ::${X}_RESULT_ERROR_UNSUPPORTED_VERSION 82 | ${X}_DLLEXPORT ${x}_result_t ${X}_APICALL 83 | ${tbl['export']['name']}( 84 | %for line in th.make_param_lines(n, tags, tbl['export']): 85 | ${line} 86 | %endfor 87 | ) 88 | { 89 | auto& dditable = tracing_layer::context.${n}DdiTable.${tbl['name']}; 90 | 91 | if( nullptr == pDdiTable ) 92 | return ${X}_RESULT_ERROR_INVALID_NULL_POINTER; 93 | 94 | if (tracing_layer::context.version < version) 95 | return ${X}_RESULT_ERROR_UNSUPPORTED_VERSION; 96 | 97 | ${x}_result_t result = ${X}_RESULT_SUCCESS; 98 | 99 | %for obj in tbl['functions']: 100 | if (version >= ${th.get_version(obj)}) { 101 | %if 'condition' in obj: 102 | #if ${th.subt(n, tags, obj['condition'])} 103 | %endif 104 | dditable.${th.append_ws(th.make_pfn_name(n, tags, obj), 43)} = pDdiTable->${th.make_pfn_name(n, tags, obj)}; 105 | pDdiTable->${th.append_ws(th.make_pfn_name(n, tags, obj), 41)} = tracing_layer::${th.make_func_name(n, tags, obj)}; 106 | %if 'condition' in obj: 107 | #else 108 | dditable.${th.append_ws(th.make_pfn_name(n, tags, obj), 43)} = nullptr; 109 | pDdiTable->${th.append_ws(th.make_pfn_name(n, tags, obj), 41)} = nullptr; 110 | #endif 111 | %endif 112 | } 113 | %endfor 114 | return result; 115 | } 116 | 117 | %endfor 118 | #if defined(__cplusplus) 119 | }; 120 | #endif 121 | -------------------------------------------------------------------------------- /scripts/templates/validation/entry_points.h.mako: -------------------------------------------------------------------------------- 1 | <%! 2 | import re 3 | from templates import helper as th 4 | %><% 5 | n=namespace 6 | N=n.upper() 7 | 8 | x=tags['$x'] 9 | X=x.upper() 10 | %>/* 11 | * ***THIS FILE IS GENERATED. *** 12 | * See entry_points.h.mako for modifications 13 | * 14 | * Copyright (C) 2019-2024 Intel Corporation 15 | * 16 | * SPDX-License-Identifier: MIT 17 | * 18 | * @file ${name} 19 | * 20 | */ 21 | #pragma once 22 | #include "${n}_api.h" 23 | 24 | namespace validation_layer 25 | { 26 | 27 | class ${N}ValidationEntryPoints { 28 | public: 29 | %for obj in th.extract_objs(specs, r"function"): 30 | virtual ${x}_result_t ${th.make_func_name(n, tags, obj)}Prologue( \ 31 | %for line in th.make_param_lines(n, tags, obj, format=["type", "name", "delim"]): 32 | ${line} \ 33 | %endfor 34 | ) {return ZE_RESULT_SUCCESS;} 35 | virtual ${x}_result_t ${th.make_func_name(n, tags, obj)}Epilogue( \ 36 | %for line in th.make_param_lines(n, tags, obj, format=["type", "name", "delim"]): 37 | ${line} \ 38 | %endfor 39 | , ze_result_t result) {return ZE_RESULT_SUCCESS;} 40 | %endfor 41 | virtual ~${N}ValidationEntryPoints() {} 42 | }; 43 | } -------------------------------------------------------------------------------- /scripts/templates/validation/handle_lifetime.cpp.mako: -------------------------------------------------------------------------------- 1 | <%! 2 | import re 3 | from templates import helper as th 4 | %><% 5 | n=namespace 6 | N=n.upper() 7 | 8 | x=tags['$x'] 9 | X=x.upper() 10 | %>/* 11 | * ***THIS FILE IS GENERATED. *** 12 | * See handle_lifetime.cpp.mako for modifications 13 | * 14 | * Copyright (C) 2019-2023 Intel Corporation 15 | * 16 | * SPDX-License-Identifier: MIT 17 | * 18 | * @file ${name} 19 | * 20 | */ 21 | #include "${x}_validation_layer.h" 22 | #include "${x}_handle_lifetime.h" 23 | 24 | namespace validation_layer 25 | { 26 | %for obj in th.extract_objs(specs, r"function"): 27 | ## don't genrate function if it has no handles as parameters 28 | %if th.obj_traits.is_function_with_input_handles(obj): 29 | ${x}_result_t 30 | ${N}HandleLifetimeValidation::${th.make_func_name(n, tags, obj)}Prologue( 31 | %for line in th.make_param_lines(n, tags, obj): 32 | ${line} 33 | %endfor 34 | ) 35 | { 36 | <% func_name = th.make_func_name(n, tags, obj) 37 | %> 38 | %if re.match(r"\w+Destroy$", func_name): 39 | %for i, item in enumerate(th.get_loader_prologue(n, tags, obj, meta)): 40 | if (${item['name']} && context.handleLifetime->isHandleValid( ${item['name']} )){ 41 | if (context.handleLifetime->hasDependents( ${item['name']} )){ 42 | return ${X}_RESULT_ERROR_HANDLE_OBJECT_IN_USE; 43 | } 44 | context.handleLifetime->removeDependent( ${item['name']}); 45 | context.handleLifetime->removeHandle( ${item['name']} ); 46 | } else if (!context.handleLifetime->isHandleValid( ${item['name']} )) { 47 | return ${X}_RESULT_ERROR_INVALID_NULL_HANDLE; 48 | } 49 | %endfor 50 | %else: ## Not Destroy 51 | %for i, item in enumerate(th.get_loader_prologue(n, tags, obj, meta)): 52 | %if not 'range' in item: 53 | ## if item is optional, check if it is not null before checking if it is valid 54 | %if item['optional']: 55 | if (${item['name']} && !context.handleLifetime->isHandleValid( ${item['name']} )){ 56 | return ${X}_RESULT_ERROR_INVALID_NULL_HANDLE; 57 | } 58 | %else: 59 | if ( !context.handleLifetime->isHandleValid( ${item['name']} )){ 60 | return ${X}_RESULT_ERROR_INVALID_NULL_HANDLE; 61 | } 62 | %endif ## if item['optional'] 63 | %if re.match(r"\w+CommandListAppend\w+$", func_name) and (0 == i) : ## i = 0, first parameter is command list 64 | if (!context.handleLifetime->isOpen( ${item['name']} )){ 65 | return ${X}_RESULT_ERROR_INVALID_ARGUMENT; 66 | } 67 | %endif 68 | %if re.match(r"\w+CommandListClose$", func_name): 69 | context.handleLifetime->close( ${item['name']} ); 70 | %endif 71 | %if re.match(r"\w+CommandListReset$", func_name): 72 | context.handleLifetime->reset( ${item['name']} ); 73 | %endif 74 | %else: ## if 'range' in item 75 | for (size_t i = ${item['range'][0]}; ( nullptr != ${item['name']}) && (i < ${item['range'][1]}); ++i){ 76 | if (!context.handleLifetime->isHandleValid( ${item['name']}[i] )){ 77 | return ${X}_RESULT_ERROR_INVALID_NULL_HANDLE; 78 | } 79 | } 80 | %if re.match(r"\w+ExecuteCommandLists$", func_name) and (1 == i): 81 | for (size_t i = ${item['range'][0]}; ( nullptr != ${item['name']}) && (i < ${item['range'][1]}); ++i){ 82 | if (context.handleLifetime->isOpen( ${item['name']}[i] )){ 83 | return ${X}_RESULT_ERROR_INVALID_ARGUMENT; 84 | } 85 | } 86 | %endif 87 | %endif ## if 'range' in item 88 | %endfor ## for i, item in enumerate(th.get_loader_prologue(n, tags, obj, meta)) 89 | %endif ## if re.match(r"\w+Destroy$", func_name) 90 | return ${X}_RESULT_SUCCESS; 91 | } 92 | %endif 93 | %endfor 94 | } -------------------------------------------------------------------------------- /scripts/templates/validation/handle_lifetime.h.mako: -------------------------------------------------------------------------------- 1 | <%! 2 | import re 3 | from templates import helper as th 4 | %><% 5 | n=namespace 6 | N=n.upper() 7 | 8 | x=tags['$x'] 9 | X=x.upper() 10 | %>/* 11 | * ***THIS FILE IS GENERATED. *** 12 | * See handle_lifetime.h.mako for modifications 13 | * 14 | * Copyright (C) 2019-2023 Intel Corporation 15 | * 16 | * SPDX-License-Identifier: MIT 17 | * 18 | * @file ${name} 19 | * 20 | */ 21 | 22 | #pragma once 23 | #include "${n}_entry_points.h" 24 | 25 | 26 | namespace validation_layer 27 | { 28 | 29 | class ${N}HandleLifetimeValidation : public ${N}ValidationEntryPoints { 30 | public: 31 | %for obj in th.extract_objs(specs, r"function"): 32 | %if not th.obj_traits.is_function_with_input_handles(obj): 33 | <% continue %> 34 | %endif 35 | ${x}_result_t ${th.make_func_name(n, tags, obj)}Prologue( \ 36 | %for line in th.make_param_lines(n, tags, obj, format=["type", "name", "delim"]): 37 | ${line} \ 38 | %endfor 39 | ) override; 40 | %endfor 41 | }; 42 | 43 | } 44 | -------------------------------------------------------------------------------- /scripts/templates/validation/param.cpp.mako: -------------------------------------------------------------------------------- 1 | <%! 2 | import re 3 | from templates import helper as th 4 | %><% 5 | n=namespace 6 | N=n.upper() 7 | 8 | x=tags['$x'] 9 | X=x.upper() 10 | %>/* 11 | * ***THIS FILE IS GENERATED. *** 12 | * See valddi.cpp.mako for modifications 13 | * 14 | * Copyright (C) 2019-2023 Intel Corporation 15 | * 16 | * SPDX-License-Identifier: MIT 17 | * 18 | * @file ${name} 19 | * 20 | */ 21 | #include "${x}_validation_layer.h" 22 | #include "param_validation.h" 23 | 24 | namespace validation_layer 25 | { 26 | %if 'ze' == n: 27 | class parameterValidationChecker parameterChecker; 28 | 29 | parameterValidationChecker::parameterValidationChecker() { 30 | enableParameterValidation = getenv_tobool( "ZE_ENABLE_PARAMETER_VALIDATION" ); 31 | if(enableParameterValidation) { 32 | ZEParameterValidation *zeChecker = new ZEParameterValidation; 33 | ZESParameterValidation *zesChecker = new ZESParameterValidation; 34 | ZETParameterValidation *zetChecker = new ZETParameterValidation; 35 | parameterChecker.zeValidation = zeChecker; 36 | parameterChecker.zetValidation = zetChecker; 37 | parameterChecker.zesValidation = zesChecker; 38 | validation_layer::context.getInstance().validationHandlers.push_back(¶meterChecker); 39 | } 40 | } 41 | 42 | parameterValidationChecker::~parameterValidationChecker() { 43 | if(enableParameterValidation) { 44 | delete parameterChecker.zeValidation; 45 | delete parameterChecker.zetValidation; 46 | delete parameterChecker.zesValidation; 47 | } 48 | } 49 | %endif 50 | %for obj in th.extract_objs(specs, r"function"): 51 | 52 | ${x}_result_t 53 | ${N}ParameterValidation::${th.make_func_name(n, tags, obj)}Prologue( 54 | %for line in th.make_param_lines(n, tags, obj): 55 | ${line} 56 | %endfor 57 | ) 58 | { 59 | %for key, values in th.make_param_checks(n, tags, obj, meta=meta).items(): 60 | %for val in values: 61 | if( ${val} ) 62 | return ${key}; 63 | 64 | %endfor 65 | %endfor 66 | <% 67 | descs = th.get_func_descs(n, tags, obj) 68 | %>\ 69 | %if len(descs) == 0: 70 | return ${X}_RESULT_SUCCESS; 71 | %elif len(descs) == 1: 72 | return ParameterValidation::validateExtensions(${descs[0]}); 73 | %else: 74 | auto retVal = ${X}_RESULT_SUCCESS; 75 | %for i, desc in enumerate(descs): 76 | retVal = ParameterValidation::validateExtensions(${desc}); 77 | %if i < len(descs)-1: 78 | if(retVal) 79 | return retVal; 80 | %endif 81 | %endfor 82 | return retVal; 83 | %endif 84 | } 85 | 86 | %endfor 87 | } -------------------------------------------------------------------------------- /scripts/templates/validation/param.h.mako: -------------------------------------------------------------------------------- 1 | <%! 2 | import re 3 | from templates import helper as th 4 | %><% 5 | n=namespace 6 | N=n.upper() 7 | 8 | x=tags['$x'] 9 | X=x.upper() 10 | %>/* 11 | * ***THIS FILE IS GENERATED. *** 12 | * See param.h.mako for modifications 13 | * 14 | * Copyright (C) 2019-2023 Intel Corporation 15 | * 16 | * SPDX-License-Identifier: MIT 17 | * 18 | * @file ${name} 19 | * 20 | */ 21 | 22 | #pragma once 23 | #include "${x}_validation_layer.h" 24 | #include "${n}_entry_points.h" 25 | 26 | 27 | namespace validation_layer 28 | { 29 | 30 | class ${N}ParameterValidation : public ${N}ValidationEntryPoints { 31 | public: 32 | %for obj in th.extract_objs(specs, r"function"): 33 | ${x}_result_t ${th.make_func_name(n, tags, obj)}Prologue( \ 34 | %for line in th.make_param_lines(n, tags, obj, format=["type", "name", "delim"]): 35 | ${line} \ 36 | %endfor 37 | ) override; 38 | %endfor 39 | }; 40 | } -------------------------------------------------------------------------------- /scripts/util.py: -------------------------------------------------------------------------------- 1 | """ 2 | Copyright (C) 2019-2021 Intel Corporation 3 | 4 | SPDX-License-Identifier: MIT 5 | 6 | """ 7 | import re 8 | import json 9 | from mako.template import Template 10 | 11 | makoFileList = [] 12 | 13 | def makoWrite(inpath, outpath, **args): 14 | template = Template(filename=inpath) 15 | rendered = template.render(**args) 16 | rendered = re.sub(r"\r\n", r"\n", rendered) 17 | 18 | with open(outpath, 'w') as fout: 19 | fout.write(rendered) 20 | 21 | makoFileList.append(outpath) 22 | return len(rendered.splitlines()) 23 | 24 | def makoFileListWrite(outpath): 25 | with open(outpath, 'w') as fout: 26 | fout.write(json.dumps(makoFileList, indent=4, sort_keys=True)) 27 | -------------------------------------------------------------------------------- /scripts/wix_env_installation.wxs: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /source/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Intel Corporation 2 | # SPDX-License-Identifier: MIT 3 | 4 | add_definitions(-DL0_LOADER_VERSION="${PROJECT_VERSION_MAJOR}") 5 | add_definitions(-DL0_VALIDATION_LAYER_SUPPORTED_VERSION="${PROJECT_VERSION_MAJOR}") 6 | 7 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc) 8 | 9 | configure_file( 10 | ${CMAKE_CURRENT_SOURCE_DIR}/ZeLoaderVersion.rc.in 11 | ${CMAKE_CURRENT_BINARY_DIR}/ZeLoaderVersion.rc 12 | @ONLY) 13 | 14 | include(GNUInstallDirs) 15 | if (BUILD_STATIC) 16 | message(STATUS "Building loader as static library") 17 | add_library(${TARGET_LOADER_NAME} 18 | STATIC 19 | "" 20 | ${CMAKE_CURRENT_BINARY_DIR}/ZeLoaderVersion.rc 21 | ) 22 | add_definitions(-DL0_STATIC_LOADER_BUILD="1") 23 | else() 24 | message(STATUS "Building loader as dynamic library") 25 | add_library(${TARGET_LOADER_NAME} 26 | SHARED 27 | "" 28 | ${CMAKE_CURRENT_BINARY_DIR}/ZeLoaderVersion.rc 29 | ) 30 | endif() 31 | 32 | if(MSVC AND L0_DLL_INTEGRITY_CHECKS) 33 | set_target_properties(ze_loader PROPERTIES LINK_FLAGS "${CMAKE_CXX_LINKER_WRAPPER_FLAG}/INTEGRITYCHECK") 34 | endif() 35 | 36 | add_subdirectory(lib) 37 | if (NOT BUILD_STATIC) 38 | add_subdirectory(loader) 39 | add_subdirectory(layers) 40 | endif() 41 | add_subdirectory(drivers) 42 | add_subdirectory(utils) 43 | 44 | set_target_properties(${TARGET_LOADER_NAME} PROPERTIES 45 | VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}" 46 | SOVERSION "${PROJECT_VERSION_MAJOR}" 47 | ) 48 | 49 | target_link_libraries(${TARGET_LOADER_NAME} PRIVATE ${CMAKE_DL_LIBS} level_zero_utils) 50 | 51 | if (UNIX) 52 | set(CMAKE_THREAD_PREFER_PTHREAD TRUE) 53 | set(THREADS_PREFER_PTHREAD_FLAG TRUE) 54 | find_package(Threads REQUIRED) 55 | target_link_libraries (${TARGET_LOADER_NAME} PRIVATE Threads::Threads) 56 | endif() 57 | 58 | if(WIN32) 59 | target_link_libraries (${TARGET_LOADER_NAME} PRIVATE cfgmgr32.lib) 60 | endif() 61 | 62 | set(SDK_COMPONENT_STRING "level-zero-devel") 63 | set(LIB_COMPONENT_STRING "level-zero") 64 | 65 | if(BUILD_INSTALLER) 66 | set(SDK_COMPONENT_STRING "SDK") 67 | set(LIB_COMPONENT_STRING "Loader") 68 | endif() 69 | 70 | install(TARGETS ze_loader 71 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${SDK_COMPONENT_STRING} 72 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${LIB_COMPONENT_STRING} 73 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${LIB_COMPONENT_STRING} 74 | NAMELINK_COMPONENT ${SDK_COMPONENT_STRING} 75 | ) 76 | 77 | if(NOT BUILD_INSTALLER) 78 | file(RELATIVE_PATH pkgconfig_prefix "${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig" "${CMAKE_INSTALL_PREFIX}") 79 | file(RELATIVE_PATH pkgconfig_include_dir "${CMAKE_INSTALL_PREFIX}" "${CMAKE_INSTALL_FULL_INCLUDEDIR}") 80 | file(RELATIVE_PATH pkgconfig_lib_dir "${CMAKE_INSTALL_PREFIX}" "${CMAKE_INSTALL_FULL_LIBDIR}") 81 | 82 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libze_loader.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libze_loader.pc @ONLY) 83 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/level-zero.pc.in ${CMAKE_CURRENT_BINARY_DIR}/level-zero.pc @ONLY) 84 | 85 | install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libze_loader.pc" 86 | "${CMAKE_CURRENT_BINARY_DIR}/level-zero.pc" 87 | DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig" COMPONENT ${SDK_COMPONENT_STRING}) 88 | endif() 89 | -------------------------------------------------------------------------------- /source/ZeLoaderVersion.rc.in: -------------------------------------------------------------------------------- 1 | #define VER_FILEVERSION @PROJECT_VERSION_MAJOR@,@PROJECT_VERSION_MINOR@,@PROJECT_VERSION_PATCH@ 2 | #define VER_FILEVERSION_STR "@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@\0" 3 | 4 | #define VER_PRODUCTVERSION @PROJECT_VERSION_MAJOR@,@PROJECT_VERSION_MINOR@,@PROJECT_VERSION_PATCH@ 5 | #define VER_PRODUCTVERSION_STR "@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@\0" 6 | 7 | #define VER_FILEDESCRIPTION_STR "oneAPI Level Zero Loader for Windows(R) Level Zero Drivers" 8 | 9 | #define VER_PRODUCT_NAME_STR "oneAPI Level Zero Loader for Windows(R)" 10 | 11 | #define VER_LEGALCOPYRIGHT_STR "Copyright (C) 2023 Intel Corporation" 12 | 13 | 1 VERSIONINFO 14 | FILEVERSION VER_FILEVERSION 15 | PRODUCTVERSION VER_PRODUCTVERSION 16 | BEGIN 17 | BLOCK "StringFileInfo" 18 | BEGIN 19 | BLOCK "040904E4" 20 | BEGIN 21 | VALUE "FileDescription", VER_FILEDESCRIPTION_STR 22 | VALUE "FileVersion", VER_FILEVERSION_STR 23 | VALUE "ProductVersion", VER_PRODUCTVERSION_STR 24 | VALUE "ProductName", VER_PRODUCT_NAME_STR 25 | VALUE "LegalCopyright", VER_LEGALCOPYRIGHT_STR 26 | END 27 | END 28 | 29 | BLOCK "VarFileInfo" 30 | BEGIN 31 | VALUE "Translation", 0x409, 1252 32 | END 33 | END -------------------------------------------------------------------------------- /source/drivers/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(null) -------------------------------------------------------------------------------- /source/drivers/null/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(TARGET_NAME ze_null) 2 | 3 | add_library(${TARGET_NAME} 4 | SHARED 5 | ${CMAKE_CURRENT_SOURCE_DIR}/ze_null.h 6 | ${CMAKE_CURRENT_SOURCE_DIR}/ze_null.cpp 7 | ${CMAKE_CURRENT_SOURCE_DIR}/ze_nullddi.cpp 8 | ${CMAKE_CURRENT_SOURCE_DIR}/zet_nullddi.cpp 9 | ${CMAKE_CURRENT_SOURCE_DIR}/zes_nullddi.cpp 10 | ) 11 | 12 | set_target_properties(${TARGET_NAME} PROPERTIES 13 | VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}" 14 | SOVERSION "${PROJECT_VERSION_MAJOR}" 15 | ) 16 | 17 | target_include_directories(${TARGET_NAME} 18 | PUBLIC 19 | ${CMAKE_CURRENT_SOURCE_DIR} 20 | ) 21 | 22 | if(INSTALL_NULL_DRIVER) 23 | install(TARGETS ze_null 24 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT level-zero-devel 25 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT level-zero 26 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT level-zero 27 | NAMELINK_COMPONENT level-zero-devel 28 | ) 29 | endif() 30 | 31 | if (BUILD_L0_LOADER_TESTS) 32 | add_library(ze_null_test1 SHARED 33 | ${CMAKE_CURRENT_SOURCE_DIR}/ze_null.h 34 | ${CMAKE_CURRENT_SOURCE_DIR}/ze_null.cpp 35 | ${CMAKE_CURRENT_SOURCE_DIR}/ze_nullddi.cpp 36 | ${CMAKE_CURRENT_SOURCE_DIR}/zet_nullddi.cpp 37 | ${CMAKE_CURRENT_SOURCE_DIR}/zes_nullddi.cpp 38 | ) 39 | 40 | add_library(ze_null_test2 SHARED 41 | ${CMAKE_CURRENT_SOURCE_DIR}/ze_null.h 42 | ${CMAKE_CURRENT_SOURCE_DIR}/ze_null.cpp 43 | ${CMAKE_CURRENT_SOURCE_DIR}/ze_nullddi.cpp 44 | ${CMAKE_CURRENT_SOURCE_DIR}/zet_nullddi.cpp 45 | ${CMAKE_CURRENT_SOURCE_DIR}/zes_nullddi.cpp 46 | ) 47 | 48 | set_target_properties(ze_null_test1 PROPERTIES 49 | VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}" 50 | SOVERSION "${PROJECT_VERSION_MAJOR}" 51 | ) 52 | 53 | set_target_properties(ze_null_test2 PROPERTIES 54 | VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}" 55 | SOVERSION "${PROJECT_VERSION_MAJOR}" 56 | ) 57 | 58 | target_include_directories(ze_null_test1 59 | PUBLIC 60 | ${CMAKE_CURRENT_SOURCE_DIR} 61 | ) 62 | 63 | target_include_directories(ze_null_test2 64 | PUBLIC 65 | ${CMAKE_CURRENT_SOURCE_DIR} 66 | ) 67 | 68 | target_compile_definitions(ze_null_test1 PUBLIC ZEL_NULL_DRIVER_ID=1) 69 | target_compile_definitions(ze_null_test2 PUBLIC ZEL_NULL_DRIVER_ID=2) 70 | target_compile_definitions(ze_null PUBLIC ZEL_NULL_DRIVER_ID=1) 71 | 72 | if(INSTALL_NULL_DRIVER) 73 | install(TARGETS ze_null_test1 74 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT level-zero-devel 75 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT level-zero 76 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT level-zero 77 | NAMELINK_COMPONENT level-zero-devel 78 | ) 79 | install(TARGETS ze_null_test2 80 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT level-zero-devel 81 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT level-zero 82 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT level-zero 83 | NAMELINK_COMPONENT level-zero-devel 84 | ) 85 | endif() 86 | endif() 87 | 88 | if(UNIX) 89 | set(GCC_COVERAGE_COMPILE_FLAGS "-fvisibility=hidden -fvisibility-inlines-hidden -fno-strict-aliasing") 90 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}") 91 | endif() -------------------------------------------------------------------------------- /source/drivers/null/ze_null.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019-2021 Intel Corporation 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * @file ze_null.h 8 | * 9 | */ 10 | #pragma once 11 | #include 12 | #include 13 | #include "ze_ddi.h" 14 | #include "zet_ddi.h" 15 | #include "zes_ddi.h" 16 | #include "ze_util.h" 17 | 18 | #ifndef ZEL_NULL_DRIVER_ID 19 | #define ZEL_NULL_DRIVER_ID 1 20 | #endif 21 | 22 | namespace driver 23 | { 24 | /////////////////////////////////////////////////////////////////////////////// 25 | class __zedlllocal context_t 26 | { 27 | public: 28 | ze_api_version_t version = ZE_API_VERSION_CURRENT; 29 | 30 | ze_dditable_t zeDdiTable = {}; 31 | zet_dditable_t zetDdiTable = {}; 32 | zes_dditable_t zesDdiTable = {}; 33 | context_t(); 34 | ~context_t() = default; 35 | 36 | void* get( void ) 37 | { 38 | static uint64_t count = 0x80800000; 39 | return reinterpret_cast( ++count ); 40 | } 41 | }; 42 | 43 | extern context_t context; 44 | } // namespace driver 45 | 46 | namespace instrumented 47 | { 48 | ////////////////////////////////////////////////////////////////////////// 49 | struct tracer_data_t 50 | { 51 | ze_bool_t enabled = false; 52 | 53 | void* userData = nullptr; 54 | 55 | ze_callbacks_t zePrologueCbs = {}; 56 | ze_callbacks_t zeEpilogueCbs = {}; 57 | }; 58 | 59 | /////////////////////////////////////////////////////////////////////////////// 60 | class __zedlllocal context_t 61 | { 62 | public: 63 | ze_bool_t enableTracing = false; 64 | std::vector< tracer_data_t > tracerData; 65 | 66 | context_t(); 67 | ~context_t() = default; 68 | }; 69 | 70 | extern context_t context; 71 | } // namespace instrumented 72 | -------------------------------------------------------------------------------- /source/inc/ze_singleton.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019-2021 Intel Corporation 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | */ 8 | #pragma once 9 | #include 10 | #include 11 | #include 12 | 13 | ////////////////////////////////////////////////////////////////////////// 14 | /// a abstract factory for creation of singleton objects 15 | template 16 | class singleton_factory_t 17 | { 18 | protected: 19 | using singleton_t = _singleton_t; 20 | using key_t = typename std::conditional::value, size_t, _key_t>::type; 21 | 22 | using ptr_t = std::unique_ptr < singleton_t >; 23 | using map_t = std::unordered_map < key_t, ptr_t >; 24 | 25 | std::mutex mut; ///< lock for thread-safety 26 | map_t map; ///< single instance of singleton for each unique key 27 | 28 | ////////////////////////////////////////////////////////////////////////// 29 | /// extract the key from parameter list and if necessary, convert type 30 | template 31 | key_t getKey( _key_t _key, Ts&&... _params ) 32 | { 33 | return reinterpret_cast( _key ); 34 | } 35 | 36 | public: 37 | ////////////////////////////////////////////////////////////////////////// 38 | /// default ctor/dtor 39 | singleton_factory_t() = default; 40 | ~singleton_factory_t() = default; 41 | 42 | ////////////////////////////////////////////////////////////////////////// 43 | /// gets a pointer to a unique instance of singleton 44 | /// if no instance exists, then creates a new instance 45 | /// the params are forwarded to the ctor of the singleton 46 | /// the first parameter must be the unique identifier of the instance 47 | template 48 | _singleton_t* getInstance( Ts&&... _params ) 49 | { 50 | auto key = getKey( std::forward( _params )... ); 51 | 52 | if(key == 0) // No zero keys allowed in map 53 | return static_cast<_singleton_t*>(0); 54 | 55 | std::lock_guard lk( mut ); 56 | auto iter = map.find( key ); 57 | 58 | if( map.end() == iter ) 59 | { 60 | auto ptr = std::make_unique( std::forward( _params )... ); 61 | iter = map.emplace( key, std::move( ptr ) ).first; 62 | } 63 | return iter->second.get(); 64 | } 65 | 66 | ////////////////////////////////////////////////////////////////////////// 67 | /// once the key is no longer valid, release the singleton 68 | void release( _key_t _key ) 69 | { 70 | std::lock_guard lk( mut ); 71 | map.erase( getKey( _key ) ); 72 | } 73 | }; 74 | -------------------------------------------------------------------------------- /source/layers/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Intel Corporation 2 | # SPDX-License-Identifier: MIT 3 | add_subdirectory(validation) 4 | add_subdirectory(tracing) -------------------------------------------------------------------------------- /source/layers/tracing/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Intel Corporation 2 | # SPDX-License-Identifier: MIT 3 | set(TARGET_NAME ze_tracing_layer) 4 | 5 | configure_file( 6 | ${CMAKE_CURRENT_SOURCE_DIR}/ZeTracingLayerVersion.rc.in 7 | ${CMAKE_CURRENT_BINARY_DIR}/ZeTracingLayerVersion.rc 8 | @ONLY) 9 | 10 | add_library(${TARGET_NAME} 11 | SHARED 12 | ${CMAKE_CURRENT_SOURCE_DIR}/ze_tracing_layer.h 13 | ${CMAKE_CURRENT_SOURCE_DIR}/tracing.h 14 | ${CMAKE_CURRENT_SOURCE_DIR}/tracing_imp.h 15 | ${CMAKE_CURRENT_SOURCE_DIR}/ze_tracing_layer.cpp 16 | ${CMAKE_CURRENT_SOURCE_DIR}/ze_trcddi.cpp 17 | ${CMAKE_CURRENT_SOURCE_DIR}/tracing_imp.cpp 18 | ${CMAKE_CURRENT_SOURCE_DIR}/ze_tracing.cpp 19 | ${CMAKE_CURRENT_SOURCE_DIR}/ze_tracing_cb_structs.h 20 | ${CMAKE_CURRENT_SOURCE_DIR}/ze_tracing_register_cb.cpp 21 | ${CMAKE_CURRENT_BINARY_DIR}/ZeTracingLayerVersion.rc 22 | ) 23 | 24 | if(WIN32) 25 | target_sources(${TARGET_NAME} 26 | PRIVATE 27 | ${CMAKE_CURRENT_SOURCE_DIR}/windows/tracing_init.cpp 28 | ) 29 | else() 30 | target_sources(${TARGET_NAME} 31 | PRIVATE 32 | ${CMAKE_CURRENT_SOURCE_DIR}/linux/tracing_init.cpp 33 | ) 34 | endif() 35 | 36 | target_include_directories(${TARGET_NAME} 37 | PUBLIC 38 | ${CMAKE_CURRENT_SOURCE_DIR} 39 | ) 40 | 41 | if(UNIX) 42 | set(GCC_COVERAGE_COMPILE_FLAGS "-fvisibility=hidden -fvisibility-inlines-hidden") 43 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}") 44 | endif() 45 | 46 | set_target_properties(${TARGET_NAME} PROPERTIES 47 | VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}" 48 | SOVERSION "${PROJECT_VERSION_MAJOR}" 49 | ) 50 | 51 | set(SDK_COMPONENT_STRING "level-zero-devel") 52 | set(LIB_COMPONENT_STRING "level-zero") 53 | 54 | if(BUILD_INSTALLER) 55 | set(SDK_COMPONENT_STRING "SDK") 56 | set(LIB_COMPONENT_STRING "Loader") 57 | endif() 58 | 59 | if(MSVC AND L0_DLL_INTEGRITY_CHECKS) 60 | set_target_properties(ze_tracing_layer PROPERTIES LINK_FLAGS "${CMAKE_CXX_LINKER_WRAPPER_FLAG}/INTEGRITYCHECK") 61 | endif() 62 | 63 | install(TARGETS ze_tracing_layer 64 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${SDK_COMPONENT_STRING} 65 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${LIB_COMPONENT_STRING} 66 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${LIB_COMPONENT_STRING} 67 | NAMELINK_COMPONENT ${SDK_COMPONENT_STRING} 68 | ) 69 | -------------------------------------------------------------------------------- /source/layers/tracing/ZeTracingLayerVersion.rc.in: -------------------------------------------------------------------------------- 1 | #define VER_FILEVERSION @PROJECT_VERSION_MAJOR@,@PROJECT_VERSION_MINOR@,@PROJECT_VERSION_PATCH@ 2 | #define VER_FILEVERSION_STR "@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@\0" 3 | 4 | #define VER_PRODUCTVERSION @PROJECT_VERSION_MAJOR@,@PROJECT_VERSION_MINOR@,@PROJECT_VERSION_PATCH@ 5 | #define VER_PRODUCTVERSION_STR "@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@\0" 6 | 7 | #define VER_FILEDESCRIPTION_STR "oneAPI Level Zero API Tracing Layer for Windows(R) Level Zero Drivers" 8 | 9 | #define VER_PRODUCT_NAME_STR "oneAPI Level Zero API Tracing Layer for Windows(R)" 10 | 11 | #define VER_LEGALCOPYRIGHT_STR "Copyright (C) 2020 Intel Corporation" 12 | 13 | 1 VERSIONINFO 14 | FILEVERSION VER_FILEVERSION 15 | PRODUCTVERSION VER_PRODUCTVERSION 16 | BEGIN 17 | BLOCK "StringFileInfo" 18 | BEGIN 19 | BLOCK "040904E4" 20 | BEGIN 21 | VALUE "FileDescription", VER_FILEDESCRIPTION_STR 22 | VALUE "FileVersion", VER_FILEVERSION_STR 23 | VALUE "ProductVersion", VER_PRODUCTVERSION_STR 24 | VALUE "ProductName", VER_PRODUCT_NAME_STR 25 | VALUE "LegalCopyright", VER_LEGALCOPYRIGHT_STR 26 | END 27 | END 28 | 29 | BLOCK "VarFileInfo" 30 | BEGIN 31 | VALUE "Translation", 0x409, 1252 32 | END 33 | END -------------------------------------------------------------------------------- /source/layers/tracing/linux/tracing_init.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019-2021 Intel Corporation 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | */ 8 | #include "../tracing_imp.h" 9 | 10 | namespace tracing_layer 11 | { 12 | void __attribute__((constructor)) createAPITracerContextImp() { 13 | pGlobalAPITracerContextImp = new struct APITracerContextImp; 14 | } 15 | 16 | void __attribute__((destructor)) deleteAPITracerContextImp() { 17 | delete pGlobalAPITracerContextImp; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /source/layers/tracing/tracing.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020-2021 Intel Corporation 3 | * 4 | * SPDX-License-Identifier: MIT 5 | * 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "ze_api.h" 11 | #include "layers/zel_tracing_api.h" 12 | #include "layers/zel_tracing_register_cb.h" 13 | #include "ze_tracing_cb_structs.h" 14 | 15 | struct _zel_tracer_handle_t {}; 16 | 17 | #define TRACING_COMP_NAME "tracing layer" 18 | namespace tracing_layer { 19 | 20 | struct APITracer : _zel_tracer_handle_t { 21 | static APITracer *create(); 22 | virtual ~APITracer() = default; 23 | static APITracer *fromHandle(zel_tracer_handle_t handle) { return static_cast(handle); } 24 | inline zel_tracer_handle_t toHandle() { return this; } 25 | virtual ze_result_t destroyTracer(zel_tracer_handle_t phTracer) = 0; 26 | virtual ze_result_t setPrologues(zel_core_callbacks_t *pCoreCbs) = 0; 27 | virtual ze_result_t setEpilogues(zel_core_callbacks_t *pCoreCbs) = 0; 28 | virtual zel_all_core_callbacks_t& getProEpilogues(zel_tracer_reg_t callback_type, ze_result_t& result) = 0; 29 | virtual ze_result_t resetAllCallbacks() = 0; 30 | virtual ze_result_t enableTracer(ze_bool_t enable) = 0; 31 | }; 32 | 33 | ze_result_t createAPITracer(const zel_tracer_desc_t *desc, zel_tracer_handle_t *phTracer); 34 | 35 | struct APITracerContext { 36 | virtual ~APITracerContext() = default; 37 | virtual void *getActiveTracersList() = 0; 38 | virtual void releaseActivetracersList() = 0; 39 | }; 40 | 41 | } // namespace tracing_layer 42 | -------------------------------------------------------------------------------- /source/layers/tracing/windows/tracing_init.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019-2021 Intel Corporation 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | */ 8 | #include "../tracing_imp.h" 9 | #include 10 | 11 | namespace tracing_layer { 12 | extern "C" BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { 13 | if (fdwReason == DLL_PROCESS_DETACH) { 14 | delete pGlobalAPITracerContextImp; 15 | } else if (fdwReason == DLL_PROCESS_ATTACH) { 16 | pGlobalAPITracerContextImp = new APITracerContextImp; 17 | } 18 | return TRUE; 19 | } 20 | } // namespace tracing_layer 21 | -------------------------------------------------------------------------------- /source/layers/tracing/ze_tracing.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Intel Corporation 3 | * 4 | * SPDX-License-Identifier: MIT 5 | * 6 | */ 7 | 8 | #include "tracing.h" 9 | #include "ze_tracing_layer.h" 10 | #include "layers/zel_tracing_api.h" 11 | #include "layers/zel_tracing_ddi.h" 12 | #include "loader/ze_loader.h" 13 | 14 | namespace tracing { 15 | ZE_APIEXPORT ze_result_t ZE_APICALL 16 | zelTracerCreate( 17 | const zel_tracer_desc_t *desc, 18 | zel_tracer_handle_t *phTracer) { 19 | return tracing_layer::createAPITracer(desc, phTracer); 20 | } 21 | 22 | ZE_APIEXPORT ze_result_t ZE_APICALL 23 | zelTracerDestroy( 24 | zel_tracer_handle_t hTracer) { 25 | return tracing_layer::APITracer::fromHandle(hTracer)->destroyTracer(hTracer); 26 | } 27 | 28 | ZE_APIEXPORT ze_result_t ZE_APICALL 29 | zelTracerSetPrologues( 30 | zel_tracer_handle_t hTracer, 31 | zel_core_callbacks_t *pCoreCbs) { 32 | return tracing_layer::APITracer::fromHandle(hTracer)->setPrologues(pCoreCbs); 33 | } 34 | 35 | ZE_APIEXPORT ze_result_t ZE_APICALL 36 | zelTracerSetEpilogues( 37 | zel_tracer_handle_t hTracer, 38 | zel_core_callbacks_t *pCoreCbs) { 39 | return tracing_layer::APITracer::fromHandle(hTracer)->setEpilogues(pCoreCbs); 40 | } 41 | 42 | ZE_APIEXPORT ze_result_t ZE_APICALL 43 | zelTracerSetEnabled( 44 | zel_tracer_handle_t hTracer, 45 | ze_bool_t enable) { 46 | return tracing_layer::APITracer::fromHandle(hTracer)->enableTracer(enable); 47 | } 48 | 49 | } 50 | #if defined(__cplusplus) 51 | extern "C" { 52 | #endif 53 | 54 | /////////////////////////////////////////////////////////////////////////////// 55 | /// @brief Exported function for filling application's TracerExp table 56 | /// with current process' addresses 57 | /// 58 | /// @returns 59 | /// - ::ZE_RESULT_SUCCESS 60 | /// - ::ZE_RESULT_ERROR_INVALID_NULL_POINTER 61 | /// - ::ZE_RESULT_ERROR_UNSUPPORTED_VERSION 62 | ZE_DLLEXPORT ze_result_t ZE_APICALL 63 | zelGetTracerApiProcAddrTable( 64 | ze_api_version_t version, ///< [in] API version requested 65 | zel_tracer_dditable_t* pDdiTable ///< [in,out] pointer to table of DDI function pointers 66 | ) 67 | { 68 | if( nullptr == pDdiTable ) 69 | return ZE_RESULT_ERROR_INVALID_NULL_POINTER; 70 | 71 | if( tracing_layer::context.version < version ) 72 | return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; 73 | 74 | ze_result_t result = ZE_RESULT_SUCCESS; 75 | 76 | pDdiTable->pfnCreate = tracing::zelTracerCreate; 77 | 78 | pDdiTable->pfnDestroy = tracing::zelTracerDestroy; 79 | 80 | pDdiTable->pfnSetPrologues = tracing::zelTracerSetPrologues; 81 | 82 | pDdiTable->pfnSetEpilogues = tracing::zelTracerSetEpilogues; 83 | 84 | pDdiTable->pfnSetEnabled = tracing::zelTracerSetEnabled; 85 | 86 | return result; 87 | } 88 | 89 | ZE_DLLEXPORT ze_result_t ZE_APICALL 90 | zelLoaderGetVersion(zel_component_version_t *version) 91 | { 92 | if(version == nullptr) 93 | return ZE_RESULT_ERROR_INVALID_NULL_POINTER; 94 | string_copy_s(version->component_name, TRACING_COMP_NAME, ZEL_COMPONENT_STRING_SIZE); 95 | version->spec_version = ZE_API_VERSION_CURRENT; 96 | version->component_lib_version.major = LOADER_VERSION_MAJOR; 97 | version->component_lib_version.minor = LOADER_VERSION_MINOR; 98 | version->component_lib_version.patch = LOADER_VERSION_PATCH; 99 | 100 | return ZE_RESULT_SUCCESS; 101 | } 102 | 103 | 104 | #if defined(__cplusplus) 105 | }; 106 | #endif 107 | -------------------------------------------------------------------------------- /source/layers/tracing/ze_tracing_layer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Intel Corporation 3 | * 4 | * SPDX-License-Identifier: MIT 5 | * 6 | * @file ze_layer.cpp 7 | * 8 | */ 9 | #include "ze_tracing_layer.h" 10 | 11 | namespace tracing_layer 12 | { 13 | context_t context; 14 | 15 | /////////////////////////////////////////////////////////////////////////////// 16 | context_t::context_t() 17 | { 18 | } 19 | 20 | /////////////////////////////////////////////////////////////////////////////// 21 | context_t::~context_t() 22 | { 23 | } 24 | } // namespace tracing_layer 25 | -------------------------------------------------------------------------------- /source/layers/tracing/ze_tracing_layer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020-2022 Intel Corporation 3 | * 4 | * SPDX-License-Identifier: MIT 5 | * 6 | * @file ze_layer.h 7 | * 8 | */ 9 | #pragma once 10 | #include "ze_ddi.h" 11 | #include "ze_util.h" 12 | #include "tracing_imp.h" 13 | 14 | namespace tracing_layer 15 | { 16 | /////////////////////////////////////////////////////////////////////////////// 17 | class __zedlllocal context_t 18 | { 19 | public: 20 | ze_api_version_t version = ZE_API_VERSION_CURRENT; 21 | 22 | ze_dditable_t zeDdiTable = {}; 23 | 24 | context_t(); 25 | ~context_t(); 26 | }; 27 | 28 | extern context_t context; 29 | } // namespace tracing_layer 30 | -------------------------------------------------------------------------------- /source/layers/validation/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020-2023 Intel Corporation 2 | # SPDX-License-Identifier: MIT 3 | set(TARGET_NAME ze_validation_layer) 4 | 5 | configure_file( 6 | ${CMAKE_CURRENT_SOURCE_DIR}/ZeValidationLayerVersion.rc.in 7 | ${CMAKE_CURRENT_BINARY_DIR}/ZeValidationLayerVersion.rc 8 | @ONLY) 9 | 10 | add_library(${TARGET_NAME} 11 | SHARED 12 | ${CMAKE_CURRENT_SOURCE_DIR}/ze_validation_layer.h 13 | ${CMAKE_CURRENT_SOURCE_DIR}/ze_validation_layer.cpp 14 | ${CMAKE_CURRENT_SOURCE_DIR}/ze_valddi.cpp 15 | ${CMAKE_CURRENT_SOURCE_DIR}/zet_valddi.cpp 16 | ${CMAKE_CURRENT_SOURCE_DIR}/zes_valddi.cpp 17 | ${CMAKE_CURRENT_BINARY_DIR}/ZeValidationLayerVersion.rc 18 | ) 19 | 20 | target_include_directories(${TARGET_NAME} 21 | PUBLIC 22 | ${CMAKE_CURRENT_SOURCE_DIR} 23 | ${CMAKE_CURRENT_SOURCE_DIR}/common 24 | ${CMAKE_CURRENT_SOURCE_DIR}/handle_lifetime_tracking 25 | ${CMAKE_CURRENT_SOURCE_DIR}/checkers/parameter_validation 26 | ${CMAKE_CURRENT_SOURCE_DIR}/checkers/template 27 | ${CMAKE_CURRENT_SOURCE_DIR}/../../utils 28 | ) 29 | 30 | target_link_libraries(${TARGET_NAME} PRIVATE level_zero_utils) 31 | 32 | if(UNIX) 33 | set(GCC_COVERAGE_COMPILE_FLAGS "-fvisibility=hidden -fvisibility-inlines-hidden") 34 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}") 35 | endif() 36 | 37 | set_target_properties(${TARGET_NAME} PROPERTIES 38 | VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}" 39 | SOVERSION "${PROJECT_VERSION_MAJOR}" 40 | ) 41 | 42 | set(SDK_COMPONENT_STRING "level-zero-devel") 43 | set(LIB_COMPONENT_STRING "level-zero") 44 | 45 | if(BUILD_INSTALLER) 46 | set(SDK_COMPONENT_STRING "SDK") 47 | set(LIB_COMPONENT_STRING "Loader") 48 | endif() 49 | 50 | if(MSVC AND L0_DLL_INTEGRITY_CHECKS) 51 | set_target_properties(ze_validation_layer PROPERTIES LINK_FLAGS "${CMAKE_CXX_LINKER_WRAPPER_FLAG}/INTEGRITYCHECK") 52 | endif() 53 | 54 | install(TARGETS ze_validation_layer 55 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${SDK_COMPONENT_STRING} 56 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${LIB_COMPONENT_STRING} 57 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${LIB_COMPONENT_STRING} 58 | NAMELINK_COMPONENT ${SDK_COMPONENT_STRING} 59 | ) 60 | 61 | add_subdirectory(handle_lifetime_tracking) 62 | add_subdirectory(checkers) 63 | -------------------------------------------------------------------------------- /source/layers/validation/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | We encourage anyone who wants to contribute to the validation layer to submit 4 | [Issues](https://github.com/oneapi-src/level-zero/issues) and 5 | [Pull Requests](https://github.com/oneapi-src/level-zero/pulls). We will help 6 | review these for proper alignment with the 7 | [Level Zero Specification](https://spec.oneapi.com/level-zero/latest/index.html). 8 | 9 | ## C++ Coding Standards 10 | 11 | * C++14 maximum support 12 | * Avoid C Arrays, replace with `std::array<>` / `std::vector<>` 13 | * Avoid "magic numbers" 14 | * Avoid C-style memory allocations in favor of C++ 15 | * Use `nullptr` instead of `NULL` 16 | * Don't add `void` to empty argument lists 17 | * Use `std::unique_ptr` in place of `std::auto_ptr` 18 | 19 | ## Validation Checkers 20 | 21 | * To allow for dynamic validation of input/outputs from all Level Zero APIs, the Validation Layer supports pluggable validation checkers. 22 | * These pluggable validation checkers are compiled into the Validation layer and can be enabled thru per checker environment variables. 23 | * Current Checkers are: 24 | * * `PARAMETER_VALIDATION` 25 | * To create your own checker, one must first generate the skeleton for the new checker using the `scripts/generate_checker.py`. 26 | * Generate a checker template thru: 27 | * * `python3 ./scripts/generate_checker.py .` 28 | * * this will create a new folder at `source/layers/validation/checkers/` 29 | * * this folder will have 3 files, the `CMakeLists.txt` include file, `zel__checker.cpp`, and `zel__checker.h` 30 | * * Naming Convention of the Checkers in the generator is `PascalCase`. 31 | * * An `EXAMPLE` Checker is located [here](./checkers/template/zel_template_checker.cpp) 32 | * Once one has generated the checker files, one can define intercepts for any of the functions in the Level Zero Specification. 33 | * Each function allows for Prologue and Epilogue intercepts to check both the pre and post call parameters. 34 | * In your generated class, one can overide any functions with: 35 | * * `Prologue(` 36 | * * `Epilogue(` 37 | * Once your checker meets your needs, include your checker in the compile by adding your new checker folder to: 38 | * * `source/layers/validation/checkers/CMakeLists.txt` 39 | * Your new checker will need to be enabled during runtime with `ZEL_ENABLE__CHECKER=1` when the validation layer is enabled with `ZE_ENABLE_VALIDATION_LAYER=1`. 40 | 41 | ## Sign Your Work 42 | 43 | Please use the sign-off line at the end of your patch. Your signature certifies 44 | that you wrote the patch or otherwise have the right to pass it on as an 45 | open-source patch. To do so, if you can certify the below 46 | (from [developercertificate.org](http://developercertificate.org/)): 47 | 48 | ``` 49 | Developer Certificate of Origin 50 | Version 1.1 51 | 52 | Copyright (C) 2004, 2006 The Linux Foundation and its contributors. 53 | 660 York Street, Suite 102, 54 | San Francisco, CA 94110 USA 55 | 56 | Everyone is permitted to copy and distribute verbatim copies of this 57 | license document, but changing it is not allowed. 58 | 59 | Developer's Certificate of Origin 1.1 60 | 61 | By making a contribution to this project, I certify that: 62 | 63 | (a) The contribution was created in whole or in part by me and I 64 | have the right to submit it under the open source license 65 | indicated in the file; or 66 | 67 | (b) The contribution is based upon previous work that, to the best 68 | of my knowledge, is covered under an appropriate open source 69 | license and I have the right under that license to submit that 70 | work with modifications, whether created in whole or in part 71 | by me, under the same open source license (unless I am 72 | permitted to submit under a different license), as indicated 73 | in the file; or 74 | 75 | (c) The contribution was provided directly to me by some other 76 | person who certified (a), (b) or (c) and I have not modified 77 | it. 78 | 79 | (d) I understand and agree that this project and the contribution 80 | are public and that a record of the contribution (including all 81 | personal information I submit with it, including my sign-off) is 82 | maintained indefinitely and may be redistributed consistent with 83 | this project or the open source license(s) involved. 84 | ``` 85 | 86 | Then add a line to every git commit message: 87 | 88 | Signed-off-by: Kris Smith 89 | 90 | Use your real name (sorry, no pseudonyms or anonymous contributions). 91 | 92 | If you set your `user.name` and `user.email` git configs, you can sign your 93 | commit automatically with `git commit -s`. -------------------------------------------------------------------------------- /source/layers/validation/ZeValidationLayerVersion.rc.in: -------------------------------------------------------------------------------- 1 | #define VER_FILEVERSION @PROJECT_VERSION_MAJOR@,@PROJECT_VERSION_MINOR@,@PROJECT_VERSION_PATCH@ 2 | #define VER_FILEVERSION_STR "@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@\0" 3 | 4 | #define VER_PRODUCTVERSION @PROJECT_VERSION_MAJOR@,@PROJECT_VERSION_MINOR@,@PROJECT_VERSION_PATCH@ 5 | #define VER_PRODUCTVERSION_STR "@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@\0" 6 | 7 | #define VER_FILEDESCRIPTION_STR "oneAPI Level Zero Validation Layer for Windows(R) Level Zero Drivers" 8 | 9 | #define VER_PRODUCT_NAME_STR "oneAPI Level Zero Validation Layer for Windows(R)" 10 | 11 | #define VER_LEGALCOPYRIGHT_STR "Copyright (C) 2020 Intel Corporation" 12 | 13 | 1 VERSIONINFO 14 | FILEVERSION VER_FILEVERSION 15 | PRODUCTVERSION VER_PRODUCTVERSION 16 | BEGIN 17 | BLOCK "StringFileInfo" 18 | BEGIN 19 | BLOCK "040904E4" 20 | BEGIN 21 | VALUE "FileDescription", VER_FILEDESCRIPTION_STR 22 | VALUE "FileVersion", VER_FILEVERSION_STR 23 | VALUE "ProductVersion", VER_PRODUCTVERSION_STR 24 | VALUE "ProductName", VER_PRODUCT_NAME_STR 25 | VALUE "LegalCopyright", VER_LEGALCOPYRIGHT_STR 26 | END 27 | END 28 | 29 | BLOCK "VarFileInfo" 30 | BEGIN 31 | VALUE "Translation", 0x409, 1252 32 | END 33 | END -------------------------------------------------------------------------------- /source/layers/validation/checkers/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(basic_leak) 2 | add_subdirectory(events_checker) 3 | add_subdirectory(parameter_validation) 4 | add_subdirectory(template) 5 | -------------------------------------------------------------------------------- /source/layers/validation/checkers/basic_leak/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | target_sources(${TARGET_NAME} 2 | PRIVATE 3 | ${CMAKE_CURRENT_LIST_DIR}/zel_basic_leak_checker.h 4 | ${CMAKE_CURRENT_LIST_DIR}/zel_basic_leak_checker.cpp 5 | ) -------------------------------------------------------------------------------- /source/layers/validation/checkers/events_checker/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | target_sources(${TARGET_NAME} 2 | PRIVATE 3 | ${CMAKE_CURRENT_LIST_DIR}/zel_events_checker.h 4 | ${CMAKE_CURRENT_LIST_DIR}/zel_events_checker.cpp 5 | 6 | ${THIRD_PARTY_SOURCE_DIR}/xla/graphcycles.cc 7 | ) 8 | 9 | target_include_directories(${TARGET_NAME} 10 | PRIVATE 11 | ${THIRD_PARTY_SOURCE_DIR} 12 | ) 13 | -------------------------------------------------------------------------------- /source/layers/validation/checkers/events_checker/DESIGN.md: -------------------------------------------------------------------------------- 1 | # Events Deadlock Checker Design Document 2 | This document outlines the design and implementation details of the events checker. 3 | 4 | ## Introduction 5 | The Events Checker validates usage of events. 6 | - It is designed to detect potential deadlocks that might occur due to improper event usage in the Level Zero API. It prints out warning messages for user when it detects a potential deadlock. 7 | - It may also detect whether an event is being used more than once without being reset. Consider a case in which a single event is signaled from twice. 8 | 9 | ## Objectives 10 | - Detect potential deadlocks caused by event usage. 11 | - Provide detailed information to help developers identify and resolve deadlock issues. 12 | 13 | ## Design Overview 14 | The checker creates an internal Directed Acyclic Graph (DAG) of dependencies between API calls (the actions that are nodes in the graph) and events (the edges in the graph). It also maintains a topological sort and when an attempt is made to insert an edge that causes a cycle in the graph it warns the user of a potential deadlock and returns without inserting that edge. 15 | 16 | ## API Implemented 17 | ### zeEventCreate 18 | ### zeEventDestroy 19 | ### zeCommandListAppendMemoryCopy 20 | ### zeCommandListAppendWriteGlobalTimestamp 21 | ### zeCommandListAppendBarrier 22 | ### zeCommandListAppendMemoryRangesBarrier 23 | ### zeCommandListAppendMemoryFill 24 | ### zeCommandListAppendMemoryCopyRegion 25 | ### zeCommandListAppendMemoryCopyFromContext 26 | ### zeCommandListAppendImageCopy 27 | ### zeCommandListAppendImageCopyRegion 28 | ### zeCommandListAppendImageCopyToMemory 29 | ### zeCommandListAppendImageCopyFromMemory 30 | ### zeCommandListAppendSignalEvent 31 | ### zeCommandListAppendWaitOnEvents 32 | ### zeEventHostSignal 33 | ### zeCommandListAppendEventReset 34 | ### zeEventHostReset 35 | ### zeCommandListAppendQueryKernelTimestamp 36 | ### zeCommandListAppendLaunchKernel 37 | ### zeCommandListAppendLaunchCooperativeKernel 38 | ### zeCommandListAppendLaunchKernelIndirect 39 | ### zeCommandListAppendLaunchMultipleKernelsIndirect 40 | ### zeCommandListUpdateMutableCommandSignalEventExp 41 | ### zeCommandListUpdateMutableCommandWaitEventsExp 42 | ### zeCommandListAppendImageCopyToMemoryExt 43 | ### zeCommandListAppendImageCopyFromMemoryExt 44 | ### zeCommandListImmediateAppendCommandListsExp 45 | -------------------------------------------------------------------------------- /source/layers/validation/checkers/parameter_validation/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | target_sources(${TARGET_NAME} 2 | PRIVATE 3 | ${CMAKE_CURRENT_LIST_DIR}/param_validation.h 4 | ${CMAKE_CURRENT_LIST_DIR}/ze_parameter_validation.cpp 5 | ${CMAKE_CURRENT_LIST_DIR}/ze_parameter_validation.h 6 | ${CMAKE_CURRENT_LIST_DIR}/zes_parameter_validation.cpp 7 | ${CMAKE_CURRENT_LIST_DIR}/zes_parameter_validation.h 8 | ${CMAKE_CURRENT_LIST_DIR}/zet_parameter_validation.cpp 9 | ${CMAKE_CURRENT_LIST_DIR}/zet_parameter_validation.h 10 | ) 11 | 12 | -------------------------------------------------------------------------------- /source/layers/validation/checkers/parameter_validation/param_validation.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #pragma once 4 | 5 | #include "ze_validation_layer.h" 6 | #include "ze_parameter_validation.h" 7 | #include "zet_parameter_validation.h" 8 | #include "zes_parameter_validation.h" 9 | #include 10 | 11 | 12 | namespace validation_layer 13 | { 14 | 15 | class parameterValidationChecker : public validationChecker { 16 | public: 17 | parameterValidationChecker(); 18 | ~parameterValidationChecker(); 19 | bool enableParameterValidation = false; 20 | }; 21 | extern class parameterValidationChecker parameterChecker; 22 | 23 | class ParameterValidation { 24 | public: 25 | ZEParameterValidation zeParamValidation; 26 | ZESParameterValidation zesParamValidation; 27 | ZETParameterValidation zetParamValidation; 28 | template static ze_result_t validateExtensions(T descriptor); 29 | }; 30 | 31 | template 32 | ze_result_t ParameterValidation::validateExtensions(T descriptor){ 33 | return ZE_RESULT_SUCCESS; 34 | } 35 | 36 | #include "extension_validation.inl" 37 | 38 | } -------------------------------------------------------------------------------- /source/layers/validation/checkers/template/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | target_sources(${TARGET_NAME} 2 | PRIVATE 3 | ${CMAKE_CURRENT_LIST_DIR}/zel_template_checker.h 4 | ${CMAKE_CURRENT_LIST_DIR}/zel_template_checker.cpp 5 | ) 6 | 7 | -------------------------------------------------------------------------------- /source/layers/validation/checkers/template/zel_template_checker.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2024 Intel Corporation 3 | * 4 | * SPDX-License-Identifier: MIT 5 | * 6 | * @file zel_template_checker.cpp 7 | * 8 | */ 9 | #include "zel_template_checker.h" 10 | 11 | namespace validation_layer 12 | { 13 | class validationCheckerTemplate templateChecker; 14 | 15 | validationCheckerTemplate::validationCheckerTemplate() { 16 | enableValidationCheckerTemplate = getenv_tobool( "ZEL_ENABLE_VALIDATION_CHECKER_TEMPLATE" ); 17 | if(enableValidationCheckerTemplate) { 18 | validationCheckerTemplate::ZEvalidationCheckerTemplate *zeChecker = new validationCheckerTemplate::ZEvalidationCheckerTemplate; 19 | validationCheckerTemplate::ZESvalidationCheckerTemplate *zesChecker = new validationCheckerTemplate::ZESvalidationCheckerTemplate; 20 | validationCheckerTemplate::ZETvalidationCheckerTemplate *zetChecker = new validationCheckerTemplate::ZETvalidationCheckerTemplate; 21 | templateChecker.zeValidation = zeChecker; 22 | templateChecker.zetValidation = zetChecker; 23 | templateChecker.zesValidation = zesChecker; 24 | validation_layer::context.getInstance().validationHandlers.push_back(&templateChecker); 25 | } 26 | } 27 | 28 | validationCheckerTemplate::~validationCheckerTemplate() { 29 | if(enableValidationCheckerTemplate) { 30 | delete templateChecker.zeValidation; 31 | delete templateChecker.zetValidation; 32 | delete templateChecker.zesValidation; 33 | } 34 | } 35 | 36 | ze_result_t 37 | validationCheckerTemplate::ZEvalidationCheckerTemplate::zeInitPrologue( 38 | ze_init_flags_t flags) 39 | { 40 | return ZE_RESULT_SUCCESS; 41 | } 42 | 43 | ze_result_t 44 | validationCheckerTemplate::ZESvalidationCheckerTemplate::zesInitPrologue( 45 | zes_init_flags_t flags) 46 | { 47 | return ZE_RESULT_SUCCESS; 48 | } 49 | 50 | ze_result_t 51 | validationCheckerTemplate::ZETvalidationCheckerTemplate::zetModuleGetDebugInfoPrologue( 52 | zet_module_handle_t hModule, 53 | zet_module_debug_info_format_t format, 54 | size_t* pSize, 55 | uint8_t* pDebugInfo 56 | ) 57 | { 58 | return ZE_RESULT_SUCCESS; 59 | } 60 | 61 | } -------------------------------------------------------------------------------- /source/layers/validation/checkers/template/zel_template_checker.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2024 Intel Corporation 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * @file zel_template_checker.h 8 | * 9 | */ 10 | 11 | #pragma once 12 | 13 | #include 14 | #include "ze_api.h" 15 | #include "ze_validation_layer.h" 16 | 17 | namespace validation_layer 18 | { 19 | class __zedlllocal validationCheckerTemplate : public validationChecker{ 20 | public: 21 | validationCheckerTemplate(); 22 | ~validationCheckerTemplate(); 23 | 24 | class ZEvalidationCheckerTemplate : public ZEValidationEntryPoints { 25 | public: 26 | ze_result_t zeInitPrologue( ze_init_flags_t flags ) override; 27 | }; 28 | class ZESvalidationCheckerTemplate : public ZESValidationEntryPoints { 29 | public: 30 | ze_result_t zesInitPrologue( zes_init_flags_t flags ) override; 31 | }; 32 | class ZETvalidationCheckerTemplate : public ZETValidationEntryPoints { 33 | public: 34 | ze_result_t zetModuleGetDebugInfoPrologue( zet_module_handle_t hModule, zet_module_debug_info_format_t format, size_t* pSize, uint8_t* pDebugInfo ) override; 35 | }; 36 | bool enableValidationCheckerTemplate = false; 37 | }; 38 | extern class validationCheckerTemplate templateChecker; 39 | } -------------------------------------------------------------------------------- /source/layers/validation/handle_lifetime_tracking/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | target_sources(${TARGET_NAME} 2 | PRIVATE 3 | ${CMAKE_CURRENT_LIST_DIR}/handle_lifetime.h 4 | ${CMAKE_CURRENT_LIST_DIR}/ze_handle_lifetime.cpp 5 | ${CMAKE_CURRENT_LIST_DIR}/ze_handle_lifetime.h 6 | ${CMAKE_CURRENT_LIST_DIR}/zes_handle_lifetime.cpp 7 | ${CMAKE_CURRENT_LIST_DIR}/zes_handle_lifetime.h 8 | ${CMAKE_CURRENT_LIST_DIR}/zet_handle_lifetime.cpp 9 | ${CMAKE_CURRENT_LIST_DIR}/zet_handle_lifetime.h 10 | ) 11 | -------------------------------------------------------------------------------- /source/layers/validation/ze_validation_layer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019-2021 Intel Corporation 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * @file ze_validation_layer.cpp 8 | * 9 | */ 10 | #include "ze_validation_layer.h" 11 | #include "param_validation.h" 12 | #include 13 | 14 | namespace validation_layer 15 | { 16 | context_t& context = context_t::getInstance(); 17 | 18 | /////////////////////////////////////////////////////////////////////////////// 19 | context_t::context_t() 20 | { 21 | enableHandleLifetime = getenv_tobool( "ZE_ENABLE_HANDLE_LIFETIME" ); 22 | if (enableHandleLifetime) { 23 | handleLifetime = std::make_unique(); 24 | } 25 | enableThreadingValidation = getenv_tobool( "ZE_ENABLE_THREADING_VALIDATION" ); 26 | 27 | logger = loader::createLogger(); 28 | } 29 | 30 | /////////////////////////////////////////////////////////////////////////////// 31 | context_t::~context_t() 32 | { 33 | validationHandlers.clear(); 34 | } 35 | } // namespace validation_layer 36 | 37 | 38 | #if defined(__cplusplus) 39 | extern "C" { 40 | #endif 41 | 42 | ZE_DLLEXPORT ze_result_t ZE_APICALL 43 | zelLoaderGetVersion(zel_component_version_t *version) 44 | { 45 | if(version == nullptr) 46 | return ZE_RESULT_ERROR_INVALID_NULL_POINTER; 47 | string_copy_s(version->component_name, VALIDATION_COMP_NAME, ZEL_COMPONENT_STRING_SIZE); 48 | version->spec_version = ZE_API_VERSION_CURRENT; 49 | version->component_lib_version.major = LOADER_VERSION_MAJOR; 50 | version->component_lib_version.minor = LOADER_VERSION_MINOR; 51 | version->component_lib_version.patch = LOADER_VERSION_PATCH; 52 | 53 | return ZE_RESULT_SUCCESS; 54 | } 55 | 56 | #if defined(__cplusplus) 57 | }; 58 | #endif 59 | -------------------------------------------------------------------------------- /source/layers/validation/ze_validation_layer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019-2021 Intel Corporation 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * @file ze_layer.h 8 | * 9 | */ 10 | #pragma once 11 | #include "ze_ddi.h" 12 | #include "zet_ddi.h" 13 | #include "zes_ddi.h" 14 | #include "ze_util.h" 15 | #include "loader/ze_loader.h" 16 | #include "handle_lifetime.h" 17 | #include "ze_entry_points.h" 18 | #include "zet_entry_points.h" 19 | #include "zes_entry_points.h" 20 | #include "logging.h" 21 | #include 22 | #include 23 | 24 | #define VALIDATION_COMP_NAME "validation layer" 25 | 26 | namespace validation_layer 27 | { 28 | /////////////////////////////////////////////////////////////////////////////// 29 | 30 | class validationChecker { 31 | public: 32 | ZEValidationEntryPoints *zeValidation; 33 | ZESValidationEntryPoints *zesValidation; 34 | ZETValidationEntryPoints *zetValidation; 35 | }; 36 | class __zedlllocal context_t 37 | { 38 | public: 39 | ze_api_version_t version = ZE_API_VERSION_CURRENT; 40 | 41 | bool enableHandleLifetime = false; 42 | bool enableThreadingValidation = false; 43 | 44 | ze_dditable_t zeDdiTable = {}; 45 | zet_dditable_t zetDdiTable = {}; 46 | zes_dditable_t zesDdiTable = {}; 47 | 48 | std::vector validationHandlers; 49 | std::unique_ptr handleLifetime; 50 | 51 | std::shared_ptr logger; 52 | 53 | static context_t& getInstance() { 54 | static context_t instance; 55 | return instance; 56 | } 57 | context_t(); 58 | ~context_t(); 59 | }; 60 | 61 | extern context_t& context; 62 | } // namespace validation_layer 63 | -------------------------------------------------------------------------------- /source/level-zero.pc.in: -------------------------------------------------------------------------------- 1 | prefix=${pcfiledir}/@pkgconfig_prefix@ 2 | includedir=${prefix}/@pkgconfig_include_dir@ 3 | libdir=${prefix}/@pkgconfig_lib_dir@ 4 | 5 | Name: Level Zero 6 | Description: Level Zero 7 | URL: https://github.com/oneapi-src/level-zero 8 | Version: @PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@ 9 | Requires: libze_loader 10 | Libs: -L${libdir} 11 | CFlags: -I${includedir}/level_zero 12 | -------------------------------------------------------------------------------- /source/lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | target_sources(${TARGET_LOADER_NAME} 4 | PRIVATE 5 | ${CMAKE_CURRENT_SOURCE_DIR}/ze_libapi.cpp 6 | ${CMAKE_CURRENT_SOURCE_DIR}/ze_libddi.cpp 7 | ${CMAKE_CURRENT_SOURCE_DIR}/zet_libapi.cpp 8 | ${CMAKE_CURRENT_SOURCE_DIR}/zet_libddi.cpp 9 | ${CMAKE_CURRENT_SOURCE_DIR}/zes_libapi.cpp 10 | ${CMAKE_CURRENT_SOURCE_DIR}/zes_libddi.cpp 11 | ${CMAKE_CURRENT_SOURCE_DIR}/zel_tracing_libapi.cpp 12 | ${CMAKE_CURRENT_SOURCE_DIR}/zel_tracing_libddi.cpp 13 | ${CMAKE_CURRENT_SOURCE_DIR}/ze_lib.h 14 | ${CMAKE_CURRENT_SOURCE_DIR}/ze_lib.cpp 15 | ${CMAKE_CURRENT_SOURCE_DIR}/ze_tracing_register_cb_libapi.cpp 16 | ) 17 | 18 | 19 | 20 | if(WIN32) 21 | target_sources(${TARGET_LOADER_NAME} 22 | PRIVATE 23 | ${CMAKE_CURRENT_SOURCE_DIR}/windows/lib_init.cpp 24 | ) 25 | else() 26 | target_sources(${TARGET_LOADER_NAME} 27 | PRIVATE 28 | ${CMAKE_CURRENT_SOURCE_DIR}/linux/lib_init.cpp 29 | ) 30 | endif() 31 | 32 | -------------------------------------------------------------------------------- /source/lib/linux/lib_init.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2021 Intel Corporation 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | */ 8 | 9 | #include "../ze_lib.h" 10 | 11 | namespace ze_lib 12 | { 13 | #ifndef L0_STATIC_LOADER_BUILD 14 | void __attribute__((constructor)) createLibContext() { 15 | context = new context_t; 16 | } 17 | void __attribute__((destructor)) deleteLibContext() { 18 | delete context; 19 | } 20 | #endif 21 | 22 | } -------------------------------------------------------------------------------- /source/lib/windows/lib_init.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2021 Intel Corporation 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | */ 8 | 9 | #include "../ze_lib.h" 10 | #ifndef L0_STATIC_LOADER_BUILD 11 | #include "../loader/ze_loader_internal.h" 12 | #endif 13 | 14 | namespace ze_lib 15 | { 16 | #ifndef L0_STATIC_LOADER_BUILD 17 | extern "C" BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { 18 | if (fdwReason == DLL_PROCESS_DETACH) { 19 | delete context; 20 | delete loader::context; 21 | } else if (fdwReason == DLL_PROCESS_ATTACH) { 22 | context = new context_t; 23 | loader::context = new loader::context_t; 24 | } 25 | return TRUE; 26 | } 27 | 28 | #endif 29 | } 30 | -------------------------------------------------------------------------------- /source/lib/zel_tracing_libddi.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020-2022 Intel Corporation 3 | * 4 | * SPDX-License-Identifier: MIT 5 | * 6 | * @file zel_tracing_libddi.cpp 7 | * Perhaps have this generated at some point. 8 | * 9 | */ 10 | #include "ze_lib.h" 11 | #include "layers/zel_tracing_ddi.h" 12 | 13 | namespace ze_lib 14 | { 15 | /////////////////////////////////////////////////////////////////////////////// 16 | 17 | #ifdef L0_STATIC_LOADER_BUILD 18 | __zedlllocal ze_result_t context_t::zelTracingDdiTableInit(ze_api_version_t version) 19 | { 20 | ze_result_t result = ZE_RESULT_SUCCESS; 21 | 22 | if( ZE_RESULT_SUCCESS == result ) 23 | { 24 | auto getTable = reinterpret_cast( 25 | GET_FUNCTION_PTR(loader, "zelGetTracerApiProcAddrTable") ); 26 | result = getTableWithCheck(getTable, version, &zelTracingDdiTable.Tracer); 27 | } 28 | 29 | return result; 30 | } 31 | #else 32 | __zedlllocal ze_result_t context_t::zelTracingDdiTableInit(ze_api_version_t version) 33 | { 34 | ze_result_t result; 35 | result = zelGetTracerApiProcAddrTable( ZE_API_VERSION_CURRENT, &zelTracingDdiTable.Tracer); 36 | return result; 37 | } 38 | #endif 39 | } // namespace ze_lib 40 | -------------------------------------------------------------------------------- /source/libze_loader.pc.in: -------------------------------------------------------------------------------- 1 | prefix=${pcfiledir}/@pkgconfig_prefix@ 2 | includedir=${prefix}/@pkgconfig_include_dir@ 3 | libdir=${prefix}/@pkgconfig_lib_dir@ 4 | 5 | Name: Level Zero Loader 6 | Description: Runtime Library Loader for Level Zero 7 | URL: https://github.com/oneapi-src/level-zero 8 | Version: @PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@ 9 | Requires: 10 | Libs: -L${libdir} -lze_loader 11 | CFlags: -I${includedir} 12 | -------------------------------------------------------------------------------- /source/loader/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Intel Corporation 2 | # SPDX-License-Identifier: MIT 3 | 4 | 5 | target_sources(${TARGET_LOADER_NAME} 6 | PRIVATE 7 | ${CMAKE_CURRENT_SOURCE_DIR}/ze_object.h 8 | ${CMAKE_CURRENT_SOURCE_DIR}/ze_loader_internal.h 9 | ${CMAKE_CURRENT_SOURCE_DIR}/ze_loader.cpp 10 | ${CMAKE_CURRENT_SOURCE_DIR}/ze_loader_api.cpp 11 | ${CMAKE_CURRENT_SOURCE_DIR}/ze_ldrddi.h 12 | ${CMAKE_CURRENT_SOURCE_DIR}/ze_ldrddi.cpp 13 | ${CMAKE_CURRENT_SOURCE_DIR}/zet_ldrddi.h 14 | ${CMAKE_CURRENT_SOURCE_DIR}/zet_ldrddi.cpp 15 | ${CMAKE_CURRENT_SOURCE_DIR}/zes_ldrddi.h 16 | ${CMAKE_CURRENT_SOURCE_DIR}/zes_ldrddi.cpp 17 | ${CMAKE_CURRENT_SOURCE_DIR}/zel_tracing_ldrddi.cpp 18 | ${CMAKE_CURRENT_SOURCE_DIR}/driver_discovery.h 19 | ) 20 | 21 | if(WIN32) 22 | target_sources(${TARGET_LOADER_NAME} 23 | PRIVATE 24 | ${CMAKE_CURRENT_SOURCE_DIR}/windows/driver_discovery_win.cpp 25 | ${CMAKE_CURRENT_SOURCE_DIR}/windows/loader_init.cpp 26 | ) 27 | else() 28 | target_sources(${TARGET_LOADER_NAME} 29 | PRIVATE 30 | ${CMAKE_CURRENT_SOURCE_DIR}/linux/driver_discovery_lin.cpp 31 | ${CMAKE_CURRENT_SOURCE_DIR}/linux/loader_init.cpp 32 | ) 33 | endif() 34 | 35 | -------------------------------------------------------------------------------- /source/loader/driver_discovery.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2020 Intel Corporation 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | */ 8 | 9 | #pragma once 10 | 11 | #include 12 | #include 13 | 14 | namespace loader { 15 | 16 | using DriverLibraryPath = std::string; 17 | 18 | std::vector discoverEnabledDrivers(); 19 | 20 | } // namespace loader 21 | -------------------------------------------------------------------------------- /source/loader/linux/driver_discovery_lin.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2020 Intel Corporation 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | */ 8 | 9 | #include "source/loader/driver_discovery.h" 10 | 11 | #include "source/inc/ze_util.h" 12 | #include 13 | #include 14 | #include 15 | 16 | namespace loader { 17 | 18 | static const char *knownDriverNames[] = { 19 | MAKE_LIBRARY_NAME("ze_intel_gpu", "1"), 20 | MAKE_LIBRARY_NAME("ze_intel_gpu_legacy1", "1"), 21 | MAKE_LIBRARY_NAME("ze_intel_vpu", "1"), 22 | MAKE_LIBRARY_NAME("ze_intel_npu", "1"), 23 | }; 24 | 25 | std::vector discoverEnabledDrivers() { 26 | std::vector enabledDrivers; 27 | const char *altDrivers = nullptr; 28 | 29 | // ZE_ENABLE_ALT_DRIVERS is for development/debug only 30 | altDrivers = getenv("ZE_ENABLE_ALT_DRIVERS"); 31 | if (altDrivers == nullptr) { 32 | for (auto path : knownDriverNames) { 33 | enabledDrivers.emplace_back(path); 34 | } 35 | } else { 36 | std::stringstream ss(altDrivers); 37 | while (ss.good()) { 38 | std::string substr; 39 | getline(ss, substr, ','); 40 | enabledDrivers.emplace_back(substr); 41 | } 42 | } 43 | return enabledDrivers; 44 | } 45 | 46 | } // namespace loader 47 | -------------------------------------------------------------------------------- /source/loader/linux/loader_init.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2021 Intel Corporation 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | */ 8 | 9 | #include "../ze_loader_internal.h" 10 | 11 | namespace loader 12 | { 13 | #ifndef L0_STATIC_LOADER_BUILD 14 | void __attribute__((constructor)) createLoaderContext() { 15 | context = new context_t; 16 | } 17 | 18 | void __attribute__((destructor)) deleteLoaderContext() { 19 | delete context; 20 | } 21 | #endif 22 | } -------------------------------------------------------------------------------- /source/loader/windows/loader_init.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2021 Intel Corporation 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | */ 8 | 9 | #include "../ze_loader_internal.h" 10 | 11 | namespace loader 12 | { 13 | #ifdef L0_STATIC_LOADER_BUILD 14 | extern "C" BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { 15 | if (fdwReason == DLL_PROCESS_DETACH) { 16 | delete context; 17 | } else if (fdwReason == DLL_PROCESS_ATTACH) { 18 | context = new context_t; 19 | } 20 | return TRUE; 21 | } 22 | #endif 23 | } -------------------------------------------------------------------------------- /source/loader/ze_ldrddi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019-2024 Intel Corporation 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * @file ze_ldrddi.h 8 | * 9 | */ 10 | #pragma once 11 | 12 | namespace loader 13 | { 14 | /////////////////////////////////////////////////////////////////////////////// 15 | using ze_driver_object_t = object_t < ze_driver_handle_t >; 16 | using ze_driver_factory_t = singleton_factory_t < ze_driver_object_t, ze_driver_handle_t >; 17 | 18 | using ze_device_object_t = object_t < ze_device_handle_t >; 19 | using ze_device_factory_t = singleton_factory_t < ze_device_object_t, ze_device_handle_t >; 20 | 21 | using ze_context_object_t = object_t < ze_context_handle_t >; 22 | using ze_context_factory_t = singleton_factory_t < ze_context_object_t, ze_context_handle_t >; 23 | 24 | using ze_command_queue_object_t = object_t < ze_command_queue_handle_t >; 25 | using ze_command_queue_factory_t = singleton_factory_t < ze_command_queue_object_t, ze_command_queue_handle_t >; 26 | 27 | using ze_command_list_object_t = object_t < ze_command_list_handle_t >; 28 | using ze_command_list_factory_t = singleton_factory_t < ze_command_list_object_t, ze_command_list_handle_t >; 29 | 30 | using ze_fence_object_t = object_t < ze_fence_handle_t >; 31 | using ze_fence_factory_t = singleton_factory_t < ze_fence_object_t, ze_fence_handle_t >; 32 | 33 | using ze_event_pool_object_t = object_t < ze_event_pool_handle_t >; 34 | using ze_event_pool_factory_t = singleton_factory_t < ze_event_pool_object_t, ze_event_pool_handle_t >; 35 | 36 | using ze_event_object_t = object_t < ze_event_handle_t >; 37 | using ze_event_factory_t = singleton_factory_t < ze_event_object_t, ze_event_handle_t >; 38 | 39 | using ze_image_object_t = object_t < ze_image_handle_t >; 40 | using ze_image_factory_t = singleton_factory_t < ze_image_object_t, ze_image_handle_t >; 41 | 42 | using ze_module_object_t = object_t < ze_module_handle_t >; 43 | using ze_module_factory_t = singleton_factory_t < ze_module_object_t, ze_module_handle_t >; 44 | 45 | using ze_module_build_log_object_t = object_t < ze_module_build_log_handle_t >; 46 | using ze_module_build_log_factory_t = singleton_factory_t < ze_module_build_log_object_t, ze_module_build_log_handle_t >; 47 | 48 | using ze_kernel_object_t = object_t < ze_kernel_handle_t >; 49 | using ze_kernel_factory_t = singleton_factory_t < ze_kernel_object_t, ze_kernel_handle_t >; 50 | 51 | using ze_sampler_object_t = object_t < ze_sampler_handle_t >; 52 | using ze_sampler_factory_t = singleton_factory_t < ze_sampler_object_t, ze_sampler_handle_t >; 53 | 54 | using ze_physical_mem_object_t = object_t < ze_physical_mem_handle_t >; 55 | using ze_physical_mem_factory_t = singleton_factory_t < ze_physical_mem_object_t, ze_physical_mem_handle_t >; 56 | 57 | using ze_fabric_vertex_object_t = object_t < ze_fabric_vertex_handle_t >; 58 | using ze_fabric_vertex_factory_t = singleton_factory_t < ze_fabric_vertex_object_t, ze_fabric_vertex_handle_t >; 59 | 60 | using ze_fabric_edge_object_t = object_t < ze_fabric_edge_handle_t >; 61 | using ze_fabric_edge_factory_t = singleton_factory_t < ze_fabric_edge_object_t, ze_fabric_edge_handle_t >; 62 | 63 | using ze_external_semaphore_ext_object_t = object_t < ze_external_semaphore_ext_handle_t >; 64 | using ze_external_semaphore_ext_factory_t = singleton_factory_t < ze_external_semaphore_ext_object_t, ze_external_semaphore_ext_handle_t >; 65 | 66 | using ze_rtas_builder_ext_object_t = object_t < ze_rtas_builder_ext_handle_t >; 67 | using ze_rtas_builder_ext_factory_t = singleton_factory_t < ze_rtas_builder_ext_object_t, ze_rtas_builder_ext_handle_t >; 68 | 69 | using ze_rtas_parallel_operation_ext_object_t = object_t < ze_rtas_parallel_operation_ext_handle_t >; 70 | using ze_rtas_parallel_operation_ext_factory_t = singleton_factory_t < ze_rtas_parallel_operation_ext_object_t, ze_rtas_parallel_operation_ext_handle_t >; 71 | 72 | using ze_rtas_builder_exp_object_t = object_t < ze_rtas_builder_exp_handle_t >; 73 | using ze_rtas_builder_exp_factory_t = singleton_factory_t < ze_rtas_builder_exp_object_t, ze_rtas_builder_exp_handle_t >; 74 | 75 | using ze_rtas_parallel_operation_exp_object_t = object_t < ze_rtas_parallel_operation_exp_handle_t >; 76 | using ze_rtas_parallel_operation_exp_factory_t = singleton_factory_t < ze_rtas_parallel_operation_exp_object_t, ze_rtas_parallel_operation_exp_handle_t >; 77 | 78 | } 79 | -------------------------------------------------------------------------------- /source/loader/ze_loader_api.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2020-2021 Intel Corporation 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * @file ze_loader_api.cpp 8 | * 9 | */ 10 | 11 | #include "ze_loader_internal.h" 12 | #include "loader/ze_loader.h" 13 | 14 | #define TRACING_COMP_NAME "loader" 15 | 16 | #if defined(__cplusplus) 17 | extern "C" { 18 | #endif 19 | 20 | /////////////////////////////////////////////////////////////////////////////// 21 | /// @brief Exported function for initializing loader 22 | /// 23 | /// @returns 24 | /// - ::ZE_RESULT_SUCCESS 25 | /// - ::ZE_RESULT_ERROR_UNINITIALIZED 26 | ZE_DLLEXPORT ze_result_t ZE_APICALL 27 | zeLoaderInit(); 28 | 29 | /////////////////////////////////////////////////////////////////////////////// 30 | /// @brief Exported function for verifying usable L0 Drivers for Loader to report 31 | /// 32 | /// @returns 33 | /// - ::ZE_RESULT_SUCCESS 34 | /// - ::ZE_RESULT_ERROR_UNINITIALIZED 35 | ZE_DLLEXPORT ze_result_t ZE_APICALL 36 | zelLoaderDriverCheck(ze_init_flags_t flags, ze_init_driver_type_desc_t* desc, ze_global_dditable_t *globalInitStored, zes_global_dditable_t *sysmanGlobalInitStored, bool *requireDdiReinit, bool sysmanOnly); 37 | 38 | 39 | /////////////////////////////////////////////////////////////////////////////// 40 | /// @brief Internal function for Setting the ddi table for the Tracing Layer. 41 | /// 42 | ZE_DLLEXPORT ze_result_t ZE_APICALL 43 | zelLoaderTracingLayerInit(std::atomic &zeDdiTable); 44 | 45 | 46 | /////////////////////////////////////////////////////////////////////////////// 47 | /// @brief Exported function for getting tracing lib handle 48 | /// 49 | /// @returns 50 | /// - ::handle to tracing library 51 | ZE_DLLEXPORT HMODULE ZE_APICALL 52 | zeLoaderGetTracingHandle(); 53 | 54 | /////////////////////////////////////////////////////////////////////////////// 55 | /// @brief Get pointer to Loader Context 56 | /// 57 | /// @returns 58 | /// - ::handle to tracing library 59 | ZE_DLLEXPORT loader::context_t *ZE_APICALL 60 | zelLoaderGetContext(); 61 | 62 | 63 | /////////////////////////////////////////////////////////////////////////////// 64 | /// @brief Exported function for getting version 65 | /// 66 | ZE_DLLEXPORT ze_result_t ZE_APICALL 67 | zelLoaderGetVersion(zel_component_version_t *version); 68 | 69 | 70 | /////////////////////////////////////////////////////////////////////////////// 71 | /// @brief Exported function for getting versions of all components 72 | /// 73 | ZE_DLLEXPORT ze_result_t ZE_APICALL 74 | zelLoaderGetVersionsInternal( 75 | size_t *num_elems, //Pointer to num versions to get. 76 | zel_component_version_t *versions); //Pointer to array of versions. If set to NULL, num_elems is returned 77 | 78 | 79 | ZE_DLLEXPORT ze_result_t ZE_APICALL 80 | zelLoaderTranslateHandleInternal( 81 | zel_handle_type_t handleType, //Handle type 82 | void *handleIn, //Input: handle to translate from loader handle to driver handle 83 | void **handleOut); //Output: Pointer to handleOut is set to driver handle if successful 84 | 85 | 86 | #if defined(__cplusplus) 87 | } 88 | #endif -------------------------------------------------------------------------------- /source/loader/ze_object.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019-2021 Intel Corporation 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * @file ze_object.h 8 | * 9 | */ 10 | #pragma once 11 | #include "ze_singleton.h" 12 | 13 | ////////////////////////////////////////////////////////////////////////// 14 | struct dditable_t 15 | { 16 | ze_dditable_t ze; 17 | zet_dditable_t zet; 18 | zes_dditable_t zes; 19 | }; 20 | 21 | ////////////////////////////////////////////////////////////////////////// 22 | template 23 | class object_t 24 | { 25 | public: 26 | using handle_t = _handle_t; 27 | 28 | handle_t handle; 29 | dditable_t* dditable; 30 | 31 | object_t() = delete; 32 | 33 | object_t( handle_t _handle, dditable_t* _dditable ) 34 | : handle( _handle ), dditable( _dditable ) 35 | { 36 | } 37 | 38 | ~object_t() = default; 39 | }; 40 | -------------------------------------------------------------------------------- /source/loader/zel_tracing_ldrddi.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Intel Corporation 3 | * 4 | * SPDX-License-Identifier: MIT 5 | * 6 | * @file zel_tracing_ldrddi.cpp 7 | * 8 | */ 9 | #include "ze_loader_internal.h" 10 | #include "layers/zel_tracing_ddi.h" 11 | 12 | namespace loader 13 | { 14 | 15 | #if defined(__cplusplus) 16 | extern "C" { 17 | #endif 18 | 19 | /////////////////////////////////////////////////////////////////////////////// 20 | /// @brief Exported function for filling application's Tracer table 21 | /// with current process' addresses 22 | /// 23 | /// @returns 24 | /// - ::ZE_RESULT_SUCCESS 25 | /// - ::ZE_RESULT_ERROR_UNINITIALIZED 26 | /// - ::ZE_RESULT_ERROR_INVALID_NULL_POINTER 27 | /// - ::ZE_RESULT_ERROR_UNSUPPORTED_VERSION 28 | ZE_DLLEXPORT ze_result_t ZE_APICALL 29 | zelGetTracerApiProcAddrTable( 30 | ze_api_version_t version, ///< [in] API version requested 31 | zel_tracer_dditable_t* pDdiTable ///< [in,out] pointer to table of DDI function pointers 32 | ) 33 | { 34 | if( loader::context->zeDrivers.size() < 1 ) 35 | return ZE_RESULT_ERROR_UNINITIALIZED; 36 | 37 | if( nullptr == pDdiTable ) 38 | return ZE_RESULT_ERROR_INVALID_NULL_POINTER; 39 | 40 | if( loader::context->version < version ) 41 | return ZE_RESULT_ERROR_UNSUPPORTED_VERSION; 42 | 43 | ze_result_t result = ZE_RESULT_SUCCESS; 44 | 45 | if(( nullptr != loader::context->tracingLayer )) 46 | { 47 | auto getTable = reinterpret_cast( 48 | GET_FUNCTION_PTR(loader::context->tracingLayer, "zelGetTracerApiProcAddrTable") ); 49 | if(!getTable) 50 | return ZE_RESULT_ERROR_UNINITIALIZED; 51 | result = getTable( version, pDdiTable ); 52 | } 53 | 54 | return result; 55 | } 56 | 57 | 58 | #if defined(__cplusplus) 59 | }; 60 | #endif 61 | } // namespace loader 62 | -------------------------------------------------------------------------------- /source/loader/zes_ldrddi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019-2024 Intel Corporation 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * @file zes_ldrddi.h 8 | * 9 | */ 10 | #pragma once 11 | 12 | namespace loader 13 | { 14 | /////////////////////////////////////////////////////////////////////////////// 15 | using zes_driver_object_t = object_t < zes_driver_handle_t >; 16 | using zes_driver_factory_t = singleton_factory_t < zes_driver_object_t, zes_driver_handle_t >; 17 | 18 | using zes_device_object_t = object_t < zes_device_handle_t >; 19 | using zes_device_factory_t = singleton_factory_t < zes_device_object_t, zes_device_handle_t >; 20 | 21 | using zes_sched_object_t = object_t < zes_sched_handle_t >; 22 | using zes_sched_factory_t = singleton_factory_t < zes_sched_object_t, zes_sched_handle_t >; 23 | 24 | using zes_perf_object_t = object_t < zes_perf_handle_t >; 25 | using zes_perf_factory_t = singleton_factory_t < zes_perf_object_t, zes_perf_handle_t >; 26 | 27 | using zes_pwr_object_t = object_t < zes_pwr_handle_t >; 28 | using zes_pwr_factory_t = singleton_factory_t < zes_pwr_object_t, zes_pwr_handle_t >; 29 | 30 | using zes_freq_object_t = object_t < zes_freq_handle_t >; 31 | using zes_freq_factory_t = singleton_factory_t < zes_freq_object_t, zes_freq_handle_t >; 32 | 33 | using zes_engine_object_t = object_t < zes_engine_handle_t >; 34 | using zes_engine_factory_t = singleton_factory_t < zes_engine_object_t, zes_engine_handle_t >; 35 | 36 | using zes_standby_object_t = object_t < zes_standby_handle_t >; 37 | using zes_standby_factory_t = singleton_factory_t < zes_standby_object_t, zes_standby_handle_t >; 38 | 39 | using zes_firmware_object_t = object_t < zes_firmware_handle_t >; 40 | using zes_firmware_factory_t = singleton_factory_t < zes_firmware_object_t, zes_firmware_handle_t >; 41 | 42 | using zes_mem_object_t = object_t < zes_mem_handle_t >; 43 | using zes_mem_factory_t = singleton_factory_t < zes_mem_object_t, zes_mem_handle_t >; 44 | 45 | using zes_fabric_port_object_t = object_t < zes_fabric_port_handle_t >; 46 | using zes_fabric_port_factory_t = singleton_factory_t < zes_fabric_port_object_t, zes_fabric_port_handle_t >; 47 | 48 | using zes_temp_object_t = object_t < zes_temp_handle_t >; 49 | using zes_temp_factory_t = singleton_factory_t < zes_temp_object_t, zes_temp_handle_t >; 50 | 51 | using zes_psu_object_t = object_t < zes_psu_handle_t >; 52 | using zes_psu_factory_t = singleton_factory_t < zes_psu_object_t, zes_psu_handle_t >; 53 | 54 | using zes_fan_object_t = object_t < zes_fan_handle_t >; 55 | using zes_fan_factory_t = singleton_factory_t < zes_fan_object_t, zes_fan_handle_t >; 56 | 57 | using zes_led_object_t = object_t < zes_led_handle_t >; 58 | using zes_led_factory_t = singleton_factory_t < zes_led_object_t, zes_led_handle_t >; 59 | 60 | using zes_ras_object_t = object_t < zes_ras_handle_t >; 61 | using zes_ras_factory_t = singleton_factory_t < zes_ras_object_t, zes_ras_handle_t >; 62 | 63 | using zes_diag_object_t = object_t < zes_diag_handle_t >; 64 | using zes_diag_factory_t = singleton_factory_t < zes_diag_object_t, zes_diag_handle_t >; 65 | 66 | using zes_overclock_object_t = object_t < zes_overclock_handle_t >; 67 | using zes_overclock_factory_t = singleton_factory_t < zes_overclock_object_t, zes_overclock_handle_t >; 68 | 69 | using zes_vf_object_t = object_t < zes_vf_handle_t >; 70 | using zes_vf_factory_t = singleton_factory_t < zes_vf_object_t, zes_vf_handle_t >; 71 | 72 | } 73 | -------------------------------------------------------------------------------- /source/loader/zet_ldrddi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2019-2024 Intel Corporation 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | * @file zet_ldrddi.h 8 | * 9 | */ 10 | #pragma once 11 | 12 | namespace loader 13 | { 14 | /////////////////////////////////////////////////////////////////////////////// 15 | using zet_driver_object_t = object_t < zet_driver_handle_t >; 16 | using zet_driver_factory_t = singleton_factory_t < zet_driver_object_t, zet_driver_handle_t >; 17 | 18 | using zet_device_object_t = object_t < zet_device_handle_t >; 19 | using zet_device_factory_t = singleton_factory_t < zet_device_object_t, zet_device_handle_t >; 20 | 21 | using zet_context_object_t = object_t < zet_context_handle_t >; 22 | using zet_context_factory_t = singleton_factory_t < zet_context_object_t, zet_context_handle_t >; 23 | 24 | using zet_command_list_object_t = object_t < zet_command_list_handle_t >; 25 | using zet_command_list_factory_t = singleton_factory_t < zet_command_list_object_t, zet_command_list_handle_t >; 26 | 27 | using zet_module_object_t = object_t < zet_module_handle_t >; 28 | using zet_module_factory_t = singleton_factory_t < zet_module_object_t, zet_module_handle_t >; 29 | 30 | using zet_kernel_object_t = object_t < zet_kernel_handle_t >; 31 | using zet_kernel_factory_t = singleton_factory_t < zet_kernel_object_t, zet_kernel_handle_t >; 32 | 33 | using zet_metric_group_object_t = object_t < zet_metric_group_handle_t >; 34 | using zet_metric_group_factory_t = singleton_factory_t < zet_metric_group_object_t, zet_metric_group_handle_t >; 35 | 36 | using zet_metric_object_t = object_t < zet_metric_handle_t >; 37 | using zet_metric_factory_t = singleton_factory_t < zet_metric_object_t, zet_metric_handle_t >; 38 | 39 | using zet_metric_streamer_object_t = object_t < zet_metric_streamer_handle_t >; 40 | using zet_metric_streamer_factory_t = singleton_factory_t < zet_metric_streamer_object_t, zet_metric_streamer_handle_t >; 41 | 42 | using zet_metric_query_pool_object_t = object_t < zet_metric_query_pool_handle_t >; 43 | using zet_metric_query_pool_factory_t = singleton_factory_t < zet_metric_query_pool_object_t, zet_metric_query_pool_handle_t >; 44 | 45 | using zet_metric_query_object_t = object_t < zet_metric_query_handle_t >; 46 | using zet_metric_query_factory_t = singleton_factory_t < zet_metric_query_object_t, zet_metric_query_handle_t >; 47 | 48 | using zet_tracer_exp_object_t = object_t < zet_tracer_exp_handle_t >; 49 | using zet_tracer_exp_factory_t = singleton_factory_t < zet_tracer_exp_object_t, zet_tracer_exp_handle_t >; 50 | 51 | using zet_debug_session_object_t = object_t < zet_debug_session_handle_t >; 52 | using zet_debug_session_factory_t = singleton_factory_t < zet_debug_session_object_t, zet_debug_session_handle_t >; 53 | 54 | using zet_metric_tracer_exp_object_t = object_t < zet_metric_tracer_exp_handle_t >; 55 | using zet_metric_tracer_exp_factory_t = singleton_factory_t < zet_metric_tracer_exp_object_t, zet_metric_tracer_exp_handle_t >; 56 | 57 | using zet_metric_decoder_exp_object_t = object_t < zet_metric_decoder_exp_handle_t >; 58 | using zet_metric_decoder_exp_factory_t = singleton_factory_t < zet_metric_decoder_exp_object_t, zet_metric_decoder_exp_handle_t >; 59 | 60 | using zet_metric_programmable_exp_object_t = object_t < zet_metric_programmable_exp_handle_t >; 61 | using zet_metric_programmable_exp_factory_t = singleton_factory_t < zet_metric_programmable_exp_object_t, zet_metric_programmable_exp_handle_t >; 62 | 63 | } 64 | -------------------------------------------------------------------------------- /source/utils/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2024 Intel Corporation 2 | # SPDX-License-Identifier: MIT 3 | 4 | set(logging_files logging.h logging.cpp) 5 | add_library(level_zero_utils STATIC ${logging_files}) 6 | 7 | if(SYSTEM_SPDLOG) 8 | target_link_libraries(level_zero_utils PUBLIC spdlog::spdlog) 9 | else() 10 | target_include_directories(level_zero_utils PUBLIC $) 11 | endif() 12 | 13 | target_include_directories(level_zero_utils PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) 14 | 15 | set_property(TARGET level_zero_utils PROPERTY POSITION_INDEPENDENT_CODE ON) 16 | -------------------------------------------------------------------------------- /source/utils/logging.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright (C) 2024 Intel Corporation 4 | * 5 | * SPDX-License-Identifier: MIT 6 | * 7 | */ 8 | 9 | #include "logging.h" 10 | namespace loader { 11 | 12 | std::string to_string(const ze_result_t result) { 13 | if (result == ZE_RESULT_SUCCESS) { 14 | return "ZE_RESULT_SUCCESS"; 15 | } else if (result == ZE_RESULT_NOT_READY) { 16 | return "ZE_RESULT_NOT_READY"; 17 | } else if (result == ZE_RESULT_ERROR_UNINITIALIZED) { 18 | return "ZE_RESULT_ERROR_UNINITIALIZED"; 19 | } else if (result == ZE_RESULT_ERROR_DEVICE_LOST) { 20 | return "ZE_RESULT_ERROR_DEVICE_LOST"; 21 | } else if (result == ZE_RESULT_ERROR_INVALID_ARGUMENT) { 22 | return "ZE_RESULT_ERROR_INVALID_ARGUMENT"; 23 | } else if (result == ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY) { 24 | return "ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY"; 25 | } else if (result == ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY) { 26 | return "ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY"; 27 | } else if (result == ZE_RESULT_ERROR_MODULE_BUILD_FAILURE) { 28 | return "ZE_RESULT_ERROR_MODULE_BUILD_FAILURE"; 29 | } else if (result == ZE_RESULT_ERROR_MODULE_LINK_FAILURE) { 30 | return "ZE_RESULT_ERROR_MODULE_LINK_FAILURE"; 31 | } else if (result == ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS) { 32 | return "ZE_RESULT_ERROR_INSUFFICIENT_PERMISSIONS"; 33 | } else if (result == ZE_RESULT_ERROR_NOT_AVAILABLE) { 34 | return "ZE_RESULT_ERROR_NOT_AVAILABLE"; 35 | } else if (result == ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE) { 36 | return "ZE_RESULT_ERROR_DEPENDENCY_UNAVAILABLE"; 37 | } else if (result == ZE_RESULT_WARNING_DROPPED_DATA) { 38 | return "ZE_RESULT_WARNING_DROPPED_DATA"; 39 | } else if (result == ZE_RESULT_ERROR_UNSUPPORTED_VERSION) { 40 | return "ZE_RESULT_ERROR_UNSUPPORTED_VERSION"; 41 | } else if (result == ZE_RESULT_ERROR_UNSUPPORTED_FEATURE) { 42 | return "ZE_RESULT_ERROR_UNSUPPORTED_FEATURE"; 43 | } else if (result == ZE_RESULT_ERROR_INVALID_NULL_HANDLE) { 44 | return "ZE_RESULT_ERROR_INVALID_NULL_HANDLE"; 45 | } else if (result == ZE_RESULT_ERROR_HANDLE_OBJECT_IN_USE) { 46 | return "ZE_RESULT_ERROR_HANDLE_OBJECT_IN_USE"; 47 | } else if (result == ZE_RESULT_ERROR_INVALID_NULL_POINTER) { 48 | return "ZE_RESULT_ERROR_INVALID_NULL_POINTER"; 49 | } else if (result == ZE_RESULT_ERROR_INVALID_SIZE) { 50 | return "ZE_RESULT_ERROR_INVALID_SIZE"; 51 | } else if (result == ZE_RESULT_ERROR_UNSUPPORTED_SIZE) { 52 | return "ZE_RESULT_ERROR_UNSUPPORTED_SIZE"; 53 | } else if (result == ZE_RESULT_ERROR_UNSUPPORTED_ALIGNMENT) { 54 | return "ZE_RESULT_ERROR_UNSUPPORTED_ALIGNMENT"; 55 | } else if (result == ZE_RESULT_ERROR_INVALID_SYNCHRONIZATION_OBJECT) { 56 | return "ZE_RESULT_ERROR_INVALID_SYNCHRONIZATION_OBJECT"; 57 | } else if (result == ZE_RESULT_ERROR_INVALID_ENUMERATION) { 58 | return "ZE_RESULT_ERROR_INVALID_ENUMERATION"; 59 | } else if (result == ZE_RESULT_ERROR_UNSUPPORTED_ENUMERATION) { 60 | return "ZE_RESULT_ERROR_UNSUPPORTED_ENUMERATION"; 61 | } else if (result == ZE_RESULT_ERROR_UNSUPPORTED_IMAGE_FORMAT) { 62 | return "ZE_RESULT_ERROR_UNSUPPORTED_IMAGE_FORMAT"; 63 | } else if (result == ZE_RESULT_ERROR_INVALID_NATIVE_BINARY) { 64 | return "ZE_RESULT_ERROR_INVALID_NATIVE_BINARY"; 65 | } else if (result == ZE_RESULT_ERROR_INVALID_GLOBAL_NAME) { 66 | return "ZE_RESULT_ERROR_INVALID_GLOBAL_NAME"; 67 | } else if (result == ZE_RESULT_ERROR_INVALID_KERNEL_NAME) { 68 | return "ZE_RESULT_ERROR_INVALID_KERNEL_NAME"; 69 | } else if (result == ZE_RESULT_ERROR_INVALID_FUNCTION_NAME) { 70 | return "ZE_RESULT_ERROR_INVALID_FUNCTION_NAME"; 71 | } else if (result == ZE_RESULT_ERROR_INVALID_GROUP_SIZE_DIMENSION) { 72 | return "ZE_RESULT_ERROR_INVALID_GROUP_SIZE_DIMENSION"; 73 | } else if (result == ZE_RESULT_ERROR_INVALID_GLOBAL_WIDTH_DIMENSION) { 74 | return "ZE_RESULT_ERROR_INVALID_GLOBAL_WIDTH_DIMENSION"; 75 | } else if (result == ZE_RESULT_ERROR_INVALID_KERNEL_ARGUMENT_INDEX) { 76 | return "ZE_RESULT_ERROR_INVALID_KERNEL_ARGUMENT_INDEX"; 77 | } else if (result == ZE_RESULT_ERROR_INVALID_KERNEL_ARGUMENT_SIZE) { 78 | return "ZE_RESULT_ERROR_INVALID_KERNEL_ARGUMENT_SIZE"; 79 | } else if (result == ZE_RESULT_ERROR_INVALID_KERNEL_ATTRIBUTE_VALUE) { 80 | return "ZE_RESULT_ERROR_INVALID_KERNEL_ATTRIBUTE_VALUE"; 81 | } else if (result == ZE_RESULT_ERROR_INVALID_MODULE_UNLINKED) { 82 | return "ZE_RESULT_ERROR_INVALID_MODULE_UNLINKED"; 83 | } else if (result == ZE_RESULT_ERROR_INVALID_COMMAND_LIST_TYPE) { 84 | return "ZE_RESULT_ERROR_INVALID_COMMAND_LIST_TYPE"; 85 | } else if (result == ZE_RESULT_ERROR_OVERLAPPING_REGIONS) { 86 | return "ZE_RESULT_ERROR_OVERLAPPING_REGIONS"; 87 | } else if (result == ZE_RESULT_ERROR_UNKNOWN) { 88 | return "ZE_RESULT_ERROR_UNKNOWN"; 89 | } else { 90 | return std::to_string(static_cast(result)); 91 | } 92 | } 93 | } // namespace loader -------------------------------------------------------------------------------- /third_party/spdlog_headers/.version: -------------------------------------------------------------------------------- 1 | 1.13.0 2 | -------------------------------------------------------------------------------- /third_party/spdlog_headers/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Gabi Melman. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | 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 THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | -- NOTE: Third party dependency used by this software -- 24 | This software depends on the fmt lib (MIT License), 25 | and users must comply to its license: https://raw.githubusercontent.com/fmtlib/fmt/master/LICENSE 26 | 27 | -------------------------------------------------------------------------------- /third_party/spdlog_headers/README.md: -------------------------------------------------------------------------------- 1 | # Source locations of interface headers 2 | 3 | https://github.com/gabime/spdlog/tree/a3a0c9d66386962fcaf0178fcae03ac77c1e0257/include/spdlog 4 | -------------------------------------------------------------------------------- /third_party/spdlog_headers/spdlog/common-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #ifndef SPDLOG_HEADER_ONLY 7 | #include 8 | #endif 9 | 10 | #include 11 | #include 12 | 13 | namespace spdlog { 14 | namespace level { 15 | 16 | #if __cplusplus >= 201703L 17 | constexpr 18 | #endif 19 | static string_view_t level_string_views[] SPDLOG_LEVEL_NAMES; 20 | 21 | static const char *short_level_names[] SPDLOG_SHORT_LEVEL_NAMES; 22 | 23 | SPDLOG_INLINE const string_view_t &to_string_view(spdlog::level::level_enum l) SPDLOG_NOEXCEPT { 24 | return level_string_views[l]; 25 | } 26 | 27 | SPDLOG_INLINE const char *to_short_c_str(spdlog::level::level_enum l) SPDLOG_NOEXCEPT { 28 | return short_level_names[l]; 29 | } 30 | 31 | SPDLOG_INLINE spdlog::level::level_enum from_str(const std::string &name) SPDLOG_NOEXCEPT { 32 | auto it = std::find(std::begin(level_string_views), std::end(level_string_views), name); 33 | if (it != std::end(level_string_views)) 34 | return static_cast(std::distance(std::begin(level_string_views), it)); 35 | 36 | // check also for "warn" and "err" before giving up.. 37 | if (name == "warn") { 38 | return level::warn; 39 | } 40 | if (name == "err") { 41 | return level::err; 42 | } 43 | return level::off; 44 | } 45 | } // namespace level 46 | 47 | SPDLOG_INLINE spdlog_ex::spdlog_ex(std::string msg) 48 | : msg_(std::move(msg)) {} 49 | 50 | SPDLOG_INLINE spdlog_ex::spdlog_ex(const std::string &msg, int last_errno) { 51 | #ifdef SPDLOG_USE_STD_FORMAT 52 | msg_ = std::system_error(std::error_code(last_errno, std::generic_category()), msg).what(); 53 | #else 54 | memory_buf_t outbuf; 55 | fmt::format_system_error(outbuf, last_errno, msg.c_str()); 56 | msg_ = fmt::to_string(outbuf); 57 | #endif 58 | } 59 | 60 | SPDLOG_INLINE const char *spdlog_ex::what() const SPDLOG_NOEXCEPT { return msg_.c_str(); } 61 | 62 | SPDLOG_INLINE void throw_spdlog_ex(const std::string &msg, int last_errno) { 63 | SPDLOG_THROW(spdlog_ex(msg, last_errno)); 64 | } 65 | 66 | SPDLOG_INLINE void throw_spdlog_ex(std::string msg) { SPDLOG_THROW(spdlog_ex(std::move(msg))); } 67 | 68 | } // namespace spdlog 69 | -------------------------------------------------------------------------------- /third_party/spdlog_headers/spdlog/details/backtracer-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #ifndef SPDLOG_HEADER_ONLY 7 | #include 8 | #endif 9 | namespace spdlog { 10 | namespace details { 11 | SPDLOG_INLINE backtracer::backtracer(const backtracer &other) { 12 | std::lock_guard lock(other.mutex_); 13 | enabled_ = other.enabled(); 14 | messages_ = other.messages_; 15 | } 16 | 17 | SPDLOG_INLINE backtracer::backtracer(backtracer &&other) SPDLOG_NOEXCEPT { 18 | std::lock_guard lock(other.mutex_); 19 | enabled_ = other.enabled(); 20 | messages_ = std::move(other.messages_); 21 | } 22 | 23 | SPDLOG_INLINE backtracer &backtracer::operator=(backtracer other) { 24 | std::lock_guard lock(mutex_); 25 | enabled_ = other.enabled(); 26 | messages_ = std::move(other.messages_); 27 | return *this; 28 | } 29 | 30 | SPDLOG_INLINE void backtracer::enable(size_t size) { 31 | std::lock_guard lock{mutex_}; 32 | enabled_.store(true, std::memory_order_relaxed); 33 | messages_ = circular_q{size}; 34 | } 35 | 36 | SPDLOG_INLINE void backtracer::disable() { 37 | std::lock_guard lock{mutex_}; 38 | enabled_.store(false, std::memory_order_relaxed); 39 | } 40 | 41 | SPDLOG_INLINE bool backtracer::enabled() const { return enabled_.load(std::memory_order_relaxed); } 42 | 43 | SPDLOG_INLINE void backtracer::push_back(const log_msg &msg) { 44 | std::lock_guard lock{mutex_}; 45 | messages_.push_back(log_msg_buffer{msg}); 46 | } 47 | 48 | SPDLOG_INLINE bool backtracer::empty() const { 49 | std::lock_guard lock{mutex_}; 50 | return messages_.empty(); 51 | } 52 | 53 | // pop all items in the q and apply the given fun on each of them. 54 | SPDLOG_INLINE void backtracer::foreach_pop(std::function fun) { 55 | std::lock_guard lock{mutex_}; 56 | while (!messages_.empty()) { 57 | auto &front_msg = messages_.front(); 58 | fun(front_msg); 59 | messages_.pop_front(); 60 | } 61 | } 62 | } // namespace details 63 | } // namespace spdlog 64 | -------------------------------------------------------------------------------- /third_party/spdlog_headers/spdlog/details/backtracer.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | // Store log messages in circular buffer. 14 | // Useful for storing debug data in case of error/warning happens. 15 | 16 | namespace spdlog { 17 | namespace details { 18 | class SPDLOG_API backtracer { 19 | mutable std::mutex mutex_; 20 | std::atomic enabled_{false}; 21 | circular_q messages_; 22 | 23 | public: 24 | backtracer() = default; 25 | backtracer(const backtracer &other); 26 | 27 | backtracer(backtracer &&other) SPDLOG_NOEXCEPT; 28 | backtracer &operator=(backtracer other); 29 | 30 | void enable(size_t size); 31 | void disable(); 32 | bool enabled() const; 33 | void push_back(const log_msg &msg); 34 | bool empty() const; 35 | 36 | // pop all items in the q and apply the given fun on each of them. 37 | void foreach_pop(std::function fun); 38 | }; 39 | 40 | } // namespace details 41 | } // namespace spdlog 42 | 43 | #ifdef SPDLOG_HEADER_ONLY 44 | #include "backtracer-inl.h" 45 | #endif 46 | -------------------------------------------------------------------------------- /third_party/spdlog_headers/spdlog/details/circular_q.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | // circular q view of std::vector. 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | #include "spdlog/common.h" 11 | 12 | namespace spdlog { 13 | namespace details { 14 | template 15 | class circular_q { 16 | size_t max_items_ = 0; 17 | typename std::vector::size_type head_ = 0; 18 | typename std::vector::size_type tail_ = 0; 19 | size_t overrun_counter_ = 0; 20 | std::vector v_; 21 | 22 | public: 23 | using value_type = T; 24 | 25 | // empty ctor - create a disabled queue with no elements allocated at all 26 | circular_q() = default; 27 | 28 | explicit circular_q(size_t max_items) 29 | : max_items_(max_items + 1) // one item is reserved as marker for full q 30 | , 31 | v_(max_items_) {} 32 | 33 | circular_q(const circular_q &) = default; 34 | circular_q &operator=(const circular_q &) = default; 35 | 36 | // move cannot be default, 37 | // since we need to reset head_, tail_, etc to zero in the moved object 38 | circular_q(circular_q &&other) SPDLOG_NOEXCEPT { copy_moveable(std::move(other)); } 39 | 40 | circular_q &operator=(circular_q &&other) SPDLOG_NOEXCEPT { 41 | copy_moveable(std::move(other)); 42 | return *this; 43 | } 44 | 45 | // push back, overrun (oldest) item if no room left 46 | void push_back(T &&item) { 47 | if (max_items_ > 0) { 48 | v_[tail_] = std::move(item); 49 | tail_ = (tail_ + 1) % max_items_; 50 | 51 | if (tail_ == head_) // overrun last item if full 52 | { 53 | head_ = (head_ + 1) % max_items_; 54 | ++overrun_counter_; 55 | } 56 | } 57 | } 58 | 59 | // Return reference to the front item. 60 | // If there are no elements in the container, the behavior is undefined. 61 | const T &front() const { return v_[head_]; } 62 | 63 | T &front() { return v_[head_]; } 64 | 65 | // Return number of elements actually stored 66 | size_t size() const { 67 | if (tail_ >= head_) { 68 | return tail_ - head_; 69 | } else { 70 | return max_items_ - (head_ - tail_); 71 | } 72 | } 73 | 74 | // Return const reference to item by index. 75 | // If index is out of range 0…size()-1, the behavior is undefined. 76 | const T &at(size_t i) const { 77 | assert(i < size()); 78 | return v_[(head_ + i) % max_items_]; 79 | } 80 | 81 | // Pop item from front. 82 | // If there are no elements in the container, the behavior is undefined. 83 | void pop_front() { head_ = (head_ + 1) % max_items_; } 84 | 85 | bool empty() const { return tail_ == head_; } 86 | 87 | bool full() const { 88 | // head is ahead of the tail by 1 89 | if (max_items_ > 0) { 90 | return ((tail_ + 1) % max_items_) == head_; 91 | } 92 | return false; 93 | } 94 | 95 | size_t overrun_counter() const { return overrun_counter_; } 96 | 97 | void reset_overrun_counter() { overrun_counter_ = 0; } 98 | 99 | private: 100 | // copy from other&& and reset it to disabled state 101 | void copy_moveable(circular_q &&other) SPDLOG_NOEXCEPT { 102 | max_items_ = other.max_items_; 103 | head_ = other.head_; 104 | tail_ = other.tail_; 105 | overrun_counter_ = other.overrun_counter_; 106 | v_ = std::move(other.v_); 107 | 108 | // put &&other in disabled, but valid state 109 | other.max_items_ = 0; 110 | other.head_ = other.tail_ = 0; 111 | other.overrun_counter_ = 0; 112 | } 113 | }; 114 | } // namespace details 115 | } // namespace spdlog 116 | -------------------------------------------------------------------------------- /third_party/spdlog_headers/spdlog/details/console_globals.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | namespace spdlog { 10 | namespace details { 11 | 12 | struct console_mutex { 13 | using mutex_t = std::mutex; 14 | static mutex_t &mutex() { 15 | static mutex_t s_mutex; 16 | return s_mutex; 17 | } 18 | }; 19 | 20 | struct console_nullmutex { 21 | using mutex_t = null_mutex; 22 | static mutex_t &mutex() { 23 | static mutex_t s_mutex; 24 | return s_mutex; 25 | } 26 | }; 27 | } // namespace details 28 | } // namespace spdlog 29 | -------------------------------------------------------------------------------- /third_party/spdlog_headers/spdlog/details/file_helper.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | namespace spdlog { 10 | namespace details { 11 | 12 | // Helper class for file sinks. 13 | // When failing to open a file, retry several times(5) with a delay interval(10 ms). 14 | // Throw spdlog_ex exception on errors. 15 | 16 | class SPDLOG_API file_helper { 17 | public: 18 | file_helper() = default; 19 | explicit file_helper(const file_event_handlers &event_handlers); 20 | 21 | file_helper(const file_helper &) = delete; 22 | file_helper &operator=(const file_helper &) = delete; 23 | ~file_helper(); 24 | 25 | void open(const filename_t &fname, bool truncate = false); 26 | void reopen(bool truncate); 27 | void flush(); 28 | void sync(); 29 | void close(); 30 | void write(const memory_buf_t &buf); 31 | size_t size() const; 32 | const filename_t &filename() const; 33 | 34 | // 35 | // return file path and its extension: 36 | // 37 | // "mylog.txt" => ("mylog", ".txt") 38 | // "mylog" => ("mylog", "") 39 | // "mylog." => ("mylog.", "") 40 | // "/dir1/dir2/mylog.txt" => ("/dir1/dir2/mylog", ".txt") 41 | // 42 | // the starting dot in filenames is ignored (hidden files): 43 | // 44 | // ".mylog" => (".mylog". "") 45 | // "my_folder/.mylog" => ("my_folder/.mylog", "") 46 | // "my_folder/.mylog.txt" => ("my_folder/.mylog", ".txt") 47 | static std::tuple split_by_extension(const filename_t &fname); 48 | 49 | private: 50 | const int open_tries_ = 5; 51 | const unsigned int open_interval_ = 10; 52 | std::FILE *fd_{nullptr}; 53 | filename_t filename_; 54 | file_event_handlers event_handlers_; 55 | }; 56 | } // namespace details 57 | } // namespace spdlog 58 | 59 | #ifdef SPDLOG_HEADER_ONLY 60 | #include "file_helper-inl.h" 61 | #endif 62 | -------------------------------------------------------------------------------- /third_party/spdlog_headers/spdlog/details/fmt_helper.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | #pragma once 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #ifdef SPDLOG_USE_STD_FORMAT 12 | #include 13 | #include 14 | #endif 15 | 16 | // Some fmt helpers to efficiently format and pad ints and strings 17 | namespace spdlog { 18 | namespace details { 19 | namespace fmt_helper { 20 | 21 | inline void append_string_view(spdlog::string_view_t view, memory_buf_t &dest) { 22 | auto *buf_ptr = view.data(); 23 | dest.append(buf_ptr, buf_ptr + view.size()); 24 | } 25 | 26 | #ifdef SPDLOG_USE_STD_FORMAT 27 | template 28 | inline void append_int(T n, memory_buf_t &dest) { 29 | // Buffer should be large enough to hold all digits (digits10 + 1) and a sign 30 | SPDLOG_CONSTEXPR const auto BUF_SIZE = std::numeric_limits::digits10 + 2; 31 | char buf[BUF_SIZE]; 32 | 33 | auto [ptr, ec] = std::to_chars(buf, buf + BUF_SIZE, n, 10); 34 | if (ec == std::errc()) { 35 | dest.append(buf, ptr); 36 | } else { 37 | throw_spdlog_ex("Failed to format int", static_cast(ec)); 38 | } 39 | } 40 | #else 41 | template 42 | inline void append_int(T n, memory_buf_t &dest) { 43 | fmt::format_int i(n); 44 | dest.append(i.data(), i.data() + i.size()); 45 | } 46 | #endif 47 | 48 | template 49 | SPDLOG_CONSTEXPR_FUNC unsigned int count_digits_fallback(T n) { 50 | // taken from fmt: https://github.com/fmtlib/fmt/blob/8.0.1/include/fmt/format.h#L899-L912 51 | unsigned int count = 1; 52 | for (;;) { 53 | // Integer division is slow so do it for a group of four digits instead 54 | // of for every digit. The idea comes from the talk by Alexandrescu 55 | // "Three Optimization Tips for C++". See speed-test for a comparison. 56 | if (n < 10) return count; 57 | if (n < 100) return count + 1; 58 | if (n < 1000) return count + 2; 59 | if (n < 10000) return count + 3; 60 | n /= 10000u; 61 | count += 4; 62 | } 63 | } 64 | 65 | template 66 | inline unsigned int count_digits(T n) { 67 | using count_type = 68 | typename std::conditional<(sizeof(T) > sizeof(uint32_t)), uint64_t, uint32_t>::type; 69 | #ifdef SPDLOG_USE_STD_FORMAT 70 | return count_digits_fallback(static_cast(n)); 71 | #else 72 | return static_cast(fmt:: 73 | // fmt 7.0.0 renamed the internal namespace to detail. 74 | // See: https://github.com/fmtlib/fmt/issues/1538 75 | #if FMT_VERSION < 70000 76 | internal 77 | #else 78 | detail 79 | #endif 80 | ::count_digits(static_cast(n))); 81 | #endif 82 | } 83 | 84 | inline void pad2(int n, memory_buf_t &dest) { 85 | if (n >= 0 && n < 100) // 0-99 86 | { 87 | dest.push_back(static_cast('0' + n / 10)); 88 | dest.push_back(static_cast('0' + n % 10)); 89 | } else // unlikely, but just in case, let fmt deal with it 90 | { 91 | fmt_lib::format_to(std::back_inserter(dest), SPDLOG_FMT_STRING("{:02}"), n); 92 | } 93 | } 94 | 95 | template 96 | inline void pad_uint(T n, unsigned int width, memory_buf_t &dest) { 97 | static_assert(std::is_unsigned::value, "pad_uint must get unsigned T"); 98 | for (auto digits = count_digits(n); digits < width; digits++) { 99 | dest.push_back('0'); 100 | } 101 | append_int(n, dest); 102 | } 103 | 104 | template 105 | inline void pad3(T n, memory_buf_t &dest) { 106 | static_assert(std::is_unsigned::value, "pad3 must get unsigned T"); 107 | if (n < 1000) { 108 | dest.push_back(static_cast(n / 100 + '0')); 109 | n = n % 100; 110 | dest.push_back(static_cast((n / 10) + '0')); 111 | dest.push_back(static_cast((n % 10) + '0')); 112 | } else { 113 | append_int(n, dest); 114 | } 115 | } 116 | 117 | template 118 | inline void pad6(T n, memory_buf_t &dest) { 119 | pad_uint(n, 6, dest); 120 | } 121 | 122 | template 123 | inline void pad9(T n, memory_buf_t &dest) { 124 | pad_uint(n, 9, dest); 125 | } 126 | 127 | // return fraction of a second of the given time_point. 128 | // e.g. 129 | // fraction(tp) -> will return the millis part of the second 130 | template 131 | inline ToDuration time_fraction(log_clock::time_point tp) { 132 | using std::chrono::duration_cast; 133 | using std::chrono::seconds; 134 | auto duration = tp.time_since_epoch(); 135 | auto secs = duration_cast(duration); 136 | return duration_cast(duration) - duration_cast(secs); 137 | } 138 | 139 | } // namespace fmt_helper 140 | } // namespace details 141 | } // namespace spdlog 142 | -------------------------------------------------------------------------------- /third_party/spdlog_headers/spdlog/details/log_msg-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #ifndef SPDLOG_HEADER_ONLY 7 | #include 8 | #endif 9 | 10 | #include 11 | 12 | namespace spdlog { 13 | namespace details { 14 | 15 | SPDLOG_INLINE log_msg::log_msg(spdlog::log_clock::time_point log_time, 16 | spdlog::source_loc loc, 17 | string_view_t a_logger_name, 18 | spdlog::level::level_enum lvl, 19 | spdlog::string_view_t msg) 20 | : logger_name(a_logger_name), 21 | level(lvl), 22 | time(log_time) 23 | #ifndef SPDLOG_NO_THREAD_ID 24 | , 25 | thread_id(os::thread_id()) 26 | #endif 27 | , 28 | source(loc), 29 | payload(msg) { 30 | } 31 | 32 | SPDLOG_INLINE log_msg::log_msg(spdlog::source_loc loc, 33 | string_view_t a_logger_name, 34 | spdlog::level::level_enum lvl, 35 | spdlog::string_view_t msg) 36 | : log_msg(os::now(), loc, a_logger_name, lvl, msg) {} 37 | 38 | SPDLOG_INLINE log_msg::log_msg(string_view_t a_logger_name, 39 | spdlog::level::level_enum lvl, 40 | spdlog::string_view_t msg) 41 | : log_msg(os::now(), source_loc{}, a_logger_name, lvl, msg) {} 42 | 43 | } // namespace details 44 | } // namespace spdlog 45 | -------------------------------------------------------------------------------- /third_party/spdlog_headers/spdlog/details/log_msg.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | namespace spdlog { 10 | namespace details { 11 | struct SPDLOG_API log_msg { 12 | log_msg() = default; 13 | log_msg(log_clock::time_point log_time, 14 | source_loc loc, 15 | string_view_t logger_name, 16 | level::level_enum lvl, 17 | string_view_t msg); 18 | log_msg(source_loc loc, string_view_t logger_name, level::level_enum lvl, string_view_t msg); 19 | log_msg(string_view_t logger_name, level::level_enum lvl, string_view_t msg); 20 | log_msg(const log_msg &other) = default; 21 | log_msg &operator=(const log_msg &other) = default; 22 | 23 | string_view_t logger_name; 24 | level::level_enum level{level::off}; 25 | log_clock::time_point time; 26 | size_t thread_id{0}; 27 | 28 | // wrapping the formatted text with color (updated by pattern_formatter). 29 | mutable size_t color_range_start{0}; 30 | mutable size_t color_range_end{0}; 31 | 32 | source_loc source; 33 | string_view_t payload; 34 | }; 35 | } // namespace details 36 | } // namespace spdlog 37 | 38 | #ifdef SPDLOG_HEADER_ONLY 39 | #include "log_msg-inl.h" 40 | #endif 41 | -------------------------------------------------------------------------------- /third_party/spdlog_headers/spdlog/details/log_msg_buffer-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #ifndef SPDLOG_HEADER_ONLY 7 | #include 8 | #endif 9 | 10 | namespace spdlog { 11 | namespace details { 12 | 13 | SPDLOG_INLINE log_msg_buffer::log_msg_buffer(const log_msg &orig_msg) 14 | : log_msg{orig_msg} { 15 | buffer.append(logger_name.begin(), logger_name.end()); 16 | buffer.append(payload.begin(), payload.end()); 17 | update_string_views(); 18 | } 19 | 20 | SPDLOG_INLINE log_msg_buffer::log_msg_buffer(const log_msg_buffer &other) 21 | : log_msg{other} { 22 | buffer.append(logger_name.begin(), logger_name.end()); 23 | buffer.append(payload.begin(), payload.end()); 24 | update_string_views(); 25 | } 26 | 27 | SPDLOG_INLINE log_msg_buffer::log_msg_buffer(log_msg_buffer &&other) SPDLOG_NOEXCEPT 28 | : log_msg{other}, 29 | buffer{std::move(other.buffer)} { 30 | update_string_views(); 31 | } 32 | 33 | SPDLOG_INLINE log_msg_buffer &log_msg_buffer::operator=(const log_msg_buffer &other) { 34 | log_msg::operator=(other); 35 | buffer.clear(); 36 | buffer.append(other.buffer.data(), other.buffer.data() + other.buffer.size()); 37 | update_string_views(); 38 | return *this; 39 | } 40 | 41 | SPDLOG_INLINE log_msg_buffer &log_msg_buffer::operator=(log_msg_buffer &&other) SPDLOG_NOEXCEPT { 42 | log_msg::operator=(other); 43 | buffer = std::move(other.buffer); 44 | update_string_views(); 45 | return *this; 46 | } 47 | 48 | SPDLOG_INLINE void log_msg_buffer::update_string_views() { 49 | logger_name = string_view_t{buffer.data(), logger_name.size()}; 50 | payload = string_view_t{buffer.data() + logger_name.size(), payload.size()}; 51 | } 52 | 53 | } // namespace details 54 | } // namespace spdlog 55 | -------------------------------------------------------------------------------- /third_party/spdlog_headers/spdlog/details/log_msg_buffer.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | namespace spdlog { 9 | namespace details { 10 | 11 | // Extend log_msg with internal buffer to store its payload. 12 | // This is needed since log_msg holds string_views that points to stack data. 13 | 14 | class SPDLOG_API log_msg_buffer : public log_msg { 15 | memory_buf_t buffer; 16 | void update_string_views(); 17 | 18 | public: 19 | log_msg_buffer() = default; 20 | explicit log_msg_buffer(const log_msg &orig_msg); 21 | log_msg_buffer(const log_msg_buffer &other); 22 | log_msg_buffer(log_msg_buffer &&other) SPDLOG_NOEXCEPT; 23 | log_msg_buffer &operator=(const log_msg_buffer &other); 24 | log_msg_buffer &operator=(log_msg_buffer &&other) SPDLOG_NOEXCEPT; 25 | }; 26 | 27 | } // namespace details 28 | } // namespace spdlog 29 | 30 | #ifdef SPDLOG_HEADER_ONLY 31 | #include "log_msg_buffer-inl.h" 32 | #endif 33 | -------------------------------------------------------------------------------- /third_party/spdlog_headers/spdlog/details/null_mutex.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | // null, no cost dummy "mutex" and dummy "atomic" int 9 | 10 | namespace spdlog { 11 | namespace details { 12 | struct null_mutex { 13 | void lock() const {} 14 | void unlock() const {} 15 | }; 16 | 17 | struct null_atomic_int { 18 | int value; 19 | null_atomic_int() = default; 20 | 21 | explicit null_atomic_int(int new_value) 22 | : value(new_value) {} 23 | 24 | int load(std::memory_order = std::memory_order_relaxed) const { return value; } 25 | 26 | void store(int new_value, std::memory_order = std::memory_order_relaxed) { value = new_value; } 27 | 28 | int exchange(int new_value, std::memory_order = std::memory_order_relaxed) { 29 | std::swap(new_value, value); 30 | return new_value; // return value before the call 31 | } 32 | }; 33 | 34 | } // namespace details 35 | } // namespace spdlog 36 | -------------------------------------------------------------------------------- /third_party/spdlog_headers/spdlog/details/os.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include // std::time_t 7 | #include 8 | 9 | namespace spdlog { 10 | namespace details { 11 | namespace os { 12 | 13 | SPDLOG_API spdlog::log_clock::time_point now() SPDLOG_NOEXCEPT; 14 | 15 | SPDLOG_API std::tm localtime(const std::time_t &time_tt) SPDLOG_NOEXCEPT; 16 | 17 | SPDLOG_API std::tm localtime() SPDLOG_NOEXCEPT; 18 | 19 | SPDLOG_API std::tm gmtime(const std::time_t &time_tt) SPDLOG_NOEXCEPT; 20 | 21 | SPDLOG_API std::tm gmtime() SPDLOG_NOEXCEPT; 22 | 23 | // eol definition 24 | #if !defined(SPDLOG_EOL) 25 | #ifdef _WIN32 26 | #define SPDLOG_EOL "\r\n" 27 | #else 28 | #define SPDLOG_EOL "\n" 29 | #endif 30 | #endif 31 | 32 | SPDLOG_CONSTEXPR static const char *default_eol = SPDLOG_EOL; 33 | 34 | // folder separator 35 | #if !defined(SPDLOG_FOLDER_SEPS) 36 | #ifdef _WIN32 37 | #define SPDLOG_FOLDER_SEPS "\\/" 38 | #else 39 | #define SPDLOG_FOLDER_SEPS "/" 40 | #endif 41 | #endif 42 | 43 | SPDLOG_CONSTEXPR static const char folder_seps[] = SPDLOG_FOLDER_SEPS; 44 | SPDLOG_CONSTEXPR static const filename_t::value_type folder_seps_filename[] = 45 | SPDLOG_FILENAME_T(SPDLOG_FOLDER_SEPS); 46 | 47 | // fopen_s on non windows for writing 48 | SPDLOG_API bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode); 49 | 50 | // Remove filename. return 0 on success 51 | SPDLOG_API int remove(const filename_t &filename) SPDLOG_NOEXCEPT; 52 | 53 | // Remove file if exists. return 0 on success 54 | // Note: Non atomic (might return failure to delete if concurrently deleted by other process/thread) 55 | SPDLOG_API int remove_if_exists(const filename_t &filename) SPDLOG_NOEXCEPT; 56 | 57 | SPDLOG_API int rename(const filename_t &filename1, const filename_t &filename2) SPDLOG_NOEXCEPT; 58 | 59 | // Return if file exists. 60 | SPDLOG_API bool path_exists(const filename_t &filename) SPDLOG_NOEXCEPT; 61 | 62 | // Return file size according to open FILE* object 63 | SPDLOG_API size_t filesize(FILE *f); 64 | 65 | // Return utc offset in minutes or throw spdlog_ex on failure 66 | SPDLOG_API int utc_minutes_offset(const std::tm &tm = details::os::localtime()); 67 | 68 | // Return current thread id as size_t 69 | // It exists because the std::this_thread::get_id() is much slower(especially 70 | // under VS 2013) 71 | SPDLOG_API size_t _thread_id() SPDLOG_NOEXCEPT; 72 | 73 | // Return current thread id as size_t (from thread local storage) 74 | SPDLOG_API size_t thread_id() SPDLOG_NOEXCEPT; 75 | 76 | // This is avoid msvc issue in sleep_for that happens if the clock changes. 77 | // See https://github.com/gabime/spdlog/issues/609 78 | SPDLOG_API void sleep_for_millis(unsigned int milliseconds) SPDLOG_NOEXCEPT; 79 | 80 | SPDLOG_API std::string filename_to_str(const filename_t &filename); 81 | 82 | SPDLOG_API int pid() SPDLOG_NOEXCEPT; 83 | 84 | // Determine if the terminal supports colors 85 | // Source: https://github.com/agauniyal/rang/ 86 | SPDLOG_API bool is_color_terminal() SPDLOG_NOEXCEPT; 87 | 88 | // Determine if the terminal attached 89 | // Source: https://github.com/agauniyal/rang/ 90 | SPDLOG_API bool in_terminal(FILE *file) SPDLOG_NOEXCEPT; 91 | 92 | #if (defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)) && defined(_WIN32) 93 | SPDLOG_API void wstr_to_utf8buf(wstring_view_t wstr, memory_buf_t &target); 94 | 95 | SPDLOG_API void utf8_to_wstrbuf(string_view_t str, wmemory_buf_t &target); 96 | #endif 97 | 98 | // Return directory name from given path or empty string 99 | // "abc/file" => "abc" 100 | // "abc/" => "abc" 101 | // "abc" => "" 102 | // "abc///" => "abc//" 103 | SPDLOG_API filename_t dir_name(const filename_t &path); 104 | 105 | // Create a dir from the given path. 106 | // Return true if succeeded or if this dir already exists. 107 | SPDLOG_API bool create_dir(const filename_t &path); 108 | 109 | // non thread safe, cross platform getenv/getenv_s 110 | // return empty string if field not found 111 | SPDLOG_API std::string getenv(const char *field); 112 | 113 | // Do fsync by FILE objectpointer. 114 | // Return true on success. 115 | SPDLOG_API bool fsync(FILE *fp); 116 | 117 | } // namespace os 118 | } // namespace details 119 | } // namespace spdlog 120 | 121 | #ifdef SPDLOG_HEADER_ONLY 122 | #include "os-inl.h" 123 | #endif 124 | -------------------------------------------------------------------------------- /third_party/spdlog_headers/spdlog/details/periodic_worker-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #ifndef SPDLOG_HEADER_ONLY 7 | #include 8 | #endif 9 | 10 | namespace spdlog { 11 | namespace details { 12 | 13 | // stop the worker thread and join it 14 | SPDLOG_INLINE periodic_worker::~periodic_worker() { 15 | if (worker_thread_.joinable()) { 16 | { 17 | std::lock_guard lock(mutex_); 18 | active_ = false; 19 | } 20 | cv_.notify_one(); 21 | worker_thread_.join(); 22 | } 23 | } 24 | 25 | } // namespace details 26 | } // namespace spdlog 27 | -------------------------------------------------------------------------------- /third_party/spdlog_headers/spdlog/details/periodic_worker.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | // periodic worker thread - periodically executes the given callback function. 7 | // 8 | // RAII over the owned thread: 9 | // creates the thread on construction. 10 | // stops and joins the thread on destruction (if the thread is executing a callback, wait for it 11 | // to finish first). 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | namespace spdlog { 19 | namespace details { 20 | 21 | class SPDLOG_API periodic_worker { 22 | public: 23 | template 24 | periodic_worker(const std::function &callback_fun, 25 | std::chrono::duration interval) { 26 | active_ = (interval > std::chrono::duration::zero()); 27 | if (!active_) { 28 | return; 29 | } 30 | 31 | worker_thread_ = std::thread([this, callback_fun, interval]() { 32 | for (;;) { 33 | std::unique_lock lock(this->mutex_); 34 | if (this->cv_.wait_for(lock, interval, [this] { return !this->active_; })) { 35 | return; // active_ == false, so exit this thread 36 | } 37 | callback_fun(); 38 | } 39 | }); 40 | } 41 | std::thread &get_thread() { return worker_thread_; } 42 | periodic_worker(const periodic_worker &) = delete; 43 | periodic_worker &operator=(const periodic_worker &) = delete; 44 | // stop the worker thread and join it 45 | ~periodic_worker(); 46 | 47 | private: 48 | bool active_; 49 | std::thread worker_thread_; 50 | std::mutex mutex_; 51 | std::condition_variable cv_; 52 | }; 53 | } // namespace details 54 | } // namespace spdlog 55 | 56 | #ifdef SPDLOG_HEADER_ONLY 57 | #include "periodic_worker-inl.h" 58 | #endif 59 | -------------------------------------------------------------------------------- /third_party/spdlog_headers/spdlog/details/registry.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | // Loggers registry of unique name->logger pointer 7 | // An attempt to create a logger with an already existing name will result with spdlog_ex exception. 8 | // If user requests a non existing logger, nullptr will be returned 9 | // This class is thread safe 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | namespace spdlog { 22 | class logger; 23 | 24 | namespace details { 25 | class thread_pool; 26 | 27 | class SPDLOG_API registry { 28 | public: 29 | using log_levels = std::unordered_map; 30 | registry(const registry &) = delete; 31 | registry &operator=(const registry &) = delete; 32 | 33 | void register_logger(std::shared_ptr new_logger); 34 | void initialize_logger(std::shared_ptr new_logger); 35 | std::shared_ptr get(const std::string &logger_name); 36 | std::shared_ptr default_logger(); 37 | 38 | // Return raw ptr to the default logger. 39 | // To be used directly by the spdlog default api (e.g. spdlog::info) 40 | // This make the default API faster, but cannot be used concurrently with set_default_logger(). 41 | // e.g do not call set_default_logger() from one thread while calling spdlog::info() from 42 | // another. 43 | logger *get_default_raw(); 44 | 45 | // set default logger and add it to the registry if not registered already. 46 | // default logger is stored in default_logger_ (for faster retrieval) and in the loggers_ map. 47 | // Note: Make sure to unregister it when no longer needed or before calling again with a new 48 | // logger. 49 | void set_default_logger(std::shared_ptr new_default_logger); 50 | 51 | void set_tp(std::shared_ptr tp); 52 | 53 | std::shared_ptr get_tp(); 54 | 55 | // Set global formatter. Each sink in each logger will get a clone of this object 56 | void set_formatter(std::unique_ptr formatter); 57 | 58 | void enable_backtrace(size_t n_messages); 59 | 60 | void disable_backtrace(); 61 | 62 | void set_level(level::level_enum log_level); 63 | 64 | void flush_on(level::level_enum log_level); 65 | 66 | template 67 | void flush_every(std::chrono::duration interval) { 68 | std::lock_guard lock(flusher_mutex_); 69 | auto clbk = [this]() { this->flush_all(); }; 70 | periodic_flusher_ = details::make_unique(clbk, interval); 71 | } 72 | 73 | std::unique_ptr &get_flusher() { 74 | std::lock_guard lock(flusher_mutex_); 75 | return periodic_flusher_; 76 | } 77 | 78 | void set_error_handler(err_handler handler); 79 | 80 | void apply_all(const std::function)> &fun); 81 | 82 | void flush_all(); 83 | 84 | void drop(const std::string &logger_name); 85 | 86 | void drop_all(); 87 | 88 | // clean all resources and threads started by the registry 89 | void shutdown(); 90 | 91 | std::recursive_mutex &tp_mutex(); 92 | 93 | void set_automatic_registration(bool automatic_registration); 94 | 95 | // set levels for all existing/future loggers. global_level can be null if should not set. 96 | void set_levels(log_levels levels, level::level_enum *global_level); 97 | 98 | static registry &instance(); 99 | 100 | void apply_logger_env_levels(std::shared_ptr new_logger); 101 | 102 | private: 103 | registry(); 104 | ~registry(); 105 | 106 | void throw_if_exists_(const std::string &logger_name); 107 | void register_logger_(std::shared_ptr new_logger); 108 | bool set_level_from_cfg_(logger *logger); 109 | std::mutex logger_map_mutex_, flusher_mutex_; 110 | std::recursive_mutex tp_mutex_; 111 | std::unordered_map> loggers_; 112 | log_levels log_levels_; 113 | std::unique_ptr formatter_; 114 | spdlog::level::level_enum global_log_level_ = level::info; 115 | level::level_enum flush_level_ = level::off; 116 | err_handler err_handler_; 117 | std::shared_ptr tp_; 118 | std::unique_ptr periodic_flusher_; 119 | std::shared_ptr default_logger_; 120 | bool automatic_registration_ = true; 121 | size_t backtrace_n_messages_ = 0; 122 | }; 123 | 124 | } // namespace details 125 | } // namespace spdlog 126 | 127 | #ifdef SPDLOG_HEADER_ONLY 128 | #include "registry-inl.h" 129 | #endif 130 | -------------------------------------------------------------------------------- /third_party/spdlog_headers/spdlog/details/synchronous_factory.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include "registry.h" 7 | 8 | namespace spdlog { 9 | 10 | // Default logger factory- creates synchronous loggers 11 | class logger; 12 | 13 | struct synchronous_factory { 14 | template 15 | static std::shared_ptr create(std::string logger_name, SinkArgs &&...args) { 16 | auto sink = std::make_shared(std::forward(args)...); 17 | auto new_logger = std::make_shared(std::move(logger_name), std::move(sink)); 18 | details::registry::instance().initialize_logger(new_logger); 19 | return new_logger; 20 | } 21 | }; 22 | } // namespace spdlog 23 | -------------------------------------------------------------------------------- /third_party/spdlog_headers/spdlog/details/windows_include.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef NOMINMAX 4 | #define NOMINMAX // prevent windows redefining min/max 5 | #endif 6 | 7 | #ifndef WIN32_LEAN_AND_MEAN 8 | #define WIN32_LEAN_AND_MEAN 9 | #endif 10 | 11 | #include 12 | -------------------------------------------------------------------------------- /third_party/spdlog_headers/spdlog/fmt/fmt.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright(c) 2016-2018 Gabi Melman. 3 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 4 | // 5 | 6 | #pragma once 7 | 8 | // 9 | // Include a bundled header-only copy of fmtlib or an external one. 10 | // By default spdlog include its own copy. 11 | // 12 | #include 13 | 14 | #if defined(SPDLOG_USE_STD_FORMAT) // SPDLOG_USE_STD_FORMAT is defined - use std::format 15 | #include 16 | #elif !defined(SPDLOG_FMT_EXTERNAL) 17 | #if !defined(SPDLOG_COMPILED_LIB) && !defined(FMT_HEADER_ONLY) 18 | #define FMT_HEADER_ONLY 19 | #endif 20 | #ifndef FMT_USE_WINDOWS_H 21 | #define FMT_USE_WINDOWS_H 0 22 | #endif 23 | 24 | #include 25 | #include 26 | 27 | #else // SPDLOG_FMT_EXTERNAL is defined - use external fmtlib 28 | #include 29 | #include 30 | #endif 31 | -------------------------------------------------------------------------------- /third_party/spdlog_headers/spdlog/formatter.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | namespace spdlog { 10 | 11 | class formatter { 12 | public: 13 | virtual ~formatter() = default; 14 | virtual void format(const details::log_msg &msg, memory_buf_t &dest) = 0; 15 | virtual std::unique_ptr clone() const = 0; 16 | }; 17 | } // namespace spdlog 18 | -------------------------------------------------------------------------------- /third_party/spdlog_headers/spdlog/mdc.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | // MDC is a simple map of key->string values stored in thread local storage whose content will be printed by the loggers. 12 | // Note: Not supported in async mode (thread local storage - so the async thread pool have different copy). 13 | // 14 | // Usage example: 15 | // spdlog::mdc::put("mdc_key_1", "mdc_value_1"); 16 | // spdlog::info("Hello, {}", "World!"); // => [2024-04-26 02:08:05.040] [info] [mdc_key_1:mdc_value_1] Hello, World! 17 | 18 | namespace spdlog { 19 | class SPDLOG_API mdc { 20 | public: 21 | using mdc_map_t = std::map; 22 | 23 | static void put(const std::string &key, const std::string &value) { 24 | get_context()[key] = value; 25 | } 26 | 27 | static std::string get(const std::string &key) { 28 | auto &context = get_context(); 29 | auto it = context.find(key); 30 | if (it != context.end()) { 31 | return it->second; 32 | } 33 | return ""; 34 | } 35 | 36 | static void remove(const std::string &key) { get_context().erase(key); } 37 | 38 | static void clear() { get_context().clear(); } 39 | 40 | static mdc_map_t &get_context() { 41 | static thread_local mdc_map_t context; 42 | return context; 43 | } 44 | }; 45 | 46 | } // namespace spdlog 47 | -------------------------------------------------------------------------------- /third_party/spdlog_headers/spdlog/pattern_formatter.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | namespace spdlog { 20 | namespace details { 21 | 22 | // padding information. 23 | struct padding_info { 24 | enum class pad_side { left, right, center }; 25 | 26 | padding_info() = default; 27 | padding_info(size_t width, padding_info::pad_side side, bool truncate) 28 | : width_(width), 29 | side_(side), 30 | truncate_(truncate), 31 | enabled_(true) {} 32 | 33 | bool enabled() const { return enabled_; } 34 | size_t width_ = 0; 35 | pad_side side_ = pad_side::left; 36 | bool truncate_ = false; 37 | bool enabled_ = false; 38 | }; 39 | 40 | class SPDLOG_API flag_formatter { 41 | public: 42 | explicit flag_formatter(padding_info padinfo) 43 | : padinfo_(padinfo) {} 44 | flag_formatter() = default; 45 | virtual ~flag_formatter() = default; 46 | virtual void format(const details::log_msg &msg, 47 | const std::tm &tm_time, 48 | memory_buf_t &dest) = 0; 49 | 50 | protected: 51 | padding_info padinfo_; 52 | }; 53 | 54 | } // namespace details 55 | 56 | class SPDLOG_API custom_flag_formatter : public details::flag_formatter { 57 | public: 58 | virtual std::unique_ptr clone() const = 0; 59 | 60 | void set_padding_info(const details::padding_info &padding) { 61 | flag_formatter::padinfo_ = padding; 62 | } 63 | }; 64 | 65 | class SPDLOG_API pattern_formatter final : public formatter { 66 | public: 67 | using custom_flags = std::unordered_map>; 68 | 69 | explicit pattern_formatter(std::string pattern, 70 | pattern_time_type time_type = pattern_time_type::local, 71 | std::string eol = spdlog::details::os::default_eol, 72 | custom_flags custom_user_flags = custom_flags()); 73 | 74 | // use default pattern is not given 75 | explicit pattern_formatter(pattern_time_type time_type = pattern_time_type::local, 76 | std::string eol = spdlog::details::os::default_eol); 77 | 78 | pattern_formatter(const pattern_formatter &other) = delete; 79 | pattern_formatter &operator=(const pattern_formatter &other) = delete; 80 | 81 | std::unique_ptr clone() const override; 82 | void format(const details::log_msg &msg, memory_buf_t &dest) override; 83 | 84 | template 85 | pattern_formatter &add_flag(char flag, Args &&...args) { 86 | custom_handlers_[flag] = details::make_unique(std::forward(args)...); 87 | return *this; 88 | } 89 | void set_pattern(std::string pattern); 90 | void need_localtime(bool need = true); 91 | 92 | private: 93 | std::string pattern_; 94 | std::string eol_; 95 | pattern_time_type pattern_time_type_; 96 | bool need_localtime_; 97 | std::tm cached_tm_; 98 | std::chrono::seconds last_log_secs_; 99 | std::vector> formatters_; 100 | custom_flags custom_handlers_; 101 | 102 | std::tm get_time_(const details::log_msg &msg); 103 | template 104 | void handle_flag_(char flag, details::padding_info padding); 105 | 106 | // Extract given pad spec (e.g. %8X) 107 | // Advance the given it pass the end of the padding spec found (if any) 108 | // Return padding. 109 | static details::padding_info handle_padspec_(std::string::const_iterator &it, 110 | std::string::const_iterator end); 111 | 112 | void compile_pattern_(const std::string &pattern); 113 | }; 114 | } // namespace spdlog 115 | 116 | #ifdef SPDLOG_HEADER_ONLY 117 | #include "pattern_formatter-inl.h" 118 | #endif 119 | -------------------------------------------------------------------------------- /third_party/spdlog_headers/spdlog/sinks/ansicolor_sink.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | namespace spdlog { 15 | namespace sinks { 16 | 17 | /** 18 | * This sink prefixes the output with an ANSI escape sequence color code 19 | * depending on the severity 20 | * of the message. 21 | * If no color terminal detected, omit the escape codes. 22 | */ 23 | 24 | template 25 | class ansicolor_sink : public sink { 26 | public: 27 | using mutex_t = typename ConsoleMutex::mutex_t; 28 | ansicolor_sink(FILE *target_file, color_mode mode); 29 | ~ansicolor_sink() override = default; 30 | 31 | ansicolor_sink(const ansicolor_sink &other) = delete; 32 | ansicolor_sink(ansicolor_sink &&other) = delete; 33 | 34 | ansicolor_sink &operator=(const ansicolor_sink &other) = delete; 35 | ansicolor_sink &operator=(ansicolor_sink &&other) = delete; 36 | 37 | void set_color(level::level_enum color_level, string_view_t color); 38 | void set_color_mode(color_mode mode); 39 | bool should_color(); 40 | 41 | void log(const details::log_msg &msg) override; 42 | void flush() override; 43 | void set_pattern(const std::string &pattern) final override; 44 | void set_formatter(std::unique_ptr sink_formatter) override; 45 | 46 | // Formatting codes 47 | const string_view_t reset = "\033[m"; 48 | const string_view_t bold = "\033[1m"; 49 | const string_view_t dark = "\033[2m"; 50 | const string_view_t underline = "\033[4m"; 51 | const string_view_t blink = "\033[5m"; 52 | const string_view_t reverse = "\033[7m"; 53 | const string_view_t concealed = "\033[8m"; 54 | const string_view_t clear_line = "\033[K"; 55 | 56 | // Foreground colors 57 | const string_view_t black = "\033[30m"; 58 | const string_view_t red = "\033[31m"; 59 | const string_view_t green = "\033[32m"; 60 | const string_view_t yellow = "\033[33m"; 61 | const string_view_t blue = "\033[34m"; 62 | const string_view_t magenta = "\033[35m"; 63 | const string_view_t cyan = "\033[36m"; 64 | const string_view_t white = "\033[37m"; 65 | 66 | /// Background colors 67 | const string_view_t on_black = "\033[40m"; 68 | const string_view_t on_red = "\033[41m"; 69 | const string_view_t on_green = "\033[42m"; 70 | const string_view_t on_yellow = "\033[43m"; 71 | const string_view_t on_blue = "\033[44m"; 72 | const string_view_t on_magenta = "\033[45m"; 73 | const string_view_t on_cyan = "\033[46m"; 74 | const string_view_t on_white = "\033[47m"; 75 | 76 | /// Bold colors 77 | const string_view_t yellow_bold = "\033[33m\033[1m"; 78 | const string_view_t red_bold = "\033[31m\033[1m"; 79 | const string_view_t bold_on_red = "\033[1m\033[41m"; 80 | 81 | private: 82 | FILE *target_file_; 83 | mutex_t &mutex_; 84 | bool should_do_colors_; 85 | std::unique_ptr formatter_; 86 | std::array colors_; 87 | void print_ccode_(const string_view_t &color_code); 88 | void print_range_(const memory_buf_t &formatted, size_t start, size_t end); 89 | static std::string to_string_(const string_view_t &sv); 90 | }; 91 | 92 | template 93 | class ansicolor_stdout_sink : public ansicolor_sink { 94 | public: 95 | explicit ansicolor_stdout_sink(color_mode mode = color_mode::automatic); 96 | }; 97 | 98 | template 99 | class ansicolor_stderr_sink : public ansicolor_sink { 100 | public: 101 | explicit ansicolor_stderr_sink(color_mode mode = color_mode::automatic); 102 | }; 103 | 104 | using ansicolor_stdout_sink_mt = ansicolor_stdout_sink; 105 | using ansicolor_stdout_sink_st = ansicolor_stdout_sink; 106 | 107 | using ansicolor_stderr_sink_mt = ansicolor_stderr_sink; 108 | using ansicolor_stderr_sink_st = ansicolor_stderr_sink; 109 | 110 | } // namespace sinks 111 | } // namespace spdlog 112 | 113 | #ifdef SPDLOG_HEADER_ONLY 114 | #include "ansicolor_sink-inl.h" 115 | #endif 116 | -------------------------------------------------------------------------------- /third_party/spdlog_headers/spdlog/sinks/base_sink-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #ifndef SPDLOG_HEADER_ONLY 7 | #include 8 | #endif 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | template 17 | SPDLOG_INLINE spdlog::sinks::base_sink::base_sink() 18 | : formatter_{details::make_unique()} {} 19 | 20 | template 21 | SPDLOG_INLINE spdlog::sinks::base_sink::base_sink( 22 | std::unique_ptr formatter) 23 | : formatter_{std::move(formatter)} {} 24 | 25 | template 26 | void SPDLOG_INLINE spdlog::sinks::base_sink::log(const details::log_msg &msg) { 27 | std::lock_guard lock(mutex_); 28 | sink_it_(msg); 29 | } 30 | 31 | template 32 | void SPDLOG_INLINE spdlog::sinks::base_sink::flush() { 33 | std::lock_guard lock(mutex_); 34 | flush_(); 35 | } 36 | 37 | template 38 | void SPDLOG_INLINE spdlog::sinks::base_sink::set_pattern(const std::string &pattern) { 39 | std::lock_guard lock(mutex_); 40 | set_pattern_(pattern); 41 | } 42 | 43 | template 44 | void SPDLOG_INLINE 45 | spdlog::sinks::base_sink::set_formatter(std::unique_ptr sink_formatter) { 46 | std::lock_guard lock(mutex_); 47 | set_formatter_(std::move(sink_formatter)); 48 | } 49 | 50 | template 51 | void SPDLOG_INLINE spdlog::sinks::base_sink::set_pattern_(const std::string &pattern) { 52 | set_formatter_(details::make_unique(pattern)); 53 | } 54 | 55 | template 56 | void SPDLOG_INLINE 57 | spdlog::sinks::base_sink::set_formatter_(std::unique_ptr sink_formatter) { 58 | formatter_ = std::move(sink_formatter); 59 | } 60 | -------------------------------------------------------------------------------- /third_party/spdlog_headers/spdlog/sinks/base_sink.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | // 6 | // base sink templated over a mutex (either dummy or real) 7 | // concrete implementation should override the sink_it_() and flush_() methods. 8 | // locking is taken care of in this class - no locking needed by the 9 | // implementers.. 10 | // 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace spdlog { 17 | namespace sinks { 18 | template 19 | class SPDLOG_API base_sink : public sink { 20 | public: 21 | base_sink(); 22 | explicit base_sink(std::unique_ptr formatter); 23 | ~base_sink() override = default; 24 | 25 | base_sink(const base_sink &) = delete; 26 | base_sink(base_sink &&) = delete; 27 | 28 | base_sink &operator=(const base_sink &) = delete; 29 | base_sink &operator=(base_sink &&) = delete; 30 | 31 | void log(const details::log_msg &msg) final override; 32 | void flush() final override; 33 | void set_pattern(const std::string &pattern) final override; 34 | void set_formatter(std::unique_ptr sink_formatter) final override; 35 | 36 | protected: 37 | // sink formatter 38 | std::unique_ptr formatter_; 39 | Mutex mutex_; 40 | 41 | virtual void sink_it_(const details::log_msg &msg) = 0; 42 | virtual void flush_() = 0; 43 | virtual void set_pattern_(const std::string &pattern); 44 | virtual void set_formatter_(std::unique_ptr sink_formatter); 45 | }; 46 | } // namespace sinks 47 | } // namespace spdlog 48 | 49 | #ifdef SPDLOG_HEADER_ONLY 50 | #include "base_sink-inl.h" 51 | #endif 52 | -------------------------------------------------------------------------------- /third_party/spdlog_headers/spdlog/sinks/basic_file_sink-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #ifndef SPDLOG_HEADER_ONLY 7 | #include 8 | #endif 9 | 10 | #include 11 | #include 12 | 13 | namespace spdlog { 14 | namespace sinks { 15 | 16 | template 17 | SPDLOG_INLINE basic_file_sink::basic_file_sink(const filename_t &filename, 18 | bool truncate, 19 | const file_event_handlers &event_handlers) 20 | : file_helper_{event_handlers} { 21 | file_helper_.open(filename, truncate); 22 | } 23 | 24 | template 25 | SPDLOG_INLINE const filename_t &basic_file_sink::filename() const { 26 | return file_helper_.filename(); 27 | } 28 | 29 | template 30 | SPDLOG_INLINE void basic_file_sink::sink_it_(const details::log_msg &msg) { 31 | memory_buf_t formatted; 32 | base_sink::formatter_->format(msg, formatted); 33 | file_helper_.write(formatted); 34 | } 35 | 36 | template 37 | SPDLOG_INLINE void basic_file_sink::flush_() { 38 | file_helper_.flush(); 39 | } 40 | 41 | } // namespace sinks 42 | } // namespace spdlog 43 | -------------------------------------------------------------------------------- /third_party/spdlog_headers/spdlog/sinks/basic_file_sink.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | namespace spdlog { 15 | namespace sinks { 16 | /* 17 | * Trivial file sink with single file as target 18 | */ 19 | template 20 | class basic_file_sink final : public base_sink { 21 | public: 22 | explicit basic_file_sink(const filename_t &filename, 23 | bool truncate = false, 24 | const file_event_handlers &event_handlers = {}); 25 | const filename_t &filename() const; 26 | 27 | protected: 28 | void sink_it_(const details::log_msg &msg) override; 29 | void flush_() override; 30 | 31 | private: 32 | details::file_helper file_helper_; 33 | }; 34 | 35 | using basic_file_sink_mt = basic_file_sink; 36 | using basic_file_sink_st = basic_file_sink; 37 | 38 | } // namespace sinks 39 | 40 | // 41 | // factory functions 42 | // 43 | template 44 | inline std::shared_ptr basic_logger_mt(const std::string &logger_name, 45 | const filename_t &filename, 46 | bool truncate = false, 47 | const file_event_handlers &event_handlers = {}) { 48 | return Factory::template create(logger_name, filename, truncate, 49 | event_handlers); 50 | } 51 | 52 | template 53 | inline std::shared_ptr basic_logger_st(const std::string &logger_name, 54 | const filename_t &filename, 55 | bool truncate = false, 56 | const file_event_handlers &event_handlers = {}) { 57 | return Factory::template create(logger_name, filename, truncate, 58 | event_handlers); 59 | } 60 | 61 | } // namespace spdlog 62 | 63 | #ifdef SPDLOG_HEADER_ONLY 64 | #include "basic_file_sink-inl.h" 65 | #endif 66 | -------------------------------------------------------------------------------- /third_party/spdlog_headers/spdlog/sinks/sink-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #ifndef SPDLOG_HEADER_ONLY 7 | #include 8 | #endif 9 | 10 | #include 11 | 12 | SPDLOG_INLINE bool spdlog::sinks::sink::should_log(spdlog::level::level_enum msg_level) const { 13 | return msg_level >= level_.load(std::memory_order_relaxed); 14 | } 15 | 16 | SPDLOG_INLINE void spdlog::sinks::sink::set_level(level::level_enum log_level) { 17 | level_.store(log_level, std::memory_order_relaxed); 18 | } 19 | 20 | SPDLOG_INLINE spdlog::level::level_enum spdlog::sinks::sink::level() const { 21 | return static_cast(level_.load(std::memory_order_relaxed)); 22 | } 23 | -------------------------------------------------------------------------------- /third_party/spdlog_headers/spdlog/sinks/sink.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | namespace spdlog { 10 | 11 | namespace sinks { 12 | class SPDLOG_API sink { 13 | public: 14 | virtual ~sink() = default; 15 | virtual void log(const details::log_msg &msg) = 0; 16 | virtual void flush() = 0; 17 | virtual void set_pattern(const std::string &pattern) = 0; 18 | virtual void set_formatter(std::unique_ptr sink_formatter) = 0; 19 | 20 | void set_level(level::level_enum log_level); 21 | level::level_enum level() const; 22 | bool should_log(level::level_enum msg_level) const; 23 | 24 | protected: 25 | // sink log level - default is all 26 | level_t level_{level::trace}; 27 | }; 28 | 29 | } // namespace sinks 30 | } // namespace spdlog 31 | 32 | #ifdef SPDLOG_HEADER_ONLY 33 | #include "sink-inl.h" 34 | #endif 35 | -------------------------------------------------------------------------------- /third_party/spdlog_headers/spdlog/sinks/wincolor_sink.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | namespace spdlog { 18 | namespace sinks { 19 | /* 20 | * Windows color console sink. Uses WriteConsoleA to write to the console with 21 | * colors 22 | */ 23 | template 24 | class wincolor_sink : public sink { 25 | public: 26 | wincolor_sink(void *out_handle, color_mode mode); 27 | ~wincolor_sink() override; 28 | 29 | wincolor_sink(const wincolor_sink &other) = delete; 30 | wincolor_sink &operator=(const wincolor_sink &other) = delete; 31 | 32 | // change the color for the given level 33 | void set_color(level::level_enum level, std::uint16_t color); 34 | void log(const details::log_msg &msg) final override; 35 | void flush() final override; 36 | void set_pattern(const std::string &pattern) override final; 37 | void set_formatter(std::unique_ptr sink_formatter) override final; 38 | void set_color_mode(color_mode mode); 39 | 40 | protected: 41 | using mutex_t = typename ConsoleMutex::mutex_t; 42 | void *out_handle_; 43 | mutex_t &mutex_; 44 | bool should_do_colors_; 45 | std::unique_ptr formatter_; 46 | std::array colors_; 47 | 48 | // set foreground color and return the orig console attributes (for resetting later) 49 | std::uint16_t set_foreground_color_(std::uint16_t attribs); 50 | 51 | // print a range of formatted message to console 52 | void print_range_(const memory_buf_t &formatted, size_t start, size_t end); 53 | 54 | // in case we are redirected to file (not in console mode) 55 | void write_to_file_(const memory_buf_t &formatted); 56 | 57 | void set_color_mode_impl(color_mode mode); 58 | }; 59 | 60 | template 61 | class wincolor_stdout_sink : public wincolor_sink { 62 | public: 63 | explicit wincolor_stdout_sink(color_mode mode = color_mode::automatic); 64 | }; 65 | 66 | template 67 | class wincolor_stderr_sink : public wincolor_sink { 68 | public: 69 | explicit wincolor_stderr_sink(color_mode mode = color_mode::automatic); 70 | }; 71 | 72 | using wincolor_stdout_sink_mt = wincolor_stdout_sink; 73 | using wincolor_stdout_sink_st = wincolor_stdout_sink; 74 | 75 | using wincolor_stderr_sink_mt = wincolor_stderr_sink; 76 | using wincolor_stderr_sink_st = wincolor_stderr_sink; 77 | } // namespace sinks 78 | } // namespace spdlog 79 | 80 | #ifdef SPDLOG_HEADER_ONLY 81 | #include "wincolor_sink-inl.h" 82 | #endif 83 | -------------------------------------------------------------------------------- /third_party/spdlog_headers/spdlog/spdlog-inl.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #ifndef SPDLOG_HEADER_ONLY 7 | #include 8 | #endif 9 | 10 | #include 11 | #include 12 | 13 | namespace spdlog { 14 | 15 | SPDLOG_INLINE void initialize_logger(std::shared_ptr logger) { 16 | details::registry::instance().initialize_logger(std::move(logger)); 17 | } 18 | 19 | SPDLOG_INLINE std::shared_ptr get(const std::string &name) { 20 | return details::registry::instance().get(name); 21 | } 22 | 23 | SPDLOG_INLINE void set_formatter(std::unique_ptr formatter) { 24 | details::registry::instance().set_formatter(std::move(formatter)); 25 | } 26 | 27 | SPDLOG_INLINE void set_pattern(std::string pattern, pattern_time_type time_type) { 28 | set_formatter( 29 | std::unique_ptr(new pattern_formatter(std::move(pattern), time_type))); 30 | } 31 | 32 | SPDLOG_INLINE void enable_backtrace(size_t n_messages) { 33 | details::registry::instance().enable_backtrace(n_messages); 34 | } 35 | 36 | SPDLOG_INLINE void disable_backtrace() { details::registry::instance().disable_backtrace(); } 37 | 38 | SPDLOG_INLINE void dump_backtrace() { default_logger_raw()->dump_backtrace(); } 39 | 40 | SPDLOG_INLINE level::level_enum get_level() { return default_logger_raw()->level(); } 41 | 42 | SPDLOG_INLINE bool should_log(level::level_enum log_level) { 43 | return default_logger_raw()->should_log(log_level); 44 | } 45 | 46 | SPDLOG_INLINE void set_level(level::level_enum log_level) { 47 | details::registry::instance().set_level(log_level); 48 | } 49 | 50 | SPDLOG_INLINE void flush_on(level::level_enum log_level) { 51 | details::registry::instance().flush_on(log_level); 52 | } 53 | 54 | SPDLOG_INLINE void set_error_handler(void (*handler)(const std::string &msg)) { 55 | details::registry::instance().set_error_handler(handler); 56 | } 57 | 58 | SPDLOG_INLINE void register_logger(std::shared_ptr logger) { 59 | details::registry::instance().register_logger(std::move(logger)); 60 | } 61 | 62 | SPDLOG_INLINE void apply_all(const std::function)> &fun) { 63 | details::registry::instance().apply_all(fun); 64 | } 65 | 66 | SPDLOG_INLINE void drop(const std::string &name) { details::registry::instance().drop(name); } 67 | 68 | SPDLOG_INLINE void drop_all() { details::registry::instance().drop_all(); } 69 | 70 | SPDLOG_INLINE void shutdown() { details::registry::instance().shutdown(); } 71 | 72 | SPDLOG_INLINE void set_automatic_registration(bool automatic_registration) { 73 | details::registry::instance().set_automatic_registration(automatic_registration); 74 | } 75 | 76 | SPDLOG_INLINE std::shared_ptr default_logger() { 77 | return details::registry::instance().default_logger(); 78 | } 79 | 80 | SPDLOG_INLINE spdlog::logger *default_logger_raw() { 81 | return details::registry::instance().get_default_raw(); 82 | } 83 | 84 | SPDLOG_INLINE void set_default_logger(std::shared_ptr default_logger) { 85 | details::registry::instance().set_default_logger(std::move(default_logger)); 86 | } 87 | 88 | SPDLOG_INLINE void apply_logger_env_levels(std::shared_ptr logger) { 89 | details::registry::instance().apply_logger_env_levels(std::move(logger)); 90 | } 91 | 92 | } // namespace spdlog 93 | -------------------------------------------------------------------------------- /third_party/spdlog_headers/spdlog/version.h: -------------------------------------------------------------------------------- 1 | // Copyright(c) 2015-present, Gabi Melman & spdlog contributors. 2 | // Distributed under the MIT License (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #define SPDLOG_VER_MAJOR 1 7 | #define SPDLOG_VER_MINOR 14 8 | #define SPDLOG_VER_PATCH 1 9 | 10 | #define SPDLOG_TO_VERSION(major, minor, patch) (major * 10000 + minor * 100 + patch) 11 | #define SPDLOG_VERSION SPDLOG_TO_VERSION(SPDLOG_VER_MAJOR, SPDLOG_VER_MINOR, SPDLOG_VER_PATCH) 12 | -------------------------------------------------------------------------------- /third_party/xla/README.md: -------------------------------------------------------------------------------- 1 | # Source location 2 | 3 | https://github.com/openxla/xla/tree/18d21413942e140f923da9eefe7a5b7c7206157f/xla/service/graphcycles 4 | 5 | # Note 6 | 7 | Some modifications were made to the files, including the complete removal of the external `abseil` library, which was replaced with equivalent `std::` containers. Additionally, certain C++17 features were substituted with equivalent code to ensure compatibility with C++14. 8 | -------------------------------------------------------------------------------- /third_party/xla/ordered_set.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The OpenXLA Authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | // Copyright (C) 2024 Intel Corporation 18 | 19 | ==============================================================================*/ 20 | 21 | #ifndef XLA_SERVICE_GRAPHCYCLES_ORDERED_SET_H_ 22 | #define XLA_SERVICE_GRAPHCYCLES_ORDERED_SET_H_ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | // #include "absl/container/flat_hash_map.h" 30 | // #include "absl/types/span.h" 31 | 32 | //#include "tsl/platform/logging.h" 33 | 34 | namespace xla { 35 | // This is a set data structure that provides a deterministic iteration order. 36 | // The iteration order of elements only depends on the sequence of 37 | // inserts/deletes, so as long as the inserts/deletes happen in the same 38 | // sequence, the set will have the same iteration order. 39 | // 40 | // Assumes that T can be cheaply copied for simplicity. 41 | template 42 | class OrderedSet { 43 | public: 44 | // Inserts `value` into the ordered set. Returns true if the value was not 45 | // present in the set before the insertion. 46 | bool Insert(T value) { 47 | bool new_insertion = 48 | value_to_index_.insert({value, static_cast(value_sequence_.size())}).second; 49 | if (new_insertion) { 50 | value_sequence_.push_back(value); 51 | } 52 | return new_insertion; 53 | } 54 | 55 | // Removes `value` from the set. Assumes `value` is already present in the 56 | // set. 57 | void Erase(T value) { 58 | auto it = value_to_index_.find(value); 59 | if (it == value_to_index_.end()) { 60 | std::cerr << "Value not found in OrderedSet" << std::endl; 61 | exit(0); 62 | } 63 | 64 | auto index = it->second; 65 | // Since we don't want to move values around in `value_sequence_` we swap 66 | // the value in the last position and with value to be deleted and then 67 | // pop_back. 68 | value_to_index_[value_sequence_.back()] = index; 69 | std::swap(value_sequence_[it->second], value_sequence_.back()); 70 | value_sequence_.pop_back(); 71 | value_to_index_.erase(it); 72 | } 73 | 74 | void Reserve(size_t new_size) { 75 | value_to_index_.reserve(new_size); 76 | value_sequence_.reserve(new_size); 77 | } 78 | 79 | void Clear() { 80 | value_to_index_.clear(); 81 | value_sequence_.clear(); 82 | } 83 | 84 | bool Contains(T value) const { return value_to_index_.find(value) != value_to_index_.end(); } 85 | size_t Size() const { return value_sequence_.size(); } 86 | 87 | std::vector const& GetSequence() const { return value_sequence_; } 88 | 89 | private: 90 | // The stable order that we maintain through insertions and deletions. 91 | std::vector value_sequence_; 92 | 93 | // Maps values to their indices in `value_sequence_`. 94 | std::unordered_map value_to_index_; 95 | };; 96 | } // namespace xla 97 | 98 | #endif // XLA_SERVICE_GRAPHCYCLES_ORDERED_SET_H_ 99 | --------------------------------------------------------------------------------