diff --git a/source/lib/ze_loader_compat.h b/source/lib/ze_loader_compat.h new file mode 100644 index 0000000..56f17e8 --- /dev/null +++ b/source/lib/ze_loader_compat.h @@ -0,0 +1,162 @@ +/* + * + * Copyright (C) 2024 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ +#pragma once + +#include "ze_ddi.h" +#include "zet_ddi.h" +#include "zes_ddi.h" + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function-pointer for zesDeviceEnumActiveVFExp +typedef ze_result_t (ZE_APICALL *zes_pfnDeviceEnumActiveVFExp_t)( + zes_device_handle_t, + uint32_t*, + zes_vf_handle_t* + ); +/////////////////////////////////////////////////////////////////////////////// +/// @brief Table of DeviceExp functions pointers +typedef struct _zes_device_exp_dditable_compat_t +{ + zes_pfnDeviceGetSubDevicePropertiesExp_t pfnGetSubDevicePropertiesExp; + zes_pfnDeviceEnumActiveVFExp_t pfnEnumActiveVFExp; + zes_pfnDeviceEnumEnabledVFExp_t pfnEnumEnabledVFExp; +} zes_device_exp_dditable_compat_t; +/////////////////////////////////////////////////////////////////////////////// +/// @brief Virtual function utilization flag bit fields +typedef uint32_t zes_vf_info_util_exp_flags_t; +typedef enum _zes_vf_info_util_exp_flag_t +{ + ZES_VF_INFO_UTIL_EXP_FLAG_INFO_NONE = ZE_BIT(0), ///< No info associated with virtual function + ZES_VF_INFO_UTIL_EXP_FLAG_INFO_MEM_CPU = ZE_BIT(1), ///< System memory utilization associated with virtual function + ZES_VF_INFO_UTIL_EXP_FLAG_INFO_MEM_GPU = ZE_BIT(2), ///< Device memory utilization associated with virtual function + ZES_VF_INFO_UTIL_EXP_FLAG_INFO_ENGINE = ZE_BIT(3), ///< Engine utilization associated with virtual function + ZES_VF_INFO_UTIL_EXP_FLAG_FORCE_UINT32 = 0x7fffffff + +} zes_vf_info_util_exp_flag_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Virtual function management properties +typedef struct _zes_vf_exp_properties_t +{ + zes_structure_type_t stype; ///< [in] type of this structure + void* pNext; ///< [in,out][optional] must be null or a pointer to an extension-specific + ///< structure (i.e. contains stype and pNext). + zes_pci_address_t address; ///< [out] Virtual function BDF address + zes_uuid_t uuid; ///< [out] universal unique identifier of the device + zes_vf_info_util_exp_flags_t flags; ///< [out] utilization flags available. May be 0 or a valid combination of + ///< ::zes_vf_info_util_exp_flag_t. + +} zes_vf_exp_properties_t; +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function-pointer for zesVFManagementGetVFPropertiesExp +typedef ze_result_t (ZE_APICALL *zes_pfnVFManagementGetVFPropertiesExp_t)( + zes_vf_handle_t, + zes_vf_exp_properties_t* + ); +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function-pointer for zesVFManagementSetVFTelemetryModeExp +typedef ze_result_t (ZE_APICALL *zes_pfnVFManagementSetVFTelemetryModeExp_t)( + zes_vf_handle_t, + zes_vf_info_util_exp_flags_t, + ze_bool_t + ); +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function-pointer for zesVFManagementSetVFTelemetrySamplingIntervalExp +typedef ze_result_t (ZE_APICALL *zes_pfnVFManagementSetVFTelemetrySamplingIntervalExp_t)( + zes_vf_handle_t, + zes_vf_info_util_exp_flags_t, + uint64_t + ); +/////////////////////////////////////////////////////////////////////////////// +/// @brief Table of VFManagementExp functions pointers +typedef struct _zes_vf_management_exp_dditable_compat_t +{ + zes_pfnVFManagementGetVFCapabilitiesExp_t pfnGetVFCapabilitiesExp; + zes_pfnVFManagementGetVFPropertiesExp_t pfnGetVFPropertiesExp; + zes_pfnVFManagementGetVFMemoryUtilizationExp_t pfnGetVFMemoryUtilizationExp; + zes_pfnVFManagementGetVFEngineUtilizationExp_t pfnGetVFEngineUtilizationExp; + zes_pfnVFManagementSetVFTelemetryModeExp_t pfnSetVFTelemetryModeExp; + zes_pfnVFManagementSetVFTelemetrySamplingIntervalExp_t pfnSetVFTelemetrySamplingIntervalExp; +} zes_vf_management_exp_dditable_compat_t; +/////////////////////////////////////////////////////////////////////////////// +/// @brief Function-pointer for zetMetricGroupCreateExp +typedef ze_result_t (ZE_APICALL *zet_pfnMetricGroupCreateExp_t)( + zet_device_handle_t, + const char*, + const char*, + zet_metric_group_sampling_type_flags_t, + zet_metric_group_handle_t* + ); +/////////////////////////////////////////////////////////////////////////////// +/// @brief Table of MetricGroupExp functions pointers +typedef struct _zet_metric_group_exp_dditable_compat_t +{ + zet_pfnMetricGroupCalculateMultipleMetricValuesExp_t pfnCalculateMultipleMetricValuesExp; + zet_pfnMetricGroupGetGlobalTimestampsExp_t pfnGetGlobalTimestampsExp; + zet_pfnMetricGroupGetExportDataExp_t pfnGetExportDataExp; + zet_pfnMetricGroupCalculateMetricExportDataExp_t pfnCalculateMetricExportDataExp; + zet_pfnMetricGroupCreateExp_t pfnCreateExp; + zet_pfnMetricGroupAddMetricExp_t pfnAddMetricExp; + zet_pfnMetricGroupRemoveMetricExp_t pfnRemoveMetricExp; + zet_pfnMetricGroupCloseExp_t pfnCloseExp; + zet_pfnMetricGroupDestroyExp_t pfnDestroyExp; +} zet_metric_group_exp_dditable_compat_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Container for all DDI tables +typedef struct _zes_dditable_compat_t +{ + zes_global_dditable_t Global; + zes_device_dditable_t Device; + zes_device_exp_dditable_compat_t DeviceExp; + zes_driver_dditable_t Driver; + zes_driver_exp_dditable_t DriverExp; + zes_overclock_dditable_t Overclock; + zes_scheduler_dditable_t Scheduler; + zes_performance_factor_dditable_t PerformanceFactor; + zes_power_dditable_t Power; + zes_frequency_dditable_t Frequency; + zes_engine_dditable_t Engine; + zes_standby_dditable_t Standby; + zes_firmware_dditable_t Firmware; + zes_firmware_exp_dditable_t FirmwareExp; + zes_memory_dditable_t Memory; + zes_fabric_port_dditable_t FabricPort; + zes_temperature_dditable_t Temperature; + zes_psu_dditable_t Psu; + zes_fan_dditable_t Fan; + zes_led_dditable_t Led; + zes_ras_dditable_t Ras; + zes_ras_exp_dditable_t RasExp; + zes_diagnostics_dditable_t Diagnostics; + zes_vf_management_exp_dditable_compat_t VFManagementExp; +} zes_dditable_compat_t; + +/////////////////////////////////////////////////////////////////////////////// +/// @brief Container for all DDI tables +typedef struct _zet_dditable_compat_t +{ + zet_metric_programmable_exp_dditable_t MetricProgrammableExp; + zet_metric_tracer_exp_dditable_t MetricTracerExp; + zet_metric_decoder_exp_dditable_t MetricDecoderExp; + zet_device_dditable_t Device; + zet_device_exp_dditable_t DeviceExp; + zet_context_dditable_t Context; + zet_command_list_dditable_t CommandList; + zet_module_dditable_t Module; + zet_kernel_dditable_t Kernel; + zet_metric_dditable_t Metric; + zet_metric_exp_dditable_t MetricExp; + zet_metric_group_dditable_t MetricGroup; + zet_metric_group_exp_dditable_compat_t MetricGroupExp; + zet_metric_streamer_dditable_t MetricStreamer; + zet_metric_query_pool_dditable_t MetricQueryPool; + zet_metric_query_dditable_t MetricQuery; + zet_tracer_exp_dditable_t TracerExp; + zet_debug_dditable_t Debug; +} zet_dditable_compat_t; \ No newline at end of file diff --git a/source/loader/ze_ldrddi.cpp b/source/loader/ze_ldrddi.cpp index ba93026..9ac3258 100644 --- a/source/loader/ze_ldrddi.cpp +++ b/source/loader/ze_ldrddi.cpp @@ -134,9 +134,11 @@ namespace loader for( auto& drv : loader::context->zeDrivers ) { if (!drv.dditable.ze.Global.pfnInitDrivers) { - drv.initStatus = ZE_RESULT_ERROR_UNINITIALIZED; + drv.initDriversStatus = ZE_RESULT_ERROR_UNINITIALIZED; continue; } + if(drv.initDriversStatus != ZE_RESULT_SUCCESS) + continue; if( ( 0 < *pCount ) && ( *pCount == total_driver_handle_count)) break; @@ -147,7 +149,7 @@ namespace loader if( ZE_RESULT_SUCCESS != result ) { // If Get Drivers fails with Uninitialized, then update the driver init status to prevent reporting this driver in the next get call. if (ZE_RESULT_ERROR_UNINITIALIZED == result) { - drv.initStatus = result; + drv.initDriversStatus = result; } continue; } diff --git a/source/loader/ze_loader.cpp b/source/loader/ze_loader.cpp index da97ef8..b7b6169 100644 --- a/source/loader/ze_loader.cpp +++ b/source/loader/ze_loader.cpp @@ -179,6 +179,8 @@ namespace loader if (drivers->size() == 1 && !loader::context->forceIntercept) { *requireDdiReinit = true; } + } else { + it++; } if(return_first_driver_result) return result; @@ -309,8 +311,8 @@ namespace loader uint32_t pCount = 0; ze_result_t res = globalInitStored->pfnInitDrivers(&pCount, nullptr, desc); // Verify that this driver successfully init in the call above. - if (driver.initStatus != ZE_RESULT_SUCCESS) { - res = driver.initStatus; + if (driver.initDriversStatus != ZE_RESULT_SUCCESS) { + res = driver.initDriversStatus; } if (debugTraceEnabled) { std::string message = "init driver " + driver.name + " zeInitDrivers(" + loader::to_string(desc) + ") returning "; diff --git a/source/loader/ze_loader_internal.h b/source/loader/ze_loader_internal.h index 2b624a3..087adef 100644 --- a/source/loader/ze_loader_internal.h +++ b/source/loader/ze_loader_internal.h @@ -31,6 +31,7 @@ namespace loader { HMODULE handle = NULL; ze_result_t initStatus = ZE_RESULT_SUCCESS; + ze_result_t initDriversStatus = ZE_RESULT_SUCCESS; dditable_t dditable = {}; std::string name; bool driverInuse = false; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 334efea..6dca364 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -37,8 +37,4 @@ set_property(TEST tests_both_succeed PROPERTY ENVIRONMENT "ZE_ENABLE_NULL_DRIVER add_test(NAME tests_both_gpu COMMAND tests --gtest_filter=*GivenLevelZeroLoaderPresentWhenCallingzeInitThenZeInitDriversThenBothCallsSucceedWithGPUTypes*) set_property(TEST tests_both_gpu PROPERTY ENVIRONMENT "ZE_ENABLE_NULL_DRIVER=1") add_test(NAME tests_both_npu COMMAND tests --gtest_filter=*GivenLevelZeroLoaderPresentWhenCallingzeInitThenZeInitDriversThenBothCallsSucceedWithNPUTypes*) -set_property(TEST tests_both_npu PROPERTY ENVIRONMENT "ZE_ENABLE_NULL_DRIVER=1") -add_test(NAME tests_only_one_gpu COMMAND tests --gtest_filter=*GivenLevelZeroLoaderPresentWhenCallingzeInitThenZeInitDriversThenOnlyOneSucceedsforGPUTypes*) -set_property(TEST tests_only_one_gpu PROPERTY ENVIRONMENT "ZE_ENABLE_NULL_DRIVER=1") -add_test(NAME tests_only_one_npu COMMAND tests --gtest_filter=*GivenLevelZeroLoaderPresentWhenCallingzeInitThenZeInitDriversThenOnlyOneSucceedsforNPUTypes*) -set_property(TEST tests_only_one_npu PROPERTY ENVIRONMENT "ZE_ENABLE_NULL_DRIVER=1") \ No newline at end of file +set_property(TEST tests_both_npu PROPERTY ENVIRONMENT "ZE_ENABLE_NULL_DRIVER=1") \ No newline at end of file diff --git a/test/loader_api.cpp b/test/loader_api.cpp index ca55798..3a49909 100644 --- a/test/loader_api.cpp +++ b/test/loader_api.cpp @@ -192,32 +192,4 @@ TEST( EXPECT_GT(pCount, 0); } -TEST( - LoaderInit, - GivenLevelZeroLoaderPresentWhenCallingzeInitThenZeInitDriversThenOnlyOneSucceedsforGPUTypes) { - - uint32_t pCount = 0; - ze_init_driver_type_desc_t desc = {ZE_STRUCTURE_TYPE_INIT_DRIVER_TYPE_DESC}; - desc.flags = UINT32_MAX; - desc.pNext = nullptr; - putenv_safe( const_cast( "ZEL_TEST_NULL_DRIVER_TYPE=GPU" ) ); - EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, zeInit(ZE_INIT_FLAG_VPU_ONLY)); - EXPECT_EQ(ZE_RESULT_SUCCESS, zeInitDrivers(&pCount, nullptr, &desc)); - EXPECT_GT(pCount, 0); -} - -TEST( - LoaderInit, - GivenLevelZeroLoaderPresentWhenCallingzeInitThenZeInitDriversThenOnlyOneSucceedsforNPUTypes) { - - uint32_t pCount = 0; - ze_init_driver_type_desc_t desc = {ZE_STRUCTURE_TYPE_INIT_DRIVER_TYPE_DESC}; - desc.flags = UINT32_MAX; - desc.pNext = nullptr; - putenv_safe( const_cast( "ZEL_TEST_NULL_DRIVER_TYPE=NPU" ) ); - EXPECT_EQ(ZE_RESULT_ERROR_UNINITIALIZED, zeInit(ZE_INIT_FLAG_GPU_ONLY)); - EXPECT_EQ(ZE_RESULT_SUCCESS, zeInitDrivers(&pCount, nullptr, &desc)); - EXPECT_GT(pCount, 0); -} - } // namespace