Repository: tensorflow
Issue: Build Failure on AWS Graviton3 with Custom oneDNN (oneDNN-3.6-rc): Invalid Preprocessing Directives in dnnl_config.h
Labels: stat:awaiting tensorflower,type:build/install,comp:mkl,subtype: ubuntu/linux,2.17

### Issue type

Build/Install

### Have you reproduced the bug with TensorFlow Nightly?

No

### Source

source

### TensorFlow version

tf v2.17.0

### Custom code

No

### OS platform and distribution

Ubuntu 22.04.2 LTS

### Mobile device

_No response_

### Python version

3.10.12

### Bazel version

6.5.0

### GCC/compiler version

gcc version 11.4.0

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current behavior?

I am unable to build TensorFlow with the latest oneDNN or custom oneDNN (oneDNN-3.6-rc) on AWS Graviton3 (aarch64) CPU. The build process fails with several compilation errors related to invalid preprocessing directives in the dnnl_config.h file.

I expected the build to complete successfully with the custom oneDNN settings, allowing TensorFlow to run efficiently on the AWS Graviton3 (aarch64) architecture.

### Standalone code to reproduce the issue

```shell
Clone the TensorFlow repository:

git clone https://github.com/tensorflow/tensorflow.git
cd tensorflow
git checkout v2.17.0

Modify the relevant files as follows:

Update oneDNN version in tensorflow/workspace2.bzl.
Adjust mkldnn_acl.BUILD for versioning.

root@8c5bdc6a1bd7:/workdir/tensorflow# git diff
diff --git a/tensorflow/workspace2.bzl b/tensorflow/workspace2.bzl
index fd29dff05f3..7ed30157970 100644
--- a/tensorflow/workspace2.bzl
+++ b/tensorflow/workspace2.bzl
@@ -205,36 +205,24 @@ def _tf_repositories():
     tf_http_archive(
         name = "onednn",
         build_file = "//third_party/mkl_dnn:mkldnn_v1.BUILD",
-        sha256 = "5131ac559a13daa6e2784d20ab24e4607e55aa6da973518086326a647d389425",
-        strip_prefix = "oneDNN-3.4.2",
-        urls = tf_mirror_urls("https://github.com/oneapi-src/oneDNN/archive/refs/tags/v3.4.2.tar.gz"),
+       sha256 = "568428621a4912dd2159eaee97f646259c655acc271dc57bd75478daa9672ea5",
+       strip_prefix = "oneDNN-3.6-rc",
+       urls = tf_mirror_urls("https://github.com/oneapi-src/oneDNN/archive/refs/tags/v3.6-rc.tar.gz"),
     )
 
     tf_http_archive(
         name = "mkl_dnn_acl_compatible",
         build_file = "//third_party/mkl_dnn:mkldnn_acl.BUILD",
-        patch_file = [
-            "//third_party/mkl_dnn:onednn_acl_threadcap.patch",
-            "//third_party/mkl_dnn:onednn_acl_reorder.patch",
-            "//third_party/mkl_dnn:onednn_acl_thread_local_scheduler.patch",
-            "//third_party/mkl_dnn:onednn_acl_fp32_bf16_reorder.patch",
-            "//third_party/mkl_dnn:onednn_acl_bf16_capability_detection_for_ubuntu20.04.patch",
-            "//third_party/mkl_dnn:onednn_acl_indirect_conv.patch",
-        ],
-        sha256 = "2f76b407ef8893cca71340f88cd800019a1f14f8ac1bbdbb89a84be1370b52e3",
-        strip_prefix = "oneDNN-3.2.1",
-        urls = tf_mirror_urls("https://github.com/oneapi-src/oneDNN/archive/refs/tags/v3.2.1.tar.gz"),
+       sha256 = "568428621a4912dd2159eaee97f646259c655acc271dc57bd75478daa9672ea5",
+        strip_prefix = "oneDNN-3.6-rc",
+        urls = tf_mirror_urls("https://github.com/oneapi-src/oneDNN/archive/refs/tags/v3.6-rc.tar.gz"),
     )
 
     tf_http_archive(
         name = "compute_library",
-        patch_file = [
-            "//third_party/compute_library:compute_library.patch",
-            "//third_party/compute_library:acl_thread_local_scheduler.patch",
-        ],
-        sha256 = "c4ca329a78da380163b2d86e91ba728349b6f0ee97d66e260a694ef37f0b0d93",
-        strip_prefix = "ComputeLibrary-23.05.1",
-        urls = tf_mirror_urls("https://github.com/ARM-software/ComputeLibrary/archive/v23.05.1.tar.gz"),
+        sha256 = "e7e1b554129748c3aadf1a85de48d332afbef7c6c0c3c5be77a1cfb58311c57b",
+        strip_prefix = "ComputeLibrary-24.08.1",
+        urls = tf_mirror_urls("https://github.com/ARM-software/ComputeLibrary/archive/refs/tags/v24.08.1.tar.gz")
     )
 
     tf_http_archive(
diff --git a/third_party/mkl_dnn/mkldnn_acl.BUILD b/third_party/mkl_dnn/mkldnn_acl.BUILD
index d67b62a98d2..083b3d7a627 100644
--- a/third_party/mkl_dnn/mkldnn_acl.BUILD
+++ b/third_party/mkl_dnn/mkldnn_acl.BUILD
@@ -128,8 +128,8 @@ expand_template(
     out = "include/oneapi/dnnl/dnnl_version.h",
     substitutions = {
         "@DNNL_VERSION_MAJOR@": "3",
-        "@DNNL_VERSION_MINOR@": "2",
-        "@DNNL_VERSION_PATCH@": "1",
+        "@DNNL_VERSION_MINOR@": "6",
+        "@DNNL_VERSION_PATCH@": "0",
         "@DNNL_VERSION_HASH@": "N/A",
     },
     template = "include/oneapi/dnnl/dnnl_version.h.in",
(END)


Attempt to build TensorFlow:

taskset -c 16-32 bazel build //tensorflow/tools/pip_package:wheel --repo_env=WHEEL_NAME=tensorflow_cpu --config=mkl_aarch64_threadpool --jobs=33 --local_cpu_resources=16 --verbose_failures -s
```


### Relevant log output

```shell
ERROR: /root/.cache/bazel/_bazel_root/58adfe0c0193ce259b2b32549c3d3a4f/external/mkl_dnn_acl_compatible/BUILD.bazel:138:11: Compiling src/common/batch_normalization.cpp failed: (Exit 1): gcc failed: error executing command (from target @mkl_dnn_acl_compatible//:mkl_dnn_acl) 
  (cd /root/.cache/bazel/_bazel_root/58adfe0c0193ce259b2b32549c3d3a4f/execroot/org_tensorflow && \
  exec env - \
    PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
    PWD=/proc/self/cwd \
    PYTHON_BIN_PATH=/usr/bin/python3 \
    PYTHON_LIB_PATH=/usr/lib/python3/dist-packages \
    TF2_BEHAVIOR=1 \
  /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -g0 -O2 '-D_FORTIFY_SOURCE=1' -DNDEBUG -ffunction-sections -fdata-sections '-std=c++14' -MD -MF bazel-out/aarch64-opt/bin/external/mkl_dnn_acl_compatible/_objs/mkl_dnn_acl/batch_normalization.pic.d '-frandom-seed=bazel-out/aarch64-opt/bin/external/mkl_dnn_acl_compatible/_objs/mkl_dnn_acl/batch_normalization.pic.o' -fPIC -DENABLE_NEON -DARM_COMPUTE_CPU_ENABLED -DARM_COMPUTE_ENABLE_NEON -DARM_COMPUTE_ENABLE_I8MM -DENABLE_FP32_KERNELS -DENABLE_QASYMM8_KERNELS -DENABLE_QASYMM8_SIGNED_KERNELS -DENABLE_QSYMM16_KERNELS -DENABLE_INTEGER_KERNELS -DENABLE_NHWC_KERNELS -DENABLE_NCHW_KERNELS -DARM_COMPUTE_GRAPH_ENABLED -DARM_COMPUTE_ENABLE_SVEF32MM -DARM_COMPUTE_ENABLE_FIXED_FORMAT_KERNELS -D_GLIBCXX_USE_NANOSLEEP -DARM_COMPUTE_OPENMP_SCHEDULER '-DDNNL_AARCH64_USE_ACL=1' '-DBAZEL_CURRENT_REPOSITORY="mkl_dnn_acl_compatible"' -iquote external/mkl_dnn_acl_compatible -iquote bazel-out/aarch64-opt/bin/external/mkl_dnn_acl_compatible -iquote external/compute_library -iquote bazel-out/aarch64-opt/bin/external/compute_library -Ibazel-out/aarch64-opt/bin/external/compute_library/include/_virtual_includes/include -isystem external/mkl_dnn_acl_compatible/include -isystem bazel-out/aarch64-opt/bin/external/mkl_dnn_acl_compatible/include -isystem external/mkl_dnn_acl_compatible/src -isystem bazel-out/aarch64-opt/bin/external/mkl_dnn_acl_compatible/src -isystem external/mkl_dnn_acl_compatible/src/common -isystem bazel-out/aarch64-opt/bin/external/mkl_dnn_acl_compatible/src/common -isystem external/mkl_dnn_acl_compatible/src/cpu -isystem bazel-out/aarch64-opt/bin/external/mkl_dnn_acl_compatible/src/cpu -isystem external/mkl_dnn_acl_compatible/src/cpu/aarch64/xbyak_aarch64/src -isystem bazel-out/aarch64-opt/bin/external/mkl_dnn_acl_compatible/src/cpu/aarch64/xbyak_aarch64/src -isystem external/mkl_dnn_acl_compatible/src/cpu/aarch64/xbyak_aarch64/xbyak_aarch64 -isystem bazel-out/aarch64-opt/bin/external/mkl_dnn_acl_compatible/src/cpu/aarch64/xbyak_aarch64/xbyak_aarch64 -isystem external/mkl_dnn_acl_compatible/src/cpu/gemm -isystem bazel-out/aarch64-opt/bin/external/mkl_dnn_acl_compatible/src/cpu/gemm -isystem external/compute_library/arm_compute/runtime -isystem bazel-out/aarch64-opt/bin/external/compute_library/arm_compute/runtime -isystem external/compute_library/src/core/NEON/kernels/arm_gemm -isystem bazel-out/aarch64-opt/bin/external/compute_library/src/core/NEON/kernels/arm_gemm -isystem external/compute_library/src/core/NEON/kernels/assembly -isystem bazel-out/aarch64-opt/bin/external/compute_library/src/core/NEON/kernels/assembly -isystem external/compute_library/src/core/NEON/kernels/convolution/common -isystem bazel-out/aarch64-opt/bin/external/compute_library/src/core/NEON/kernels/convolution/common -isystem external/compute_library/src/core/NEON/kernels/convolution/winograd -isystem bazel-out/aarch64-opt/bin/external/compute_library/src/core/NEON/kernels/convolution/winograd -isystem external/compute_library/src/core/cpu/kernels/assembly -isystem bazel-out/aarch64-opt/bin/external/compute_library/src/core/cpu/kernels/assembly -isystem external/compute_library/src/cpu/kernels/assembly -isystem bazel-out/aarch64-opt/bin/external/compute_library/src/cpu/kernels/assembly -isystem external/compute_library/src/core/NEON/kernels/arm_conv -isystem bazel-out/aarch64-opt/bin/external/compute_library/src/core/NEON/kernels/arm_conv -Wno-all -Wno-extra -Wno-deprecated -Wno-deprecated-declarations -Wno-ignored-attributes -Wno-array-bounds -Wunused-result '-Werror=unused-result' -Wswitch '-Werror=switch' '-Wno-error=unused-but-set-variable' -DAUTOLOAD_DYNAMIC_KERNELS '-std=c++17' -fopenmp-simd -fexceptions -UUSE_MKL -UUSE_CBLAS -fno-canonical-system-headers -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' -c external/mkl_dnn_acl_compatible/src/common/batch_normalization.cpp -o bazel-out/aarch64-opt/bin/external/mkl_dnn_acl_compatible/_objs/mkl_dnn_acl/batch_normalization.pic.o)
# Configuration: 286713d3e237c869e8689debb2d6b060b16fc87de4d5e6ded144ba62ae251131
# Execution platform: @local_execution_config_platform//:platform
In file included from external/mkl_dnn_acl_compatible/include/oneapi/dnnl/dnnl_common_types.h:31,
                 from external/mkl_dnn_acl_compatible/include/oneapi/dnnl/dnnl_common.h:23,
                 from external/mkl_dnn_acl_compatible/include/oneapi/dnnl/dnnl.h:23,
                 from external/mkl_dnn_acl_compatible/src/common/batch_normalization.cpp:18:
bazel-out/aarch64-opt/bin/external/mkl_dnn_acl_compatible/include/oneapi/dnnl/dnnl_config.h:112:2: error: invalid preprocessing directive #cmakedefine
  112 | #cmakedefine DNNL_GPU_VENDOR DNNL_VENDOR_${DNNL_GPU_VENDOR}
      |  ^~~~~~~~~~~
bazel-out/aarch64-opt/bin/external/mkl_dnn_acl_compatible/include/oneapi/dnnl/dnnl_config.h:158:2: error: invalid preprocessing directive #cmakedefine
  158 | #cmakedefine DNNL_SYCL_GENERIC
      |  ^~~~~~~~~~~
bazel-out/aarch64-opt/bin/external/mkl_dnn_acl_compatible/include/oneapi/dnnl/dnnl_config.h:181:2: error: invalid preprocessing directive #cmakedefine
  181 | #cmakedefine DNNL_DISABLE_GPU_REF_KERNELS
      |  ^~~~~~~~~~~
bazel-out/aarch64-opt/bin/external/mkl_dnn_acl_compatible/include/oneapi/dnnl/dnnl_config.h:195:2: error: invalid preprocessing directive #cmakedefine01
  195 | #cmakedefine01 BUILD_GROUP_NORMALIZATION
      |  ^~~~~~~~~~~~~
bazel-out/aarch64-opt/bin/external/mkl_dnn_acl_compatible/include/oneapi/dnnl/dnnl_config.h:206:2: error: invalid preprocessing directive #cmakedefine01
  206 | #cmakedefine01 BUILD_SDPA
      |  ^~~~~~~~~~~~~
bazel-out/aarch64-opt/bin/external/mkl_dnn_acl_compatible/include/oneapi/dnnl/dnnl_config.h:224:2: error: invalid preprocessing directive #cmakedefine01
  224 | #cmakedefine01 BUILD_XE2
      |  ^~~~~~~~~~~~~
bazel-out/aarch64-opt/bin/external/mkl_dnn_acl_compatible/include/oneapi/dnnl/dnnl_config.h:226:2: error: invalid preprocessing directive #cmakedefine01
  226 | #cmakedefine01 BUILD_GEMM_KERNELS_ALL
      |  ^~~~~~~~~~~~~
bazel-out/aarch64-opt/bin/external/mkl_dnn_acl_compatible/include/oneapi/dnnl/dnnl_config.h:227:2: error: invalid preprocessing directive #cmakedefine01
  227 | #cmakedefine01 BUILD_GEMM_KERNELS_NONE
      |  ^~~~~~~~~~~~~
bazel-out/aarch64-opt/bin/external/mkl_dnn_acl_compatible/include/oneapi/dnnl/dnnl_config.h:228:2: error: invalid preprocessing directive #cmakedefine01
  228 | #cmakedefine01 BUILD_GEMM_SSE41
      |  ^~~~~~~~~~~~~
bazel-out/aarch64-opt/bin/external/mkl_dnn_acl_compatible/include/oneapi/dnnl/dnnl_config.h:229:2: error: invalid preprocessing directive #cmakedefine01
  229 | #cmakedefine01 BUILD_GEMM_AVX2
      |  ^~~~~~~~~~~~~
bazel-out/aarch64-opt/bin/external/mkl_dnn_acl_compatible/include/oneapi/dnnl/dnnl_config.h:230:2: error: invalid preprocessing directive #cmakedefine01
  230 | #cmakedefine01 BUILD_GEMM_AVX512
      |  ^~~~~~~~~~~~~
SUBCOMMAND: # @boringssl//:crypto [action 'Compiling src/crypto/pem/pem_lib.c [for tool]', configuration: 6c76bd453e22b21125a2028c36fb69b9de59167ea2a1dca88d8da721e8db0553, execution platform: @local_execution_config_platform//:platform]
(cd /root/.cache/bazel/_bazel_root/58adfe0c0193ce259b2b32549c3d3a4f/execroot/org_tensorflow && \
  exec env - \
    PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
    PWD=/proc/self/cwd \
  /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -g0 -O2 '-D_FORTIFY_SOURCE=1' -DNDEBUG -ffunction-sections -fdata-sections -MD -MF bazel-out/aarch64-opt-exec-50AE0418/bin/external/boringssl/_objs/crypto/pem_lib.pic.d '-frandom-seed=bazel-out/aarch64-opt-exec-50AE0418/bin/external/boringssl/_objs/crypto/pem_lib.pic.o' -fPIC '-DBAZEL_CURRENT_REPOSITORY="boringssl"' -iquote external/boringssl -iquote bazel-out/aarch64-opt-exec-50AE0418/bin/external/boringssl -isystem external/boringssl/src/include -isystem bazel-out/aarch64-opt-exec-50AE0418/bin/external/boringssl/src/include -g0 -w -DBORINGSSL_IMPLEMENTATION -Wa,--noexecstack -Wall -Werror '-Wformat=2' -Wsign-compare -Wmissing-field-initializers -Wwrite-strings -Wshadow -fno-common '-D_XOPEN_SOURCE=700' '-std=c11' -Wmissing-prototypes -Wold-style-definition -Wstrict-prototypes -fno-canonical-system-headers -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' -c external/boringssl/src/crypto/pem/pem_lib.c -o bazel-out/aarch64-opt-exec-50AE0418/bin/external/boringssl/_objs/crypto/pem_lib.pic.o)
# Configuration: 6c76bd453e22b21125a2028c36fb69b9de59167ea2a1dca88d8da721e8db0553
# Execution platform: @local_execution_config_platform//:platform
Target //tensorflow/tools/pip_package:wheel failed to build
INFO: Elapsed time: 165.542s, Critical Path: 28.45s
INFO: 5206 processes: 1083 internal, 4123 local.
FAILED: Build did NOT complete successfully
```