Skip to content

Commit bcdd274

Browse files
qukhanxnnpack-bot
authored andcommitted
Fingerprint convolution-nchw kernels packing operations.
PiperOrigin-RevId: 817650790
1 parent d4de083 commit bcdd274

File tree

14 files changed

+2016
-429
lines changed

14 files changed

+2016
-429
lines changed

BUILD.bazel

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ xnnpack_cc_library(
142142
"include/xnnpack.h",
143143
],
144144
deps = [
145+
":fingerprint_id",
145146
"@pthreadpool",
146147
],
147148
)
@@ -775,6 +776,50 @@ xnnpack_cc_library(
775776
],
776777
)
777778

779+
xnnpack_cc_library(
780+
name = "fingerprint_id",
781+
hdrs = ["src/operators/fingerprint_id.h"],
782+
)
783+
784+
xnnpack_cc_library(
785+
name = "fingerprint_cache",
786+
srcs = ["src/operators/fingerprint_cache.c"],
787+
hdrs = ["src/operators/fingerprint_cache.h"],
788+
deps = [
789+
":cache",
790+
":fingerprint_id",
791+
":init_once",
792+
":mutex",
793+
":operator_delete",
794+
":operator_type",
795+
":xnnpack_h",
796+
],
797+
)
798+
799+
xnnpack_cc_library(
800+
name = "fingerprint_check",
801+
srcs = ["src/xnnpack/fingerprint_check.c"],
802+
deps = [
803+
":fingerprint_cache",
804+
":fingerprint_id",
805+
":operators",
806+
":xnnpack_h",
807+
],
808+
)
809+
810+
xnnpack_cc_library(
811+
name = "operator_delete",
812+
srcs = ["src/operator-delete.c"],
813+
deps = [
814+
":allocator",
815+
":logging",
816+
":operator_h",
817+
":operator_utils",
818+
":params",
819+
":xnnpack_h",
820+
],
821+
)
822+
778823
xnnpack_cc_library(
779824
name = "operators",
780825
srcs = OPERATOR_SRCS,
@@ -794,6 +839,8 @@ xnnpack_cc_library(
794839
":cache",
795840
":common",
796841
":datatype",
842+
":fingerprint_cache",
843+
":fingerprint_id",
797844
":indirection",
798845
":internal",
799846
":logging",
@@ -806,6 +853,7 @@ xnnpack_cc_library(
806853
":microparams_init",
807854
":node_type",
808855
":normalization",
856+
":operator_delete",
809857
":operator_type",
810858
":operator_utils",
811859
":pack_lh",

CMakeLists.txt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,9 @@ IF(XNNPACK_BUILD_LIBRARY)
939939
ADD_LIBRARY(xnnpack-allocator OBJECT src/allocator.c)
940940
ADD_LIBRARY(xnnpack-cache OBJECT src/cache.c)
941941
ADD_LIBRARY(xnnpack-datatype OBJECT src/datatype.c)
942+
ADD_LIBRARY(xnnpack-operator-delete OBJECT src/operator-delete.c)
943+
ADD_LIBRARY(xnnpack-fingerprint-cache OBJECT src/operators/fingerprint_cache.c)
944+
ADD_LIBRARY(xnnpack-fingerprint-check OBJECT src/xnnpack/fingerprint_check.c)
942945
ADD_LIBRARY(xnnpack-memory OBJECT src/memory.c)
943946
ADD_LIBRARY(xnnpack-microkernel-utils OBJECT src/microkernel-utils.c)
944947
ADD_LIBRARY(xnnpack-mutex OBJECT src/mutex.c)
@@ -962,21 +965,25 @@ IF(XNNPACK_BUILD_LIBRARY)
962965
TARGET_LINK_LIBRARIES(xnnpack-allocator PRIVATE xnnpack-base xnnpack-logging)
963966
TARGET_LINK_LIBRARIES(xnnpack-cache PRIVATE xnnpack-base xnnpack-logging)
964967
TARGET_LINK_LIBRARIES(xnnpack-datatype PRIVATE xnnpack-base)
968+
TARGET_LINK_LIBRARIES(xnnpack-operator-delete PRIVATE xnnpack-base xnnpack-logging)
965969
TARGET_LINK_LIBRARIES(xnnpack-memory PRIVATE xnnpack-base xnnpack-logging)
966970
TARGET_LINK_LIBRARIES(xnnpack-microkernel-utils PRIVATE xnnpack-base xnnpack-hardware-config xnnpack-logging)
967971
TARGET_LINK_LIBRARIES(xnnpack-mutex PRIVATE xnnpack-base xnnpack-logging)
968972
TARGET_LINK_LIBRARIES(xnnpack-operators PRIVATE xnnpack-base xnnpack-allocator xnnpack-indirection
969973
xnnpack-logging xnnpack-microkernel-utils xnnpack-normalization xnnpack-operator-utils xnnpack-pack-lh xnnpack-packing
970974
xnnpack-reference-ukernels xnnpack-datatype)
975+
TARGET_LINK_LIBRARIES(xnnpack-fingerprint-cache PRIVATE xnnpack-base xnnpack-cache xnnpack-mutex xnnpack-operator-delete)
976+
TARGET_LINK_LIBRARIES(xnnpack-fingerprint-check PRIVATE xnnpack-base xnnpack-fingerprint-cache xnnpack-operators)
971977
TARGET_LINK_LIBRARIES(xnnpack-operator-run PRIVATE xnnpack-base xnnpack-logging)
972978
TARGET_LINK_LIBRARIES(xnnpack-operator-utils PRIVATE xnnpack-base xnnpack-logging)
973979
TARGET_LINK_LIBRARIES(xnnpack-reference-ukernels PRIVATE xnnpack-base xnnpack-datatype)
974980
TARGET_LINK_LIBRARIES(xnnpack-subgraph PRIVATE xnnpack-base xnnpack-allocator xnnpack-logging xnnpack-memory xnnpack-mutex xnnpack-operators xnnpack-operator-run xnnpack-datatype)
975981
TARGET_LINK_LIBRARIES(XNNPACK PRIVATE xnnpack-base xnnpack-allocator xnnpack-cache
976982
xnnpack-hardware-config xnnpack-indirection xnnpack-memory xnnpack-microkernel-utils xnnpack-microparams-init
977-
xnnpack-mutex xnnpack-normalization xnnpack-operators xnnpack-operator-run xnnpack-operator-utils xnnpack-pack-lh xnnpack-packing
978-
xnnpack-microkernels-prod xnnpack-subgraph xnnpack-datatype xnnpack-reference-ukernels)
979-
TARGET_LINK_LIBRARIES(XNNPACK PUBLIC pthreadpool xnnpack-logging)
983+
xnnpack-mutex xnnpack-normalization xnnpack-operators xnnpack-operator-run
984+
xnnpack-operator-utils xnnpack-pack-lh xnnpack-packing xnnpack-fingerprint-cache xnnpack-microkernels-prod
985+
xnnpack-subgraph xnnpack-datatype xnnpack-reference-ukernels)
986+
TARGET_LINK_LIBRARIES(XNNPACK PUBLIC pthreadpool xnnpack-logging xnnpack-fingerprint-check)
980987
SET_TARGET_PROPERTIES(XNNPACK PROPERTIES C_EXTENSIONS YES)
981988
ENDIF()
982989
IF(NOT MSVC)

build_srcs.bzl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ Lists of target-specific sources used to build XNNPACK.
1212
"""
1313

1414
OPERATOR_SRCS = [
15-
"src/operator-delete.c",
1615
"src/operator-run.c",
1716
"src/operators/argmax-pooling-nhwc.c",
1817
"src/operators/average-pooling-nhwc.c",

include/experimental.h

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <stdint.h>
1717

1818
#include "include/xnnpack.h"
19+
#include "src/operators/fingerprint_id.h"
1920

2021
#ifdef __cplusplus
2122
extern "C" {
@@ -98,6 +99,62 @@ enum xnn_status xnn_update_runtime_with_threadpool(
9899
xnn_runtime_t runtime,
99100
xnn_threadpool_t threadpool);
100101

102+
103+
typedef struct xnn_fingerprint* xnn_fingerprint_t;
104+
105+
struct xnn_fingerprint {
106+
enum xnn_fingerprint_id id;
107+
uint32_t value;
108+
};
109+
110+
/// Check whether the given configuration matches one that is currently in use.
111+
///
112+
/// @returns True if the configuration matches.
113+
bool xnn_check_fingerprint(struct xnn_fingerprint fingerprint);
114+
115+
/// Return the fingerprint corresponding to the given id or NULL if it wasn't
116+
/// set.
117+
const struct xnn_fingerprint* xnn_get_fingerprint(enum xnn_fingerprint_id id);
118+
119+
/// Set the given fingerprint.
120+
void xnn_set_fingerprint(struct xnn_fingerprint fingerprint);
121+
122+
/// Clear all fingerprints that were computed until now.
123+
void xnn_clear_fingerprints();
124+
125+
enum xnn_status xnn_fingerprint_fully_connected_nc_f16();
126+
enum xnn_status xnn_fingerprint_fully_connected_nc_f32_f16();
127+
enum xnn_status xnn_fingerprint_fully_connected_nc_bf16_f32();
128+
enum xnn_status xnn_fingerprint_fully_connected_nc_f32();
129+
enum xnn_status xnn_fingerprint_fully_connected_nc_f32_qc4w();
130+
enum xnn_status xnn_fingerprint_fully_connected_nc_f32_qc8w();
131+
enum xnn_status xnn_fingerprint_fully_connected_nc_qd8_f16_qc4w();
132+
enum xnn_status xnn_fingerprint_fully_connected_nc_qd8_f16_qb4w();
133+
enum xnn_status xnn_fingerprint_fully_connected_nc_qd8_f16_qb4w_f16_scales();
134+
enum xnn_status xnn_fingerprint_fully_connected_nc_qd8_f32_qc4w();
135+
enum xnn_status xnn_fingerprint_fully_connected_nc_qd8_f32_qb4w();
136+
enum xnn_status xnn_fingerprint_fully_connected_nc_qd8_f16_qc8w();
137+
enum xnn_status xnn_fingerprint_fully_connected_nc_qd8_f32_qc8w();
138+
enum xnn_status xnn_fingerprint_fully_connected_nc_qs8();
139+
enum xnn_status xnn_fingerprint_fully_connected_nc_qs8_qc4w();
140+
enum xnn_status xnn_fingerprint_fully_connected_nc_qs8_qc8w();
141+
enum xnn_status xnn_fingerprint_fully_connected_nc_qu8();
142+
enum xnn_status xnn_fingerprint_fully_connected_nc_qp8_f32_qc4w();
143+
enum xnn_status xnn_fingerprint_fully_connected_nc_qp8_f32_qc8w();
144+
enum xnn_status xnn_fingerprint_fully_connected_nc_qp8_f32_qb4w();
145+
enum xnn_status xnn_fingerprint_fully_connected_nc_qp8_f32_qb4w_f16_scales();
146+
enum xnn_status xnn_fingerprint_fully_connected_nc_pf32();
147+
enum xnn_status xnn_fingerprint_fully_connected_nc_qdu8_f16_qc8w();
148+
enum xnn_status xnn_fingerprint_fully_connected_nc_qdu8_f32_qc8w();
149+
enum xnn_status xnn_fingerprint_fully_connected_nc_qdu8_f32_qc4w();
150+
enum xnn_status xnn_fingerprint_fully_connected_nc_qdu8_f32_qb4w();
151+
enum xnn_status xnn_fingerprint_fully_connected_nc_qdu8_f16_qc4w();
152+
enum xnn_status xnn_fingerprint_fully_connected_nc_pf16();
153+
enum xnn_status xnn_fingerprint_fully_connected_nc_pqs8_qc8w();
154+
enum xnn_status xnn_fingerprint_fully_connected_nc_qd8_f32_qb4w_f16_scales();
155+
enum xnn_status xnn_fingerprint_fully_connected_nc_qdu8_f32_qb4w_f16_scales();
156+
enum xnn_status xnn_fingerprint_convolution2d_nchw(enum xnn_fingerprint_id fingerprint_id);
157+
101158
#ifdef __cplusplus
102159
} // extern "C"
103160
#endif

include/xnnpack.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Facebook, Inc. and its affiliates.
22
// All rights reserved.
33
//
4-
// Copyright 2019 Google LLC
4+
// Copyright 2019-2025 Google LLC
55
//
66
// This source code is licensed under the BSD-style license found in the
77
// LICENSE file in the root directory of this source tree.
@@ -15,6 +15,7 @@
1515
#include <stddef.h>
1616
#include <stdint.h>
1717

18+
#include "src/operators/fingerprint_id.h"
1819
#include <pthreadpool.h>
1920

2021
#ifdef __cplusplus
@@ -2297,6 +2298,8 @@ struct xnn_weights_cache_look_up_key {
22972298
const void* kernel;
22982299
/// Pointer to the original bias, could be NULL.
22992300
const void* bias;
2301+
2302+
enum xnn_fingerprint_id fingerprint_id;
23002303
};
23012304

23022305
/// A group of function pointers to manage weights cache. All functions may be

0 commit comments

Comments
 (0)