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. diff --git a/backends/xnnpack/runtime/XNNCompiler.cpp b/backends/xnnpack/runtime/XNNCompiler.cpp index b71ab08ea45..3e697566ce5 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, \ @@ -1554,48 +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 = { \ - .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 = {.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 @@ -1628,25 +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 = { \ - .output_min = min_max.first, .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/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_); diff --git a/backends/xnnpack/runtime/XNNWeightsCache.cpp b/backends/xnnpack/runtime/XNNWeightsCache.cpp index 06216b721c1..54191b72825 100644 --- a/backends/xnnpack/runtime/XNNWeightsCache.cpp +++ b/backends/xnnpack/runtime/XNNWeightsCache.cpp @@ -228,11 +228,11 @@ 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 {