Skip to content

Commit

Permalink
Copybara import of the project:
Browse files Browse the repository at this point in the history
--
b712736 by Ilya Rezvov <[email protected]>:

Add Emscripten support for Bazel benchmark builds

--
f219724 by Ilya Rezvov <[email protected]>:

add wasm build config to .bazelrc

FUTURE_COPYBARA_INTEGRATE_REVIEW=#7242 from SPY:emscripten-wasm f219724
PiperOrigin-RevId: 684061398
  • Loading branch information
Ilya Rezvov authored and xnnpack-bot committed Oct 12, 2024
1 parent 71c5d13 commit 12af1a0
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ build:macos_arm64 --cpu=darwin_arm64
# Disable Bzlmod for every Bazel command
common --enable_bzlmod=false

# wasm configs.
build:wasm --enable_bzlmod=true
build:wasm --features=wasm_relaxed_simd

# Disable some warnings to allow a warning-free build
build --cxxopt='-Wno-sign-compare'
build --cxxopt='-Wno-comment'
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ out/
*.pyc
*.pyo
*.log
MODULE.bazel.lock

# System files
.DS_Store
Expand Down
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bazel_dep(name = "platforms", version = "0.0.9")
17 changes: 17 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,20 @@ http_archive(
"https://github.com/google/ruy/archive/9f53ba413e6fc879236dcaa3e008915973d67a4f.zip",
],
)

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
git_repository(
name = "emsdk",
remote = "https://github.com/emscripten-core/emsdk.git",
tag = "3.1.68",
strip_prefix = "bazel",
)

load("@emsdk//:deps.bzl", emsdk_deps = "deps")
emsdk_deps()

load("@emsdk//:emscripten_deps.bzl", emsdk_emscripten_deps = "emscripten_deps")
emsdk_emscripten_deps(emscripten_version = "3.1.68")

load("@emsdk//:toolchains.bzl", "register_emscripten_toolchains")
register_emscripten_toolchains()
6 changes: 6 additions & 0 deletions bench/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,12 @@ xnnpack_cxx_library(
srcs = [
"%s.cc" % kernel.replace("_", "-"),
],
copts = select({
"//build_config:emscripten": ["-mfp16"],
"//conditions:default": [],
}),
tags = xnnpack_slow_benchmark_tags(),
wasm = True,
deps = MICROKERNEL_BENCHMARK_DEPS + [
":gemm_benchmark",
"//:allocator",
Expand Down Expand Up @@ -148,6 +153,7 @@ xnnpack_cxx_library(
],
copts = xnnpack_optional_ruy_copts() + xnnpack_optional_gemmlowp_copts(),
tags = xnnpack_slow_benchmark_tags(),
wasm = True,
deps = MICROKERNEL_BENCHMARK_DEPS + [
":gemm_benchmark",
"//:allocator",
Expand Down
13 changes: 12 additions & 1 deletion build_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

load("//:emscripten.bzl", "xnnpack_emscripten_benchmark_linkopts", "xnnpack_emscripten_deps", "xnnpack_emscripten_minimal_linkopts", "xnnpack_emscripten_test_linkopts")

load("@emsdk//emscripten_toolchain:wasm_rules.bzl", "wasm_cc_binary")

def xnnpack_visibility():
"""Visibility of :XNNPACK target.
Expand Down Expand Up @@ -376,7 +378,7 @@ def xnnpack_binary(name, srcs, copts = [], deps = [], linkopts = []):
deps = deps,
)

def xnnpack_benchmark(name, srcs, copts = [], deps = [], tags = [], defines = []):
def xnnpack_benchmark(name, srcs, copts = [], deps = [], tags = [], defines = [], wasm = False):
"""Microbenchmark binary based on Google Benchmark
Args:
Expand Down Expand Up @@ -421,6 +423,15 @@ def xnnpack_benchmark(name, srcs, copts = [], deps = [], tags = [], defines = []
defines = defines,
args = ["--benchmark_min_time=1x"],
)
if wasm:
wasm_cc_binary(
name = "%s_wasm" % name,
cc_target = ":%s" % name,
simd = True,
threads = "emscripten",
exit_runtime = True,
testonly = True
)

SrcListInfo = provider("A list of source files.", fields = {"srcs": "sources"})

Expand Down

0 comments on commit 12af1a0

Please sign in to comment.