Skip to content

Commit

Permalink
Parameterized API for unary operators
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 678574731
  • Loading branch information
dsharletg authored and xnnpack-bot committed Oct 24, 2024
1 parent 79a0d9c commit 5de58db
Show file tree
Hide file tree
Showing 226 changed files with 6,204 additions and 25,500 deletions.
6 changes: 3 additions & 3 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ xnnpack_cc_library(
":logging",
":math",
":microparams",
":requantization",
":unaligned",
":xnnpack_h",
],
Expand Down Expand Up @@ -973,6 +974,7 @@ xnnpack_cc_library(
":microkernel_utils",
":microkernels_h",
":microparams_init",
":node_type",
":normalization",
":operator_type",
":operator_utils",
Expand All @@ -981,9 +983,7 @@ xnnpack_cc_library(
":quantization",
":xnnpack_h",
"@pthreadpool",
] + select({
"//conditions:default": [],
}),
],
)

xnnpack_cc_library(
Expand Down
103 changes: 9 additions & 94 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,6 @@ SET(OPERATOR_SRCS
src/operators/deconvolution-nhwc.c
src/operators/dynamic-fully-connected-nc.c
src/operators/fully-connected-nc.c
src/operators/lut-elementwise-nc.c
src/operators/max-pooling-nhwc.c
src/operators/pack-lh.c
src/operators/reduce-nd.c
Expand All @@ -443,50 +442,32 @@ SET(SUBGRAPH_SRCS
src/memory-planner.c
src/runtime.c
src/subgraph.c
src/subgraph/abs.c
src/subgraph/argmax-pooling-2d.c
src/subgraph/average-pooling-2d.c
src/subgraph/bankers-rounding.c
src/subgraph/batch-matrix-multiply.c
src/subgraph/binary.c
src/subgraph/ceiling.c
src/subgraph/clamp.c
src/subgraph/concatenate.c
src/subgraph/convert.c
src/subgraph/convolution-2d.c
src/subgraph/copy.c
src/subgraph/deconvolution-2d.c
src/subgraph/deprecated.c
src/subgraph/depth-to-space-2d.c
src/subgraph/depthwise-convolution-2d.c
src/subgraph/elu.c
src/subgraph/even-split.c
src/subgraph/exp.c
src/subgraph/floor.c
src/subgraph/fully-connected-sparse.c
src/subgraph/fully-connected.c
src/subgraph/gelu.c
src/subgraph/hardswish.c
src/subgraph/leaky-relu.c
src/subgraph/log.c
src/subgraph/max-pooling-2d.c
src/subgraph/negate.c
src/subgraph/pack-lh.c
src/subgraph/reciprocal-square-root.c
src/subgraph/reshape-helpers.c
src/subgraph/scaled-dot-product-attention.c
src/subgraph/sigmoid.c
src/subgraph/softmax.c
src/subgraph/space-to-depth-2d.c
src/subgraph/square-root.c
src/subgraph/square.c
src/subgraph/static-constant-pad.c
src/subgraph/static-reduce.c
src/subgraph/static-resize-bilinear-2d.c
src/subgraph/static-slice.c
src/subgraph/static-transpose.c
src/subgraph/tanh.c
src/subgraph/unpooling-2d.c
src/subgraph/unary.c
src/subgraph/validation.c
src/tensor.c)

Expand Down Expand Up @@ -1231,10 +1212,6 @@ IF(XNNPACK_BUILD_TESTS)
ENDIF()
TARGET_LINK_LIBRARIES(gemm-microkernel-tester PUBLIC next-prime)

ADD_LIBRARY(unary-operator-tester STATIC test/unary-operator-tester.cc)
TARGET_INCLUDE_DIRECTORIES(unary-operator-tester PRIVATE include src test)
TARGET_LINK_LIBRARIES(unary-operator-tester PRIVATE XNNPACK pthreadpool GTest::gtest)

ADD_LIBRARY(dwconv-microkernel-tester STATIC test/dwconv-microkernel-tester.cc)
TARGET_INCLUDE_DIRECTORIES(dwconv-microkernel-tester PRIVATE include src test)
TARGET_LINK_LIBRARIES(dwconv-microkernel-tester PRIVATE XNNPACK pthreadpool GTest::gtest)
Expand All @@ -1245,15 +1222,6 @@ IF(XNNPACK_BUILD_TESTS)
TARGET_INCLUDE_DIRECTORIES(vbinary-microkernel-tester PRIVATE include src test)
TARGET_LINK_LIBRARIES(vbinary-microkernel-tester PRIVATE XNNPACK pthreadpool GTest::gtest)

ADD_LIBRARY(vcvt-microkernel-tester STATIC test/vcvt-microkernel-tester.cc)
TARGET_INCLUDE_DIRECTORIES(vcvt-microkernel-tester PRIVATE include src test)
TARGET_LINK_LIBRARIES(vcvt-microkernel-tester PRIVATE XNNPACK pthreadpool GTest::gtest)

ADD_LIBRARY(vunary-microkernel-tester STATIC test/vunary-microkernel-tester.cc)
TARGET_INCLUDE_DIRECTORIES(vunary-microkernel-tester PRIVATE include src test)
TARGET_LINK_LIBRARIES(vunary-microkernel-tester PRIVATE XNNPACK pthreadpool GTest::gtest)
TARGET_LINK_LIBRARIES(vunary-microkernel-tester PUBLIC next-prime)

ADD_LIBRARY(convolution-test-helpers OBJECT test/convolution-test-helpers.cc)
TARGET_INCLUDE_DIRECTORIES(convolution-test-helpers PRIVATE include src)
TARGET_LINK_LIBRARIES(convolution-test-helpers PRIVATE xnnpack-base)
Expand Down Expand Up @@ -1288,7 +1256,6 @@ IF(XNNPACK_BUILD_TESTS)
microparams-init
next-prime
pthreadpool
vunary-microkernel-tester
XNNPACK)
ADD_SHARDED_TEST(${TEST}-test 10)
ENDFOREACH()
Expand Down Expand Up @@ -1318,34 +1285,13 @@ IF(XNNPACK_BUILD_TESTS)
TARGET_LINK_LIBRARIES(subgraph-size-test PRIVATE XNNPACK)

# ---[ Build operator-level unit tests
SET(LIBRARY_UNARY_UNIT_TESTS
abs-nc
bankers-rounding-nc
ceiling-nc
clamp-nc
elu-nc
exp-nc
floor-nc
hardswish-nc
leaky-relu-nc
log-nc
negate-nc
reciprocal-square-root-nc
sigmoid-nc
square-nc
square-root-nc
tanh-nc
truncation-nc)
FOREACH(TEST ${LIBRARY_UNARY_UNIT_TESTS})
ADD_EXECUTABLE(${TEST}-test test/${TEST}.cc)
TARGET_INCLUDE_DIRECTORIES(${TEST}-test PRIVATE src test)
TARGET_LINK_LIBRARIES(${TEST}-test PRIVATE
GTest::gtest
GTest::gtest_main
unary-operator-tester
XNNPACK)
ADD_TEST(NAME ${TEST}-test COMMAND ${TEST}-test)
ENDFOREACH()
ADD_EXECUTABLE(unary-elementwise-nc-test test/unary-elementwise-nc.cc)
TARGET_INCLUDE_DIRECTORIES(unary-elementwise-nc-test PRIVATE src test)
TARGET_LINK_LIBRARIES(unary-elementwise-nc-test PRIVATE
GTest::gtest
GTest::gtest_main
XNNPACK)
ADD_TEST(NAME unary-elementwise-nc-test COMMAND unary-elementwise-nc-test)

ADD_EXECUTABLE(binary-elementwise-nd-test test/binary-elementwise-nd.cc)
TARGET_INCLUDE_DIRECTORIES(binary-elementwise-nd-test PRIVATE src test)
Expand Down Expand Up @@ -1376,53 +1322,35 @@ IF(XNNPACK_BUILD_TESTS)

# ---[ Build subgraph-level unit tests
SET(LIBRARY_SUBGRAPH_UNIT_TESTS
abs
abs-reshape
argmax-pooling-2d
average-pooling-2d
average-pooling-2d-reshape
bankers-rounding
binary
ceiling
clamp
concatenate2
concatenate3
concatenate4
concatenate5
convert
copy
depth-to-space-2d
elu
gelu
exp
even-split2
even-split3
even-split4
floor
global-average-pooling-1d
global-average-pooling-2d
global-sum-pooling-1d
global-sum-pooling-2d
hardswish
leaky-relu
log
max-pooling-2d
negate
reciprocal-square-root
reshape-helpers
sigmoid
static-slice
softmax
space-to-depth-2d
square
square-root
static-constant-pad
static-reduce
static-reshape
static-resize-bilinear-2d
static-transpose
tanh
transpose-reshape
unary
unpooling-2d)
FOREACH(TEST ${LIBRARY_SUBGRAPH_UNIT_TESTS})
ADD_EXECUTABLE(${TEST}-test test/${TEST}.cc)
Expand Down Expand Up @@ -1747,7 +1675,6 @@ IF(XNNPACK_BUILD_TESTS)
ADD_EXECUTABLE(${TEST}-test test/${TEST}.cc)
TARGET_INCLUDE_DIRECTORIES(${TEST}-test PRIVATE include src test)
TARGET_LINK_LIBRARIES(${TEST}-test PRIVATE
vcvt-microkernel-tester
GTest::gmock
GTest::gtest
GTest::gtest_main
Expand Down Expand Up @@ -1800,7 +1727,6 @@ IF(XNNPACK_BUILD_TESTS)
ADD_EXECUTABLE(${TEST}-test test/${TEST}.cc)
TARGET_INCLUDE_DIRECTORIES(${TEST}-test PRIVATE include src test)
TARGET_LINK_LIBRARIES(${TEST}-test PRIVATE
vunary-microkernel-tester
GTest::gmock
GTest::gtest
GTest::gtest_main
Expand Down Expand Up @@ -1945,7 +1871,6 @@ IF(XNNPACK_BUILD_BENCHMARKS)
softmax
square
square-root
truncation
tanh)
FOREACH(BENCH ${LIBRARY_OPERATOR_BENCHMARKS})
ADD_EXECUTABLE(${BENCH}-bench bench/${BENCH}.cc)
Expand All @@ -1963,7 +1888,6 @@ IF(XNNPACK_BUILD_BENCHMARKS)
f16-conv-hwc2chw
f16-dwconv
f16-dwconv2d-chw
f16-f32-vcvt
f16-f32acc-gemm
f16-f32acc-igemm
f16-f32acc-rdsum
Expand All @@ -1982,16 +1906,13 @@ IF(XNNPACK_BUILD_BENCHMARKS)
f32-conv-hwc2chw
f32-dwconv
f32-dwconv2d-chw
f32-f16-vcvt
f32-gemm
f32-gemm-goi-minmax
f32-gemm-minmax
f32-igemm
f32-im2col-gemm
f32-qc4w-gemm
f32-qc8w-gemm
f32-qs8-vcvt
f32-qu8-vcvt
f32-raddexpminusmax
f32-raddextexp
f32-raddstoreexpminusmax
Expand All @@ -2014,21 +1935,15 @@ IF(XNNPACK_BUILD_BENCHMARKS)
qd8-f32-qc8w-gemm
qp8-f32-qc4w-gemm
qp8-f32-qb4w-gemm
qs16-qs8-vcvt
qs8-dwconv
qs8-f16-vcvt
qs8-f32-vcvt
qs8-gemm
qs8-qc8w-gemm-fp32
qu8-rdsum
qs8-rsum
qu8-rsum
qs8-vcvt
qu8-f32-vcvt
qu8-gemm
qu8-gemm-fp32
qu8-gemm-rndnu
qu8-vcvt
x16-packw
x32-packw
x8-lut
Expand Down
24 changes: 0 additions & 24 deletions bench/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -228,29 +228,6 @@ xnnpack_benchmark(
]),
)

[xnnpack_benchmark(
name = "%s_bench" % kernel,
srcs = [
"%s.cc" % kernel.replace("_", "-"),
"vcvt-benchmark.h",
],
deps = MICROKERNEL_BENCHMARK_DEPS,
) for kernel in [
"qs8_f16_vcvt",
"qs8_f32_vcvt",
"qs8_vcvt",
"qs16_qs8_vcvt",
"qu8_f32_vcvt",
"qu8_vcvt",
"f16_f32_vcvt",
"f16_qs8_vcvt",
"f32_f16_vcvt",
"f32_qs8_vcvt",
"f32_qu8_vcvt",
"s32_f32_vcvt",
"u32_f32_vcvt",
]]

[xnnpack_benchmark(
name = "%s_bench" % kernel,
srcs = [
Expand Down Expand Up @@ -590,7 +567,6 @@ xnnpack_benchmark(
"square",
"square_root",
"tanh",
"truncation",
]]

xnnpack_benchmark(
Expand Down
8 changes: 2 additions & 6 deletions bench/abs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,11 @@


static void xnnpack_abs_f16(benchmark::State& state) {
benchmark_unary_operator<xnn_float16, xnn_float16>(
xnn_create_abs_nc_f16, xnn_reshape_abs_nc_f16, xnn_setup_abs_nc_f16,
state);
benchmark_unary_operator<xnn_float16, xnn_float16>(state, xnn_unary_abs);
}

static void xnnpack_abs_f32(benchmark::State& state) {
benchmark_unary_operator<float, float>(xnn_create_abs_nc_f32,
xnn_reshape_abs_nc_f32,
xnn_setup_abs_nc_f32, state);
benchmark_unary_operator<float, float>(state, xnn_unary_abs);
}

BENCHMARK(xnnpack_abs_f16)
Expand Down
6 changes: 2 additions & 4 deletions bench/bankers-rounding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@

static void xnnpack_bankers_rounding_f16(benchmark::State& state) {
benchmark_unary_operator<xnn_float16, xnn_float16>(
xnn_create_bankers_rounding_nc_f16, xnn_reshape_bankers_rounding_nc_f16,
xnn_setup_bankers_rounding_nc_f16, state);
state, xnn_unary_bankers_rounding);
}

static void xnnpack_bankers_rounding_f32(benchmark::State& state) {
benchmark_unary_operator<float, float>(
xnn_create_bankers_rounding_nc_f32, xnn_reshape_bankers_rounding_nc_f32,
xnn_setup_bankers_rounding_nc_f32, state);
state, xnn_unary_bankers_rounding);
}

BENCHMARK(xnnpack_bankers_rounding_f16)
Expand Down
8 changes: 2 additions & 6 deletions bench/ceiling.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,11 @@


static void xnnpack_ceiling_f16(benchmark::State& state) {
benchmark_unary_operator<xnn_float16, xnn_float16>(xnn_create_ceiling_nc_f16,
xnn_reshape_ceiling_nc_f16,
xnn_setup_ceiling_nc_f16, state);
benchmark_unary_operator<xnn_float16, xnn_float16>(state, xnn_unary_ceiling);
}

static void xnnpack_ceiling_f32(benchmark::State& state) {
benchmark_unary_operator<float, float>(xnn_create_ceiling_nc_f32,
xnn_reshape_ceiling_nc_f32,
xnn_setup_ceiling_nc_f32, state);
benchmark_unary_operator<float, float>(state, xnn_unary_ceiling);
}

BENCHMARK(xnnpack_ceiling_f16)
Expand Down
Loading

0 comments on commit 5de58db

Please sign in to comment.