Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion backends/xnnpack/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
$<$<CXX_COMPILER_ID:MSVC>:/wd4996>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-deprecated-declarations -fPIC>
)

set(_xnnpack_schema__include_dir "${CMAKE_BINARY_DIR}/schema/include")
# Paths to headers generated from the .fbs files.
Expand Down
123 changes: 63 additions & 60 deletions backends/xnnpack/runtime/XNNCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1539,8 +1539,9 @@ Error defineGenericUnaryNode(
MAYBE_UNUSED(graph); \
auto graph_node = node->xnode_union_as_XNN##name(); \
std::pair<float, float> 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, \
Expand All @@ -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<uint32_t, uint32_t>& 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, \
&params, \
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<uint32_t, uint32_t>& 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, \
&params, \
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<uint32_t, uint32_t>& 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, \
&params, \
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<uint32_t, uint32_t>& 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, \
&params, \
node->xnode_union_type(), \
node->debug_handle()); \
}

// Generic helper function for binary operations
Expand Down Expand Up @@ -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<uint32_t, uint32_t>& 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<float, float> 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, \
&params, \
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<uint32_t, uint32_t>& 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<float, float> 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, \
&params, \
node->xnode_union_type(), \
node->debug_handle()); \
}

// Macro for binary operations without parameters
Expand Down
6 changes: 5 additions & 1 deletion backends/xnnpack/runtime/XNNPACKBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ class XnnpackBackend final

auto program_id =
reinterpret_cast<uintptr_t>(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<std::mutex> lock_weight_cache(weights_cache_mutex_);
Expand Down
10 changes: 5 additions & 5 deletions backends/xnnpack/runtime/XNNWeightsCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading