Skip to content
Open
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
2 changes: 1 addition & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ xnnpack_cc_library(
":xnnpack_h",
"//src/configs:config_hdrs",
"//src/configs:hardware_config",
"//src/configs:microkernel_configs",
"//src/subgraph/rewrites:fp16_to_fp32",
"@pthreadpool",
],
)
Expand Down
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ SET(SUBGRAPH_SRCS
src/subgraph/max-pooling-2d.c
src/subgraph/pack-lh.c
src/subgraph/reshape-helpers.c
src/subgraph/rewrites/fp16_to_fp32.cc
src/subgraph/rope.c
src/subgraph/softmax.c
src/subgraph/space-to-depth-2d.c
Expand Down Expand Up @@ -982,7 +983,7 @@ IF(XNNPACK_BUILD_LIBRARY)
TARGET_LINK_LIBRARIES(xnnpack-operator-run PRIVATE xnnpack-base xnnpack-logging)
TARGET_LINK_LIBRARIES(xnnpack-operator-utils PRIVATE xnnpack-base xnnpack-logging)
TARGET_LINK_LIBRARIES(xnnpack-reference-ukernels PRIVATE xnnpack-base xnnpack-datatype)
TARGET_LINK_LIBRARIES(xnnpack-subgraph PRIVATE xnnpack-base xnnpack-allocator xnnpack-logging xnnpack-memory xnnpack-mutex xnnpack-operators xnnpack-operator-run xnnpack-datatype)
TARGET_LINK_LIBRARIES(xnnpack-subgraph PRIVATE xnnpack-base xnnpack-allocator xnnpack-cache xnnpack-logging xnnpack-memory xnnpack-mutex xnnpack-operators xnnpack-operator-run xnnpack-datatype)
TARGET_LINK_LIBRARIES(XNNPACK PRIVATE xnnpack-base xnnpack-allocator xnnpack-cache
xnnpack-hardware-config xnnpack-indirection xnnpack-memory xnnpack-microkernel-utils xnnpack-microparams-init
xnnpack-mutex xnnpack-normalization xnnpack-operators xnnpack-operator-run
Expand Down
6 changes: 5 additions & 1 deletion src/runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <stdio.h> // For snprintf.
#include <stdlib.h>
#include <string.h>
#include "src/subgraph/rewrites/fp16_to_fp32.h"

#if defined(__EMSCRIPTEN__)
#include <emscripten/emscripten.h>
Expand Down Expand Up @@ -585,6 +586,9 @@ enum xnn_status xnn_create_runtime_v4(
goto error;
}

XNN_IF_ERROR_GOTO(error, xnn_subgraph_alias_fp16_fp32_fallback_data(
subgraph, weights_cache));

status = xnn_status_out_of_memory;

runtime = xnn_allocate_zero_memory(sizeof(struct xnn_runtime));
Expand Down Expand Up @@ -1161,7 +1165,7 @@ enum xnn_status xnn_delete_runtime(
xnn_release_memory(runtime->opdata);

if (runtime->values != NULL) {
// Release the buffers created during FP16 rewrite.
// Release buffers created during rewrites.
for (size_t i = 0; i < runtime->num_values; i++) {
struct xnn_runtime_value* value = &runtime->values[i];
if (value->allocation_type == xnn_allocation_type_dynamic ||
Expand Down
5 changes: 5 additions & 0 deletions src/subgraph.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include "include/experimental.h"
#include "include/xnnpack.h"
#include "src/subgraph/rewrites/fp16_to_fp32.h"
#include "src/xnnpack/allocation-type.h"
#include "src/xnnpack/allocator.h"
#include "src/xnnpack/common.h"
Expand Down Expand Up @@ -4336,6 +4337,10 @@ enum xnn_status xnn_subgraph_optimize(xnn_subgraph_t subgraph,
XNN_RETURN_IF_ERROR(
xnn_subgraph_optimize_packed_lhs(subgraph, optimization_flags));

if (!xnn_is_f16_supported_natively(hardware_config)) {
XNN_RETURN_IF_ERROR(xnn_subgraph_fallback_from_fp16_to_fp32(subgraph, optimization_flags));
}

return xnn_status_success;
}

Expand Down
21 changes: 21 additions & 0 deletions src/subgraph/rewrites/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
load(
"//:build_defs.bzl",
"xnnpack_cxx_library",
)

package(default_visibility = ["//:__subpackages__"])

xnnpack_cxx_library(
name = "fp16_to_fp32",
srcs = ["fp16_to_fp32.cc"],
hdrs = ["fp16_to_fp32.h"],
deps = [
"//:allocator",
"//:cache",
"//:internal",
"//:logging",
"//:node_type",
"//:subgraph_h",
"//:xnnpack_h",
],
)
Loading
Loading