Skip to content

Commit

Permalink
Add partial support for building/testing/benchmarking XNNPACK on Hexa…
Browse files Browse the repository at this point in the history
…gon. Additional work would need to be done to get this fully working in the Bazel build (notably, connecting to a Qualcomm SDK) but this extends the basic build rules enough to add specializations for Hexagon to XNNPACK.

PiperOrigin-RevId: 633701620
  • Loading branch information
xnnpack-bot committed May 15, 2024
1 parent 8d5f4e0 commit 0ffe3d9
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 19 deletions.
16 changes: 15 additions & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ xnnpack_cc_library(
":logging",
":microkernels_h",
":microparams_init",
":packing",
":packing_test_mode", # TODO
":test_microkernels",
] + select({
":cpuinfo_enabled": ["@cpuinfo"],
Expand Down Expand Up @@ -2937,6 +2937,17 @@ xnnpack_cc_library(
wasmsimd_srcs = WASM32_ASM_MICROKERNEL_SRCS,
)

xnnpack_cc_library(
name = "hvx_microkernels",
gcc_copts = xnnpack_gcc_std_copts(),
hvx_srcs = ALL_HEXAGON_MICROKERNEL_SRCS,
msvc_copts = xnnpack_msvc_std_copts(),
deps = [
":common",
":microkernels_h",
],
)

xnnpack_cc_library(
name = "log_level_default",
defines = select({
Expand Down Expand Up @@ -3087,6 +3098,7 @@ xnnpack_aggregate_library(
":avxvnni_enabled": [":avxvnni_bench_microkernels"],
"//conditions:default": [],
}),
hvx_deps = [":hvx_microkernels"],
wasm_deps = [
":wasm_bench_microkernels",
":asm_microkernels",
Expand Down Expand Up @@ -3195,6 +3207,7 @@ xnnpack_aggregate_library(
":avx512fp16_enabled": [":avx512fp16_prod_microkernels"],
"//conditions:default": [],
}),
hvx_deps = [":hvx_microkernels"],
wasm_deps = [
":wasm_prod_microkernels",
":asm_microkernels",
Expand Down Expand Up @@ -3310,6 +3323,7 @@ xnnpack_aggregate_library(
":avx512fp16_enabled": [":avx512fp16_test_microkernels"],
"//conditions:default": [],
}),
hvx_deps = [":hvx_microkernels"],
wasm_deps = [
":wasm_test_microkernels",
":asm_microkernels",
Expand Down
10 changes: 10 additions & 0 deletions build_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def xnnpack_std_cxxopts():
"""Compiler flags to specify language standard for C++ sources."""
return ["-std=gnu++14"]

def xnnpack_gunit_deps_for_library():
"""Depencies needed for a library to use gunit."""
return ["@com_google_googletest//:gtest_main"]

def xnnpack_optional_ruy_copts():
"""Compiler flags to optionally enable Ruy benchmarks."""
return []
Expand Down Expand Up @@ -73,6 +77,7 @@ def xnnpack_cc_library(
x86_srcs = [],
aarch32_srcs = [],
aarch64_srcs = [],
hvx_srcs = [],
riscv_srcs = [],
wasm_srcs = [],
wasmsimd_srcs = [],
Expand All @@ -88,6 +93,7 @@ def xnnpack_cc_library(
msvc_x86_64_copts = [],
aarch32_copts = [],
aarch64_copts = [],
hvx_copts = [],
riscv_copts = [],
wasm_copts = [],
wasmsimd_copts = [],
Expand All @@ -110,6 +116,7 @@ def xnnpack_cc_library(
x86_srcs: The list of x86-specific source files.
aarch32_srcs: The list of AArch32-specific source files.
aarch64_srcs: The list of AArch64-specific source files.
hvx_srcs: The list of HVX-specific source files.
riscv_srcs: The list of RISC-V-specific source files.
wasm_srcs: The list of WebAssembly 1.0-specific source files.
wasmsimd_srcs: The list of WebAssembly SIMD-specific source files.
Expand All @@ -131,6 +138,7 @@ def xnnpack_cc_library(
builds.
aarch32_copts: The list of compiler flags to use in AArch32 builds.
aarch64_copts: The list of compiler flags to use in AArch64 builds.
hvx_copts: The list of compiler flags to use in HVX builds.
riscv_copts: The list of compiler flags to use in RISC-V builds.
wasm_copts: The list of compiler flags to use in WebAssembly 1.0 builds.
wasmsimd_copts: The list of compiler flags to use in WebAssembly SIMD
Expand Down Expand Up @@ -226,6 +234,7 @@ def xnnpack_aggregate_library(
x86_deps = [],
aarch32_deps = [],
aarch64_deps = [],
hvx_deps = [],
riscv_deps = [],
wasm_deps = [],
wasmsimd_deps = [],
Expand All @@ -240,6 +249,7 @@ def xnnpack_aggregate_library(
x86_deps: The list of libraries to link in x86 and x86-64 builds.
aarch32_deps: The list of libraries to link in AArch32 builds.
aarch64_deps: The list of libraries to link in AArch64 builds.
hvx_deps: The list of libraries to link in HVX builds.
riscv_deps: The list of libraries to link in RISC-V builds.
wasm_deps: The list of libraries to link in WebAssembly 1.0 builds.
wasmsimd_deps: The list of libraries to link in WebAssembly SIMD builds.
Expand Down
4 changes: 2 additions & 2 deletions eval/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ load(
"//:build_defs.bzl",
"xnnpack_benchmark",
"xnnpack_cc_library",
"xnnpack_gunit_deps_for_library",
"xnnpack_unit_test",
)

Expand Down Expand Up @@ -226,14 +227,13 @@ xnnpack_cc_library(
testonly = True,
srcs = ["math-evaluation-tester.cc"],
hdrs = ["math-evaluation-tester.h"],
deps = [
deps = xnnpack_gunit_deps_for_library() + [
"@FP16",
"//:aligned_allocator",
"//:common",
"//:math",
"//:math_stubs",
"@pthreadpool",
"@com_google_googletest//:gtest_main",
],
)

Expand Down
29 changes: 13 additions & 16 deletions test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ load(
"//:build_defs.bzl",
"xnnpack_binary",
"xnnpack_cc_library",
"xnnpack_gunit_deps_for_library",
"xnnpack_unit_test",
)

Expand Down Expand Up @@ -54,9 +55,8 @@ xnnpack_cc_library(
name = "replicable_random_device",
testonly = True,
hdrs = ["replicable_random_device.h"],
deps = [
deps = xnnpack_gunit_deps_for_library() + [
"//:xnnpack_h",
"@com_google_googletest//:gtest_main",
],
)

Expand All @@ -65,12 +65,11 @@ xnnpack_cc_library(
testonly = True,
srcs = ["gemm-microkernel-tester.cc"],
hdrs = ["gemm-microkernel-tester.h"],
deps = MICROKERNEL_TEST_DEPS + [
deps = MICROKERNEL_TEST_DEPS + xnnpack_gunit_deps_for_library() + [
"//:XNNPACK_test_mode",
"//:jit",
"//:packing_test_mode",
"//:post_operation",
"@com_google_googletest//:gtest_main",
],
)

Expand All @@ -79,50 +78,49 @@ xnnpack_cc_library(
testonly = True,
srcs = ["unary-operator-tester.cc"],
hdrs = ["unary-operator-tester.h"],
deps = OPERATOR_TEST_DEPS + ["@com_google_googletest//:gtest_main"],
deps = OPERATOR_TEST_DEPS + xnnpack_gunit_deps_for_library(),
)

xnnpack_cc_library(
name = "binary_elementwise_operator_tester",
testonly = True,
srcs = ["binary-elementwise-operator-tester.cc"],
hdrs = ["binary-elementwise-operator-tester.h"],
deps = OPERATOR_TEST_DEPS + ["@com_google_googletest//:gtest_main"],
deps = OPERATOR_TEST_DEPS + xnnpack_gunit_deps_for_library(),
)

xnnpack_cc_library(
name = "vunary_microkernel_tester",
testonly = True,
srcs = ["vunary-microkernel-tester.cc"],
hdrs = ["vunary-microkernel-tester.h"],
deps = MICROKERNEL_TEST_DEPS + ["@com_google_googletest//:gtest_main"],
deps = MICROKERNEL_TEST_DEPS + xnnpack_gunit_deps_for_library(),
)

xnnpack_cc_library(
name = "vbinary_microkernel_tester",
testonly = True,
srcs = ["vbinary-microkernel-tester.cc"],
hdrs = ["vbinary-microkernel-tester.h"],
deps = MICROKERNEL_TEST_DEPS + ["@com_google_googletest//:gtest_main"],
deps = MICROKERNEL_TEST_DEPS + xnnpack_gunit_deps_for_library(),
)

xnnpack_cc_library(
name = "vbinaryc_microkernel_tester",
testonly = True,
srcs = ["vbinaryc-microkernel-tester.cc"],
hdrs = ["vbinaryc-microkernel-tester.h"],
deps = MICROKERNEL_TEST_DEPS + ["@com_google_googletest//:gtest_main"],
deps = MICROKERNEL_TEST_DEPS + xnnpack_gunit_deps_for_library(),
)

xnnpack_cc_library(
name = "dwconv_microkernel_tester",
testonly = True,
srcs = ["dwconv-microkernel-tester.cc"],
hdrs = ["dwconv-microkernel-tester.h"],
deps = MICROKERNEL_TEST_DEPS + [
deps = MICROKERNEL_TEST_DEPS + xnnpack_gunit_deps_for_library() + [
"//:microkernel_utils",
"//:packing_test_mode",
"@com_google_googletest//:gtest_main",
],
)

Expand All @@ -131,7 +129,7 @@ xnnpack_cc_library(
testonly = True,
srcs = ["vcvt-microkernel-tester.cc"],
hdrs = ["vcvt-microkernel-tester.h"],
deps = MICROKERNEL_TEST_DEPS + ["@com_google_googletest//:gtest_main"],
deps = MICROKERNEL_TEST_DEPS + xnnpack_gunit_deps_for_library(),
)

######################### Unit tests for micro-kernels #########################
Expand Down Expand Up @@ -3113,6 +3111,7 @@ xnnpack_cc_library(
"convolution-test-helpers.h",
],
deps = [
"//:microparams",
"//:quantization",
],
)
Expand All @@ -3123,14 +3122,13 @@ xnnpack_cc_library(
hdrs = [
"subgraph-unary-tester.h",
],
deps = [
deps = xnnpack_gunit_deps_for_library() + [
":replicable_random_device",
"//:node_type",
"//:operators_test_mode",
"//:requantization",
"//:subgraph_test_mode",
"//:xnnpack_h",
"@com_google_googletest//:gtest_main",
],
)

Expand All @@ -3140,14 +3138,13 @@ xnnpack_cc_library(
hdrs = [
"subgraph-binary-tester.h",
],
deps = [
deps = xnnpack_gunit_deps_for_library() + [
":replicable_random_device",
"//:node_type",
"//:operators_test_mode",
"//:requantization",
"//:subgraph_test_mode",
"//:xnnpack_h",
"@com_google_googletest//:gtest_main",
],
)

Expand Down

0 comments on commit 0ffe3d9

Please sign in to comment.