From 6efe6c3405c553db810bf28d1139ca5b8f296a18 Mon Sep 17 00:00:00 2001 From: Jacob Szwejbka Date: Thu, 16 Oct 2025 21:54:35 -0700 Subject: [PATCH 1/4] xnnpack compiler flag --- backends/xnnpack/CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/backends/xnnpack/CMakeLists.txt b/backends/xnnpack/CMakeLists.txt index 33bf84b9066..625e3d2523f 100644 --- a/backends/xnnpack/CMakeLists.txt +++ b/backends/xnnpack/CMakeLists.txt @@ -35,7 +35,10 @@ if(EXECUTORCH_XNNPACK_ENABLE_KLEIDI) add_definitions(-DENABLE_XNNPACK_KLEIDI) endif() -set(_common_compile_options -Wno-deprecated-declarations -fPIC) +set(_common_compile_options + $<$:/wd4996> + $<$>:-Wno-deprecated-declarations -fPIC> +) set(_xnnpack_schema__include_dir "${CMAKE_BINARY_DIR}/schema/include") # Paths to headers generated from the .fbs files. From 25afae74369eb23e70e5798804dce35b14aaf985 Mon Sep 17 00:00:00 2001 From: Jacob Szwejbka Date: Thu, 16 Oct 2025 22:25:04 -0700 Subject: [PATCH 2/4] ETUnwrap and cpp20 initializer in xnnpack --- backends/xnnpack/runtime/XNNCompiler.cpp | 5 +++-- backends/xnnpack/runtime/XNNPACKBackend.cpp | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/backends/xnnpack/runtime/XNNCompiler.cpp b/backends/xnnpack/runtime/XNNCompiler.cpp index b71ab08ea45..b2baa461069 100644 --- a/backends/xnnpack/runtime/XNNCompiler.cpp +++ b/backends/xnnpack/runtime/XNNCompiler.cpp @@ -1539,8 +1539,9 @@ Error defineGenericUnaryNode( MAYBE_UNUSED(graph); \ auto graph_node = node->xnode_union_as_XNN##name(); \ std::pair min_max = getOutputMinMax(node); \ - union xnn_unary_params params = { \ - .clamp = {.min = min_max.first, .max = min_max.second}}; \ + union xnn_unary_params params; \ + params.clamp.min = min_max.first; \ + params.clamp.max = min_max.second; \ return defineGenericUnaryNode( \ subgraph_ptr, \ remapped_ids, \ diff --git a/backends/xnnpack/runtime/XNNPACKBackend.cpp b/backends/xnnpack/runtime/XNNPACKBackend.cpp index 70845b6cab1..76e83d4b57b 100644 --- a/backends/xnnpack/runtime/XNNPACKBackend.cpp +++ b/backends/xnnpack/runtime/XNNPACKBackend.cpp @@ -82,7 +82,11 @@ class XnnpackBackend final auto program_id = reinterpret_cast(context.get_runtime_allocator()); - auto workspace = ET_UNWRAP(get_or_create_workspace(program_id)); + auto workspace_result = get_or_create_workspace(program_id); + if (!workspace_result.ok()) { + return workspace_result.error(); + } + auto workspace = workspace_result.get(); #ifdef ENABLE_XNNPACK_WEIGHTS_CACHE const std::lock_guard lock_weight_cache(weights_cache_mutex_); From 32c29e5ba637479cab3a02f221ca0922a6c790d2 Mon Sep 17 00:00:00 2001 From: Jacob Szwejbka Date: Thu, 16 Oct 2025 22:31:33 -0700 Subject: [PATCH 3/4] more cpp20 initializers in xnnpack --- backends/xnnpack/runtime/XNNCompiler.cpp | 12 +++++++----- backends/xnnpack/runtime/XNNWeightsCache.cpp | 9 ++++----- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/backends/xnnpack/runtime/XNNCompiler.cpp b/backends/xnnpack/runtime/XNNCompiler.cpp index b2baa461069..f737611c2fc 100644 --- a/backends/xnnpack/runtime/XNNCompiler.cpp +++ b/backends/xnnpack/runtime/XNNCompiler.cpp @@ -1563,8 +1563,8 @@ Error defineGenericUnaryNode( const fb_xnnpack::XNNGraph* graph) noexcept { \ MAYBE_UNUSED(graph); \ auto graph_node = node->xnode_union_as_XNNLeakyReLU(); \ - union xnn_unary_params params = { \ - .leaky_relu = {.negative_slope = graph_node->negative_slope()}}; \ + union xnn_unary_params params; \ + params.leaky_relu.negative_slope = graph_node->negative_slope(); \ return defineGenericUnaryNode( \ subgraph_ptr, \ remapped_ids, \ @@ -1586,7 +1586,8 @@ Error defineGenericUnaryNode( const fb_xnnpack::XNNGraph* graph) noexcept { \ MAYBE_UNUSED(graph); \ auto graph_node = node->xnode_union_as_XNNELU(); \ - union xnn_unary_params params = {.elu = {.alpha = graph_node->alpha()}}; \ + union xnn_unary_params params; \ + params.elu.alpha = graph_node->alpha(); \ return defineGenericUnaryNode( \ subgraph_ptr, \ remapped_ids, \ @@ -1638,8 +1639,9 @@ Error defineGenericBinaryNode( MAYBE_UNUSED(graph); \ auto graph_node = node->xnode_union_as_XNN##name(); \ std::pair min_max = getOutputMinMax(node); \ - struct xnn_binary_params params = { \ - .output_min = min_max.first, .output_max = min_max.second}; \ + struct xnn_binary_params params; \ + params.output_min = min_max.first; \ + params.output_max = min_max.second; \ return defineGenericBinaryNode( \ subgraph_ptr, \ remapped_ids, \ diff --git a/backends/xnnpack/runtime/XNNWeightsCache.cpp b/backends/xnnpack/runtime/XNNWeightsCache.cpp index 06216b721c1..6d4f96af5e2 100644 --- a/backends/xnnpack/runtime/XNNWeightsCache.cpp +++ b/backends/xnnpack/runtime/XNNWeightsCache.cpp @@ -228,11 +228,10 @@ size_t XNNWeightsCache::look_up_or_insert( weight_bias_name.append(bias_entry->second); } } - PackedDataMeta packed_data_metadata = { - .offset = next_offset, - .ref_count = - 0, // ref_count is only incremented after finalizing for runtime - .in_current_runtime = true}; + PackedDataMeta packed_data_metadata; + packed_data_metadata.offset = next_offset; + packed_data_metadata.ref_count = 0; // ref_count is only incremented after finalizing for runtime + packed_data_metadata.in_current_runtime = true; context->name_to_packed_data_metadata_[weight_bias_name] = packed_data_metadata; } else { From fe5da0a2fec5d0c96a9384d6c469b16c7908fcf9 Mon Sep 17 00:00:00 2001 From: Jacob Szwejbka Date: Fri, 17 Oct 2025 11:40:14 -0700 Subject: [PATCH 4/4] lint --- backends/xnnpack/runtime/XNNCompiler.cpp | 120 +++++++++---------- backends/xnnpack/runtime/XNNWeightsCache.cpp | 3 +- 2 files changed, 62 insertions(+), 61 deletions(-) diff --git a/backends/xnnpack/runtime/XNNCompiler.cpp b/backends/xnnpack/runtime/XNNCompiler.cpp index f737611c2fc..3e697566ce5 100644 --- a/backends/xnnpack/runtime/XNNCompiler.cpp +++ b/backends/xnnpack/runtime/XNNCompiler.cpp @@ -1555,49 +1555,49 @@ Error defineGenericUnaryNode( } // Macro for unary operations with leaky_relu parameters -#define _DEFINE_UNARY_NODE_WITH_LEAKY_RELU(name) \ - Error define##name##Node( \ - xnn_subgraph_t subgraph_ptr, \ - const std::unordered_map& remapped_ids, \ - const NodePtr node, \ - const fb_xnnpack::XNNGraph* graph) noexcept { \ - MAYBE_UNUSED(graph); \ - auto graph_node = node->xnode_union_as_XNNLeakyReLU(); \ - union xnn_unary_params params; \ - params.leaky_relu.negative_slope = graph_node->negative_slope(); \ - return defineGenericUnaryNode( \ - subgraph_ptr, \ - remapped_ids, \ - graph_node->input_id(), \ - graph_node->output_id(), \ - graph_node->flags(), \ - xnn_unary_leaky_relu, \ - ¶ms, \ - node->xnode_union_type(), \ - node->debug_handle()); \ +#define _DEFINE_UNARY_NODE_WITH_LEAKY_RELU(name) \ + Error define##name##Node( \ + xnn_subgraph_t subgraph_ptr, \ + const std::unordered_map& remapped_ids, \ + const NodePtr node, \ + const fb_xnnpack::XNNGraph* graph) noexcept { \ + MAYBE_UNUSED(graph); \ + auto graph_node = node->xnode_union_as_XNNLeakyReLU(); \ + union xnn_unary_params params; \ + params.leaky_relu.negative_slope = graph_node->negative_slope(); \ + return defineGenericUnaryNode( \ + subgraph_ptr, \ + remapped_ids, \ + graph_node->input_id(), \ + graph_node->output_id(), \ + graph_node->flags(), \ + xnn_unary_leaky_relu, \ + ¶ms, \ + node->xnode_union_type(), \ + node->debug_handle()); \ } // Macro for unary operations with elu parameters -#define _DEFINE_UNARY_NODE_WITH_ELU(name) \ - Error define##name##Node( \ - xnn_subgraph_t subgraph_ptr, \ - const std::unordered_map& remapped_ids, \ - const NodePtr node, \ - const fb_xnnpack::XNNGraph* graph) noexcept { \ - MAYBE_UNUSED(graph); \ - auto graph_node = node->xnode_union_as_XNNELU(); \ - union xnn_unary_params params; \ - params.elu.alpha = graph_node->alpha(); \ - return defineGenericUnaryNode( \ - subgraph_ptr, \ - remapped_ids, \ - graph_node->input_id(), \ - graph_node->output_id(), \ - graph_node->flags(), \ - xnn_unary_elu, \ - ¶ms, \ - node->xnode_union_type(), \ - node->debug_handle()); \ +#define _DEFINE_UNARY_NODE_WITH_ELU(name) \ + Error define##name##Node( \ + xnn_subgraph_t subgraph_ptr, \ + const std::unordered_map& remapped_ids, \ + const NodePtr node, \ + const fb_xnnpack::XNNGraph* graph) noexcept { \ + MAYBE_UNUSED(graph); \ + auto graph_node = node->xnode_union_as_XNNELU(); \ + union xnn_unary_params params; \ + params.elu.alpha = graph_node->alpha(); \ + return defineGenericUnaryNode( \ + subgraph_ptr, \ + remapped_ids, \ + graph_node->input_id(), \ + graph_node->output_id(), \ + graph_node->flags(), \ + xnn_unary_elu, \ + ¶ms, \ + node->xnode_union_type(), \ + node->debug_handle()); \ } // Generic helper function for binary operations @@ -1630,26 +1630,26 @@ Error defineGenericBinaryNode( } // Macro for binary operations with min/max parameters -#define _DEFINE_BINARY_NODE_WITH_MINMAX(name, op_type) \ - Error define##name##Node( \ - xnn_subgraph_t subgraph_ptr, \ - const std::unordered_map& remapped_ids, \ - const NodePtr node, \ - const fb_xnnpack::XNNGraph* graph) noexcept { \ - MAYBE_UNUSED(graph); \ - auto graph_node = node->xnode_union_as_XNN##name(); \ - std::pair min_max = getOutputMinMax(node); \ - struct xnn_binary_params params; \ - params.output_min = min_max.first; \ - params.output_max = min_max.second; \ - return defineGenericBinaryNode( \ - subgraph_ptr, \ - remapped_ids, \ - graph_node, \ - op_type, \ - ¶ms, \ - node->xnode_union_type(), \ - node->debug_handle()); \ +#define _DEFINE_BINARY_NODE_WITH_MINMAX(name, op_type) \ + Error define##name##Node( \ + xnn_subgraph_t subgraph_ptr, \ + const std::unordered_map& remapped_ids, \ + const NodePtr node, \ + const fb_xnnpack::XNNGraph* graph) noexcept { \ + MAYBE_UNUSED(graph); \ + auto graph_node = node->xnode_union_as_XNN##name(); \ + std::pair min_max = getOutputMinMax(node); \ + struct xnn_binary_params params; \ + params.output_min = min_max.first; \ + params.output_max = min_max.second; \ + return defineGenericBinaryNode( \ + subgraph_ptr, \ + remapped_ids, \ + graph_node, \ + op_type, \ + ¶ms, \ + node->xnode_union_type(), \ + node->debug_handle()); \ } // Macro for binary operations without parameters diff --git a/backends/xnnpack/runtime/XNNWeightsCache.cpp b/backends/xnnpack/runtime/XNNWeightsCache.cpp index 6d4f96af5e2..54191b72825 100644 --- a/backends/xnnpack/runtime/XNNWeightsCache.cpp +++ b/backends/xnnpack/runtime/XNNWeightsCache.cpp @@ -230,7 +230,8 @@ size_t XNNWeightsCache::look_up_or_insert( } PackedDataMeta packed_data_metadata; packed_data_metadata.offset = next_offset; - packed_data_metadata.ref_count = 0; // ref_count is only incremented after finalizing for runtime + packed_data_metadata.ref_count = + 0; // ref_count is only incremented after finalizing for runtime packed_data_metadata.in_current_runtime = true; context->name_to_packed_data_metadata_[weight_bias_name] = packed_data_metadata;