xnnpack.patch 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. diff --git a/.bazelrc b/.bazelrc
  2. index ec740f38..2c193244 100644
  3. --- a/.bazelrc
  4. +++ b/.bazelrc
  5. @@ -49,4 +49,10 @@ build:ios_fat --watchos_cpus=armv7k
  6. build:macos --apple_platform_type=macos
  7. build:macos_arm64 --config=macos
  8. -build:macos_arm64 --cpu=darwin_arm64
  9. \ No newline at end of file
  10. +build:macos_arm64 --cpu=darwin_arm64
  11. +
  12. +build:wasm --copt=-msimd128
  13. +build:wasm --cpu=wasm
  14. +build:wasm --crosstool_top=@emsdk//emscripten_toolchain:everything
  15. +build:wasm --host_crosstool_top=@bazel_tools//tools/cpp:toolchain
  16. +
  17. diff --git a/BUILD.bazel b/BUILD.bazel
  18. index ae4108bc..1c11fac2 100644
  19. --- a/BUILD.bazel
  20. +++ b/BUILD.bazel
  21. @@ -5038,7 +5038,6 @@ xnnpack_benchmark(
  22. srcs = [
  23. "bench/f16-igemm.cc",
  24. "bench/conv.h",
  25. - "bench/google/conv.h",
  26. "src/xnnpack/AlignedAllocator.h",
  27. ] + MICROKERNEL_BENCHMARK_HDRS,
  28. deps = MICROKERNEL_BENCHMARK_DEPS + [
  29. @@ -5120,7 +5119,6 @@ xnnpack_benchmark(
  30. srcs = [
  31. "bench/f16-dwconv.cc",
  32. "bench/dwconv.h",
  33. - "bench/google/dwconv.h",
  34. "src/xnnpack/AlignedAllocator.h",
  35. ] + MICROKERNEL_BENCHMARK_HDRS,
  36. deps = MICROKERNEL_BENCHMARK_DEPS + [
  37. diff --git a/WORKSPACE b/WORKSPACE
  38. index 4fa1aa2f..86040d42 100644
  39. --- a/WORKSPACE
  40. +++ b/WORKSPACE
  41. @@ -89,3 +89,18 @@ android_ndk_repository(name = "androidndk")
  42. # Android SDK location and API is auto-detected from $ANDROID_HOME environment variable
  43. android_sdk_repository(name = "androidsdk")
  44. +
  45. +# emscripten library
  46. +http_archive(
  47. + name = "emsdk",
  48. + strip_prefix = "emsdk-c1589b55641787d55d53e883852035beea9aec3f/bazel",
  49. + url = "https://github.com/emscripten-core/emsdk/archive/c1589b55641787d55d53e883852035beea9aec3f.tar.gz",
  50. + sha256 = "7a58a9996b113d3e0675df30b5f17e28aa47de2e684a844f05394fe2f6f12e8e",
  51. +)
  52. +
  53. +load("@emsdk//:deps.bzl", emsdk_deps = "deps")
  54. +emsdk_deps()
  55. +
  56. +load("@emsdk//:emscripten_deps.bzl", emsdk_emscripten_deps = "emscripten_deps")
  57. +emsdk_emscripten_deps()
  58. +
  59. diff --git a/build_defs.bzl b/build_defs.bzl
  60. index 10345032..0e926fca 100644
  61. --- a/build_defs.bzl
  62. +++ b/build_defs.bzl
  63. @@ -1,6 +1,6 @@
  64. """Build definitions and rules for XNNPACK."""
  65. -load(":emscripten.bzl", "xnnpack_emscripten_benchmark_linkopts", "xnnpack_emscripten_deps", "xnnpack_emscripten_minimal_linkopts", "xnnpack_emscripten_test_linkopts")
  66. +load(":emscripten.bzl", "xnnpack_emscripten_benchmark_linkopts", "xnnpack_emscripten_deps", "xnnpack_emscripten_minimal_linkopts", "xnnpack_emscripten_test_linkopts", "xnnpack_emscripten_benchmark_copts")
  67. def xnnpack_visibility():
  68. """Visibility of :XNNPACK target.
  69. @@ -424,10 +424,15 @@ def xnnpack_benchmark(name, srcs, copts = [], deps = [], tags = []):
  70. ":windows_x86_64_mingw": ["-Wno-unused-function"],
  71. ":windows_x86_64_msys": ["-Wno-unused-function"],
  72. ":windows_x86_64": [],
  73. + ":emscripten": xnnpack_emscripten_benchmark_copts(),
  74. + ":emscripten_wasm": xnnpack_emscripten_benchmark_copts(),
  75. + ":emscripten_wasmsimd": xnnpack_emscripten_benchmark_copts(),
  76. "//conditions:default": ["-Wno-unused-function"],
  77. }) + copts,
  78. linkopts = select({
  79. ":emscripten": xnnpack_emscripten_benchmark_linkopts(),
  80. + ":emscripten_wasm": xnnpack_emscripten_benchmark_linkopts(),
  81. + ":emscripten_wasmsimd": xnnpack_emscripten_benchmark_linkopts(),
  82. ":windows_x86_64_mingw": ["-lshlwapi"],
  83. ":windows_x86_64_msys": ["-lshlwapi"],
  84. "//conditions:default": [],
  85. diff --git a/emscripten.bzl b/emscripten.bzl
  86. index 0a0caedf..d28afa30 100644
  87. --- a/emscripten.bzl
  88. +++ b/emscripten.bzl
  89. @@ -23,15 +23,28 @@ def xnnpack_emscripten_benchmark_linkopts():
  90. """Emscripten-specific linkopts for benchmarks."""
  91. return [
  92. "-s ASSERTIONS=1",
  93. - "-s ERROR_ON_UNDEFINED_SYMBOLS=1",
  94. - "-s EXIT_RUNTIME=1",
  95. - "-s ALLOW_MEMORY_GROWTH=1",
  96. + "-s ERROR_ON_UNDEFINED_SYMBOLS=0",
  97. + "-s ALLOW_MEMORY_GROWTH=0",
  98. "-s TOTAL_MEMORY=436207616", # 416M
  99. - "--pre-js $(location :preamble.js.lds)",
  100. + "-s USE_PTHREADS=0",
  101. + "-s STANDALONE_WASM=1",
  102. + "-Wno-unused",
  103. + "-Wl,--export=__heap_base",
  104. + "-Wl,--export=__data_end",
  105. + "-Wl,--export=malloc",
  106. + "-Wl,--export=free",
  107. ]
  108. def xnnpack_emscripten_deps():
  109. """Emscripten-specific dependencies for unit tests and benchmarks."""
  110. + return []
  111. +
  112. +def xnnpack_emscripten_benchmark_copts():
  113. return [
  114. - ":preamble.js.lds",
  115. + "-s ASSERTIONS=1",
  116. + "-s ERROR_ON_UNDEFINED_SYMBOLS=0",
  117. + "-s ALLOW_MEMORY_GROWTH=0",
  118. + "-s USE_PTHREADS=0",
  119. + "-s STANDALONE_WASM=1",
  120. + "-Wno-unused",
  121. ]
  122. diff --git a/third_party/cpuinfo.BUILD b/third_party/cpuinfo.BUILD
  123. index 128d683e..f6c287c4 100644
  124. --- a/third_party/cpuinfo.BUILD
  125. +++ b/third_party/cpuinfo.BUILD
  126. @@ -343,5 +343,5 @@ config_setting(
  127. config_setting(
  128. name = "emscripten",
  129. - values = {"crosstool_top": "//toolchain:emscripten"},
  130. + values = {"crosstool_top": "@emsdk//emscripten_toolchain:everything"},
  131. )