@@ -98,15 +98,14 @@ VkResult vkml_allocate_basics(
9898 VkDevice* device,
9999 VkQueue* queue,
100100 VkCommandPool* command_pool,
101- uint32_t * queue_family_index);
101+ uint32_t * queue_family_index,
102+ bool request_neural_statistics,
103+ bool * neural_statistics_device_enabled);
102104
103105// Helper functions to dump VGF Delegate Boundary Inputs
104106constexpr const char * kVgfDumpInputsDirEnv = " EXECUTORCH_VGF_DUMP_INPUTS_DIR" ;
105107constexpr const char * kVgfDumpInputsAndExitEnv =
106108 " EXECUTORCH_VGF_DUMP_INPUTS_AND_EXIT" ;
107- constexpr const char * kVgfNeuralStatisticsEnv =
108- " EXECUTORCH_VGF_ENABLE_NEURAL_STATISTICS" ;
109-
110109std::atomic<uint64_t > g_vgf_dump_invocation{0 };
111110
112111bool env_flag_enabled (const char * name) {
@@ -414,6 +413,7 @@ class VGFBackend final : public ::executorch::runtime::BackendInterface {
414413 }
415414
416415 VkResult result;
416+ neural_statistics_config_ = get_vgf_neural_statistics_runtime_config ();
417417
418418 // Fetch basic vulkan objects once
419419 result = vkml_allocate_basics (
@@ -422,7 +422,9 @@ class VGFBackend final : public ::executorch::runtime::BackendInterface {
422422 &vk_device,
423423 &vk_queue,
424424 &vk_command_pool,
425- &vk_queue_family_index);
425+ &vk_queue_family_index,
426+ neural_statistics_config_.requested ,
427+ &neural_statistics_device_enabled_);
426428 if (result != VK_SUCCESS ) {
427429 ET_LOG (
428430 Error, " Failed to initialize the Vulkan device error 0x%08X" , result);
@@ -508,7 +510,10 @@ class VGFBackend final : public ::executorch::runtime::BackendInterface {
508510 vk_device,
509511 vk_queue,
510512 vk_command_pool,
511- vk_queue_family_index);
513+ vk_queue_family_index,
514+ neural_statistics_config_.requested ,
515+ neural_statistics_device_enabled_,
516+ neural_statistics_config_.mode_index );
512517
513518#ifdef ET_EVENT_TRACER_ENABLED
514519 event_tracer_end_profiling_delegate (event_tracer, allocate_repr_event);
@@ -683,7 +688,7 @@ class VGFBackend final : public ::executorch::runtime::BackendInterface {
683688#ifdef ET_EVENT_TRACER_ENABLED
684689 event_tracer_end_profiling_delegate (event_tracer, dispatch_event);
685690
686- if (event_tracer != nullptr && env_flag_enabled ( kVgfNeuralStatisticsEnv )) {
691+ if (event_tracer != nullptr && repr-> neural_statistics_requested ( )) {
687692 // We attach the neural statistics JSON blob to ETDump as delegate
688693 // metadata, when event tracer is active.
689694
@@ -787,6 +792,8 @@ class VGFBackend final : public ::executorch::runtime::BackendInterface {
787792 VkQueue vk_queue = VK_NULL_HANDLE ;
788793 VkCommandPool vk_command_pool = VK_NULL_HANDLE ;
789794 uint32_t vk_queue_family_index = UINT32_MAX ;
795+ VgfNeuralStatisticsRuntimeConfig neural_statistics_config_{};
796+ bool neural_statistics_device_enabled_ = false ;
790797 bool is_initialized_ = false ;
791798};
792799
@@ -802,9 +809,15 @@ VkResult vkml_allocate_basics(
802809 VkDevice* device,
803810 VkQueue* queue,
804811 VkCommandPool* command_pool,
805- uint32_t * queue_family_index) {
812+ uint32_t * queue_family_index,
813+ bool request_neural_statistics,
814+ bool * neural_statistics_device_enabled) {
806815 VkResult result;
807816
817+ if (neural_statistics_device_enabled != nullptr ) {
818+ *neural_statistics_device_enabled = false ;
819+ }
820+
808821 if (VK_SUCCESS != volkInitialize ()) {
809822 ET_LOG (Error, " Volk failed to initialize" );
810823 return VK_ERROR_INITIALIZATION_FAILED ;
@@ -948,9 +961,21 @@ VkResult vkml_allocate_basics(
948961 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES ,
949962 .pNext = &available_12,
950963 };
964+ #if defined(VK_ARM_data_graph_neural_accelerator_statistics)
965+ VkPhysicalDeviceDataGraphNeuralAcceleratorStatisticsFeaturesARM
966+ available_neural_statistics{
967+ .sType =
968+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DATA_GRAPH_NEURAL_ACCELERATOR_STATISTICS_FEATURES_ARM ,
969+ .pNext = &available_11,
970+ .dataGraphNeuralAcceleratorStatistics = VK_FALSE ,
971+ };
972+ void * available_features_pnext = &available_neural_statistics;
973+ #else
974+ void * available_features_pnext = &available_11;
975+ #endif
951976 VkPhysicalDeviceFeatures2 available_2 = {
952977 .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2 ,
953- .pNext = &available_11 ,
978+ .pNext = available_features_pnext ,
954979 };
955980 vkGetPhysicalDeviceFeatures2 (*physical_device, &available_2);
956981
@@ -992,6 +1017,15 @@ VkResult vkml_allocate_basics(
9921017 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DATA_GRAPH_FEATURES_ARM , nullptr };
9931018 features_graph.dataGraph = true ;
9941019 features_graph.pNext = &features_tensor;
1020+ #if defined(VK_ARM_data_graph_neural_accelerator_statistics)
1021+ VkPhysicalDeviceDataGraphNeuralAcceleratorStatisticsFeaturesARM
1022+ features_neural_statistics{
1023+ .sType =
1024+ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DATA_GRAPH_NEURAL_ACCELERATOR_STATISTICS_FEATURES_ARM ,
1025+ .pNext = &features_tensor,
1026+ .dataGraphNeuralAcceleratorStatistics = VK_FALSE ,
1027+ };
1028+ #endif
9951029
9961030 VkPhysicalDeviceFeatures device_features = {};
9971031 device_features.shaderInt16 = VK_TRUE ;
@@ -1014,6 +1048,54 @@ VkResult vkml_allocate_basics(
10141048 *physical_device, nullptr , &exts, available.data ());
10151049
10161050 vector<const char *> requested_exts;
1051+
1052+ #if defined(VK_ARM_data_graph_neural_accelerator_statistics)
1053+ const bool neural_statistics_extension_available = std::any_of (
1054+ available.begin (), available.end (), [](const auto & ext_avail) {
1055+ return std::strcmp (
1056+ VK_ARM_DATA_GRAPH_NEURAL_ACCELERATOR_STATISTICS_EXTENSION_NAME ,
1057+ ext_avail.extensionName ) == 0 ;
1058+ });
1059+ const bool neural_statistics_feature_available =
1060+ available_neural_statistics.dataGraphNeuralAcceleratorStatistics ==
1061+ VK_TRUE ;
1062+ const bool enable_neural_statistics_device = request_neural_statistics &&
1063+ neural_statistics_extension_available &&
1064+ neural_statistics_feature_available;
1065+
1066+ if (request_neural_statistics && !neural_statistics_extension_available) {
1067+ ET_LOG (
1068+ Info,
1069+ " %s was requested but the Vulkan device does not expose %s" ,
1070+ kVgfNeuralStatisticsEnableEnv ,
1071+ VK_ARM_DATA_GRAPH_NEURAL_ACCELERATOR_STATISTICS_EXTENSION_NAME );
1072+ } else if (
1073+ request_neural_statistics && !neural_statistics_feature_available) {
1074+ ET_LOG (
1075+ Info,
1076+ " %s was requested but dataGraphNeuralAcceleratorStatistics is not supported" ,
1077+ kVgfNeuralStatisticsEnableEnv );
1078+ }
1079+
1080+ if (enable_neural_statistics_device) {
1081+ requested_exts.push_back (
1082+ VK_ARM_DATA_GRAPH_NEURAL_ACCELERATOR_STATISTICS_EXTENSION_NAME );
1083+ features_neural_statistics.dataGraphNeuralAcceleratorStatistics = VK_TRUE ;
1084+ features_graph.pNext = &features_neural_statistics;
1085+ if (neural_statistics_device_enabled != nullptr ) {
1086+ *neural_statistics_device_enabled = true ;
1087+ }
1088+ }
1089+ #else
1090+ if (request_neural_statistics) {
1091+ ET_LOG (
1092+ Info,
1093+ " %s was requested but Vulkan headers do not expose "
1094+ " VK_ARM_data_graph_neural_accelerator_statistics" ,
1095+ kVgfNeuralStatisticsEnableEnv );
1096+ }
1097+ #endif
1098+
10171099 for (auto & ext : dev_exts) {
10181100 bool found = false ;
10191101 for (auto const & ext_avail : available) {
0 commit comments