This repository has been archived on 2023-11-05. You can view files and clone it, but cannot push or open issues or pull requests.
wasm-micro-runtime/samples/workload/XNNPACK/xnnpack.patch
2021-12-29 22:08:40 +08:00

113 lines
3.5 KiB
Diff

diff --git a/.bazelrc b/.bazelrc
index ec740f38..29f9d56e 100644
--- a/.bazelrc
+++ b/.bazelrc
@@ -49,4 +49,9 @@ build:ios_fat --watchos_cpus=armv7k
build:macos --apple_platform_type=macos
build:macos_arm64 --config=macos
-build:macos_arm64 --cpu=darwin_arm64
\ No newline at end of file
+build:macos_arm64 --cpu=darwin_arm64
+
+build:wasm --cpu=wasm
+build:wasm --copt=-msimd128
+build:wasm --crosstool_top=@emsdk//emscripten_toolchain:everything
+build:wasm --host_crosstool_top=@bazel_tools//tools/cpp:toolchain
diff --git a/BUILD.bazel b/BUILD.bazel
index 3fc8139f..c893356d 100644
--- a/BUILD.bazel
+++ b/BUILD.bazel
@@ -11988,7 +11988,6 @@ config_setting(
values = {
"crosstool_top": "@emsdk//emscripten_toolchain:everything",
"cpu": "wasm",
- "copt": "-msimd128",
"copt": "-mrelaxed-simd",
},
)
diff --git a/WORKSPACE b/WORKSPACE
index c58e76b6..30934678 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -21,6 +21,7 @@ http_archive(
name = "com_google_benchmark",
strip_prefix = "benchmark-master",
urls = ["https://github.com/google/benchmark/archive/master.zip"],
+ patches = ["@//third_party:benchmark.patch"],
)
# FP16 library, used for half-precision conversions
@@ -84,6 +85,19 @@ http_archive(
],
)
+http_archive(
+ name = "emsdk",
+ strip_prefix = "emsdk-2.0.26/bazel",
+ url = "https://github.com/emscripten-core/emsdk/archive/refs/tags/2.0.26.tar.gz",
+ sha256 = "79e7166aa8eaae6e52cef1363b2d8db795d03684846066bc51f9dcf905dd58ad",
+)
+
+load("@emsdk//:deps.bzl", emsdk_deps = "deps")
+emsdk_deps()
+
+load("@emsdk//:emscripten_deps.bzl", emsdk_emscripten_deps = "emscripten_deps")
+emsdk_emscripten_deps()
+
# Android NDK location and version is auto-detected from $ANDROID_NDK_HOME environment variable
android_ndk_repository(name = "androidndk")
diff --git a/build_defs.bzl b/build_defs.bzl
index fbadb400..e496b78d 100644
--- a/build_defs.bzl
+++ b/build_defs.bzl
@@ -430,7 +430,7 @@ def xnnpack_benchmark(name, srcs, copts = [], deps = [], tags = []):
explicitly specified.
"""
native.cc_binary(
- name = name,
+ name = name + ".wasm",
srcs = srcs,
copts = xnnpack_std_cxxopts() + [
"-Iinclude",
diff --git a/emscripten.bzl b/emscripten.bzl
index 130d5f16..2696ad54 100644
--- a/emscripten.bzl
+++ b/emscripten.bzl
@@ -25,12 +25,19 @@ def xnnpack_emscripten_benchmark_linkopts():
"""Emscripten-specific linkopts for benchmarks."""
return [
"-s ASSERTIONS=1",
- "-s ENVIRONMENT=node,shell,web",
- "-s ERROR_ON_UNDEFINED_SYMBOLS=1",
- "-s EXIT_RUNTIME=1",
+ "-s ERROR_ON_UNDEFINED_SYMBOLS=0",
"-s ALLOW_MEMORY_GROWTH=1",
"-s TOTAL_MEMORY=445644800", # 425M
- "--pre-js $(location :preamble.js.lds)",
+ "-s USE_PTHREADS=0",
+ "-s STANDALONE_WASM=1",
+ "-Wno-unused",
+ "-Wno-unused-variable",
+ "-Wno-unused-command-line-argument",
+ "-Wl,--export=__heap_base",
+ "-Wl,--export=__data_end",
+ "-Wl,--export=malloc",
+ "-Wl,--export=free",
+ "--oformat=wasm",
]
def xnnpack_emscripten_deps():
diff --git a/third_party/cpuinfo.BUILD b/third_party/cpuinfo.BUILD
index 128d683e..f6c287c4 100644
--- a/third_party/cpuinfo.BUILD
+++ b/third_party/cpuinfo.BUILD
@@ -343,5 +343,5 @@ config_setting(
config_setting(
name = "emscripten",
- values = {"crosstool_top": "//toolchain:emscripten"},
+ values = {"crosstool_top": "@emsdk//emscripten_toolchain:everything"},
)