message: Build autogen files in oneDNN with just -O1 to save compilation time. These files just generate binary kernels and are not the hot spots so this should be fine.
diff: @@ -68,46 +68,70 @@ template_rule(
  },
  )
  -cc_library(
  - name = "mkl_dnn",
  - srcs = glob(
  - [
  - "src/common/*.cpp",
  - "src/cpu/*.cpp",
  - "src/cpu/**/*.cpp",
  - "src/cpu/x64/jit_utils/jitprofiling/*.c",
  - ],
  - exclude = ["src/cpu/aarch64/**"],
  - ) + [
  - ":dnnl_config_h",
  - ":dnnl_version_h",
  - ],
  - copts = select({
  +_COPTS_LIST = select({
  "@org_tensorflow//tensorflow:windows": [],
  "//conditions:default": ["-fexceptions"],
  }) + [
  "-UUSE_MKL",
  "-UUSE_CBLAS",
  "-DDNNL_ENABLE_MAX_CPU_ISA",
  - ] + tf_openmp_copts(),
  - includes = [
  +] + tf_openmp_copts()
  +
  +_INCLUDES_LIST = [
  "include",
  "src",
  "src/common",
  "src/cpu",
  "src/cpu/gemm",
  "src/cpu/x64/xbyak",
  - ],
  - textual_hdrs = glob([
  +]
  +
  +_TEXTUAL_HDRS_LIST = glob([
  "include/**/*",
  "src/common/*.hpp",
  "src/cpu/*.hpp",
  "src/cpu/**/*.hpp",
  "src/cpu/x64/jit_utils/jitprofiling/*.h",
  "src/cpu/x64/xbyak/*.h",
  - ]),
  +]) + [
  + ":dnnl_config_h",
  + ":dnnl_version_h",
  +]
  +
  +# Large autogen files take too long time to compile with usual optimization
  +# flags. These files just generate binary kernels and are not the hot spots,
  +# so we factor them out to lower compiler optimizations in ":dnnl_autogen".
  +cc_library(
  + name = "onednn_autogen",
  + srcs = glob(["src/cpu/x64/gemm/**/*_kern_autogen*.cpp"]),
  + copts = select({
  + "@org_tensorflow//tensorflow:macos": ["-O0"],
  + "//conditions:default": ["-O1"],
  + }) + ["-U_FORTIFY_SOURCE"] + _COPTS_LIST,
  + includes = _INCLUDES_LIST,
  + textual_hdrs = _TEXTUAL_HDRS_LIST,
  + visibility = ["//visibility:public"],
  +)
  +
  +cc_library(
  + name = "mkl_dnn",
  + srcs = glob(
  + [
  + "src/common/*.cpp",
  + "src/cpu/*.cpp",
  + "src/cpu/**/*.cpp",
  + "src/cpu/x64/jit_utils/jitprofiling/*.c",
  + ],
  + exclude = [
  + "src/cpu/aarch64/**",
  + "src/cpu/x64/gemm/**/*_kern_autogen.cpp",
  + ],
  + ),
  + copts = _COPTS_LIST,
  + includes = _INCLUDES_LIST,
  + textual_hdrs = _TEXTUAL_HDRS_LIST,
  visibility = ["//visibility:public"],
  - deps = if_mkl_ml(
  + deps = [":onednn_autogen"] + if_mkl_ml(
  ["@org_tensorflow//third_party/mkl:intel_binary_blob"],
  [],
  ),
  