From 7162be1f496c64444ad5b98d9897d99057865c53 Mon Sep 17 00:00:00 2001 From: Chunnien Chan <121328115+chunnienc@users.noreply.github.com> Date: Mon, 5 Jun 2023 10:39:45 -0700 Subject: [PATCH] Revert "[wasm] Update xnnpack (#7507)" This reverts commit c66f302ea5e8b16da55283688e47e303e4590d60. --- .bazelrc | 3 - WORKSPACE | 66 +++++++++++++------ tfjs-backend-wasm/package.json | 4 +- tfjs-backend-wasm/src/cc/backend.h | 1 - .../src/cc/batch_mat_mul_impl.cc | 3 +- tfjs-backend-wasm/src/cc/conv2d_impl.cc | 2 +- tfjs-backend-wasm/src/cc/prelu_impl.cc | 5 +- 7 files changed, 52 insertions(+), 32 deletions(-) diff --git a/.bazelrc b/.bazelrc index 365c70739a7..8da25af637e 100644 --- a/.bazelrc +++ b/.bazelrc @@ -12,9 +12,6 @@ build --cxxopt="-std=c++17" build --cxxopt="-fno-rtti" build --cxxopt="-fno-exceptions" build --cxxopt="-fomit-frame-pointer" -# Avoid unused function error `xnn_vlog` when building XNNPACK with `-c opt`. -build:xnnpack-opt --copt="-DXNN_LOG_TO_STDIO=0" -build:xnnpack-opt --define=xnn_log_level=none # The following --define=EXECUTOR=remote will be able to be removed # once https://github.com/bazelbuild/bazel/issues/7254 is fixed diff --git a/WORKSPACE b/WORKSPACE index 17e292cd0a6..02d1d98a879 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -102,9 +102,9 @@ http_archive( name = "emsdk", # TODO: Remove repo_mapping when emsdk updates to rules_nodejs 5 repo_mapping = {"@nodejs": "@nodejs_host"}, - sha256 = "bbea764c57af830e761f1fb8600d42dc303aa63ffd43647694eda5b8b757b469", - strip_prefix = "emsdk-3.1.35/bazel", - urls = ["https://github.com/emscripten-core/emsdk/archive/refs/tags/3.1.35.tar.gz"], + sha256 = "b8270749b99d8d14922d1831b93781a5560fba6f7bce65cd477fc1b6aa262535", + strip_prefix = "emsdk-3.1.28/bazel", + urls = ["https://github.com/emscripten-core/emsdk/archive/refs/tags/3.1.28.tar.gz"], ) load("@emsdk//:deps.bzl", emsdk_deps = "deps") @@ -124,9 +124,9 @@ load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") # xnnpack used for fast vectorized wasm operations git_repository( name = "xnnpack", - commit = "fa94f297e58c1e139ca64f78786df3744f557819", + commit = "5e8033a72a8d0f1c2b1f06e29137cc697c6b661d", remote = "https://github.com/google/XNNPACK.git", - shallow_since = "1683912990 -0700", + shallow_since = "1643627844 -0800", ) # The libraries below are transitive dependencies of XNNPACK that we need to @@ -136,10 +136,10 @@ git_repository( http_archive( name = "FP16", build_file = "@xnnpack//third_party:FP16.BUILD", - sha256 = "e66e65515fa09927b348d3d584c68be4215cfe664100d01c9dbc7655a5716d70", - strip_prefix = "FP16-0a92994d729ff76a58f692d3028ca1b64b145d91", + sha256 = "0d56bb92f649ec294dbccb13e04865e3c82933b6f6735d1d7145de45da700156", + strip_prefix = "FP16-3c54eacb74f6f5e39077300c5564156c424d77ba", urls = [ - "https://github.com/Maratyszcza/FP16/archive/0a92994d729ff76a58f692d3028ca1b64b145d91.zip", + "https://github.com/Maratyszcza/FP16/archive/3c54eacb74f6f5e39077300c5564156c424d77ba.zip", ], ) @@ -156,35 +156,61 @@ http_archive( # pthreadpool library, used for parallelization http_archive( name = "pthreadpool", - sha256 = "e6370550a1abf1503daf3c2c196e0a1c2b253440c39e1a57740ff49af2d8bedf", - strip_prefix = "pthreadpool-43edadc654d6283b4b6e45ba09a853181ae8e850", + sha256 = "8461f6540ae9f777ce20d1c0d1d249e5e61c438744fb390c0c6f91940aa69ea3", + strip_prefix = "pthreadpool-545ebe9f225aec6dca49109516fac02e973a3de2", urls = [ - "https://github.com/Maratyszcza/pthreadpool/archive/43edadc654d6283b4b6e45ba09a853181ae8e850.zip", + "https://github.com/Maratyszcza/pthreadpool/archive/545ebe9f225aec6dca49109516fac02e973a3de2.zip", + ], +) + +# clog library, used for logging +http_archive( + name = "clog", + build_file = "@xnnpack//third_party:clog.BUILD", + sha256 = "3f2dc1970f397a0e59db72f9fca6ff144b216895c1d606f6c94a507c1e53a025", + strip_prefix = "cpuinfo-d5e37adf1406cf899d7d9ec1d317c47506ccb970", + urls = [ + "https://github.com/pytorch/cpuinfo/archive/d5e37adf1406cf899d7d9ec1d317c47506ccb970.tar.gz", ], ) # cpuinfo library, used for detecting processor characteristics http_archive( name = "cpuinfo", - sha256 = "ba668f9f8ea5b4890309b7db1ed2e152aaaf98af6f9a8a63dbe1b75c04e52cb9", - strip_prefix = "cpuinfo-3dc310302210c1891ffcfb12ae67b11a3ad3a150", + build_file = "@xnnpack//third_party:cpuinfo.BUILD", + patches = ["@xnnpack//third_party:cpuinfo.patch"], + sha256 = "a7f9a188148a1660149878f737f42783e72f33a4f842f3e362fee2c981613e53", + strip_prefix = "cpuinfo-ed8b86a253800bafdb7b25c5c399f91bff9cb1f3", urls = [ - "https://github.com/pytorch/cpuinfo/archive/3dc310302210c1891ffcfb12ae67b11a3ad3a150.zip", + "https://github.com/pytorch/cpuinfo/archive/ed8b86a253800bafdb7b25c5c399f91bff9cb1f3.zip", ], ) -# Google Test framework, used by most unit-tests. +# psimd library, used for fallback 128-bit SIMD micro-kernels http_archive( + name = "psimd", + build_file = "@xnnpack//third_party:psimd.BUILD", + sha256 = "dc615342bcbe51ca885323e51b68b90ed9bb9fa7df0f4419dbfa0297d5e837b7", + strip_prefix = "psimd-072586a71b55b7f8c584153d223e95687148a900", + urls = [ + "https://github.com/Maratyszcza/psimd/archive/072586a71b55b7f8c584153d223e95687148a900.zip", + ], +) + +git_repository( name = "com_google_googletest", - sha256 = "5cb522f1427558c6df572d6d0e1bf0fd076428633d080e88ad5312be0b6a8859", - strip_prefix = "googletest-e23cdb78e9fef1f69a9ef917f447add5638daf2a", - urls = ["https://github.com/google/googletest/archive/e23cdb78e9fef1f69a9ef917f447add5638daf2a.zip"], + commit = "cd17fa2abda2a2e4111cdabd62a87aea16835014", + remote = "https://github.com/google/googletest.git", + shallow_since = "1570558426 -0400", ) http_archive( name = "rules_cc", - strip_prefix = "rules_cc-main", - urls = ["https://github.com/bazelbuild/rules_cc/archive/main.zip"], + sha256 = "90d5a66950b492cbf86201cdc49c4b59796a85a4eb9fd63c07afe5f7132ea623", + strip_prefix = "rules_cc-8346df34b6593b051403b8e429db15c7f4ead937", + urls = [ + "https://github.com/bazelbuild/rules_cc/archive/8346df34b6593b051403b8e429db15c7f4ead937.zip", + ], ) http_archive( diff --git a/tfjs-backend-wasm/package.json b/tfjs-backend-wasm/package.json index b6bf9934158..20e53047536 100644 --- a/tfjs-backend-wasm/package.json +++ b/tfjs-backend-wasm/package.json @@ -14,9 +14,9 @@ "jsdelivr": "dist/tf-backend-wasm.min.js", "miniprogram": "dist/miniprogram", "scripts": { - "build": "bazel build -c opt --config=xnnpack-opt :tfjs-backend-wasm_pkg", + "build": "bazel build -c opt :tfjs-backend-wasm_pkg", "build-dbg": "bazel build -c dbg :tfjs-backend-wasm_pkg", - "publish-npm": "bazel run -c opt --config=xnnpack-opt :tfjs-backend-wasm_pkg.publish", + "publish-npm": "bazel run -c opt :tfjs-backend-wasm_pkg.publish", "clean": "bazel clean --expunge", "cpplint": "./scripts/cpplint.js", "test": "bazel test -c dbg :tests --test_output=all", diff --git a/tfjs-backend-wasm/src/cc/backend.h b/tfjs-backend-wasm/src/cc/backend.h index 70a34c23683..89bfc8161da 100644 --- a/tfjs-backend-wasm/src/cc/backend.h +++ b/tfjs-backend-wasm/src/cc/backend.h @@ -92,7 +92,6 @@ const size_t num_tensors(); extern size_t xnn_operator_count; extern pthreadpool *threadpool; - } // namespace backend namespace wasm { diff --git a/tfjs-backend-wasm/src/cc/batch_mat_mul_impl.cc b/tfjs-backend-wasm/src/cc/batch_mat_mul_impl.cc index 25317990a10..13f2aa92a02 100644 --- a/tfjs-backend-wasm/src/cc/batch_mat_mul_impl.cc +++ b/tfjs-backend-wasm/src/cc/batch_mat_mul_impl.cc @@ -128,8 +128,7 @@ void xnn_matmul(const size_t a_id, const size_t* a_shape_ptr, const uint32_t flags = XNN_FLAG_TRANSPOSE_WEIGHTS; xnn_status status = xnn_create_fully_connected_nc_f32( input_channels, output_channels, input_stride, output_stride, b_buf, - bias_buf, output_min, output_max, flags, - /*code_cache=*/nullptr, /*weights_cache=*/nullptr, &fully_connected_op); + bias_buf, output_min, output_max, flags, &fully_connected_op); if (status != xnn_status_success) { tfjs::util::warn( "XNN status for xnn_create_fully_connected_nc_f32 is not successful. " diff --git a/tfjs-backend-wasm/src/cc/conv2d_impl.cc b/tfjs-backend-wasm/src/cc/conv2d_impl.cc index 23d1e7871e0..aae4091a4b4 100644 --- a/tfjs-backend-wasm/src/cc/conv2d_impl.cc +++ b/tfjs-backend-wasm/src/cc/conv2d_impl.cc @@ -236,7 +236,7 @@ void conv2d(const size_t x_id, const size_t batch_size, stride_height, stride_width, dilation_height, dilation_width, groups, group_input_channels, group_output_channels, input_pixel_stride, output_pixel_stride, filter_xnn, bias_buf, output_min, output_max, - flags, /*code_cache=*/nullptr, /*weights_cache=*/nullptr, &conv2d_op); + flags, &conv2d_op); if (status != xnn_status_success) { util::warn( "XNN status for xnn_create_convolution2d_nhwc_f32 is not successful. " diff --git a/tfjs-backend-wasm/src/cc/prelu_impl.cc b/tfjs-backend-wasm/src/cc/prelu_impl.cc index e28a221227f..e795eef405d 100644 --- a/tfjs-backend-wasm/src/cc/prelu_impl.cc +++ b/tfjs-backend-wasm/src/cc/prelu_impl.cc @@ -60,9 +60,8 @@ void prelu(const float* x_buf, const size_t x_size, const size_t weights_id, const size_t strides = channels; const uint32_t flags = 0; - xnn_status status = xnn_create_prelu_nc_f32( - channels, strides, strides, weights_buf, flags, - /*code_cache=*/nullptr, /*weights_cache=*/nullptr, &prelu_op); + xnn_status status = xnn_create_prelu_nc_f32(channels, strides, strides, + weights_buf, flags, &prelu_op); if (status != xnn_status_success) { util::warn( "XNN status for xnn_create_prelu_nc_f32 is not successful. Got "