chromium/third_party/ruy/BUILD.gn

# Copyright 2020 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/arm.gni")
import("//third_party/cpuinfo/cpuinfo.gni")

config("ruy_include") {
  include_dirs = [ "src" ]
}

config("ruy_shared_config") {
  include_dirs = [ "src" ]

  if (current_cpu == "arm" || current_cpu == "arm64") {
    # Disables a warning about the assembly instructions that are used.
    cflags = [ "-Wno-inline-asm" ]
  }
}

# We skip cmake's |ruy_0_Wall_Wcxx14_compat_Wextra_Wundef|, |ruy_1_mfpu_neon|,
# |ruy_2_O3|, |ruy_3_pthread|, and |ruy_no_undef| rules since those flags are
# covered by Chromium's build system..

# Analogous to cmake's |ruy_5_DRUY_HAVE_CPUINFO|.
config("ruy_cpuinfo_config") {
  if (use_cpuinfo) {
    defines = [ "RUY_HAVE_CPUINFO" ]
  }
}

# We skip cmake's
# |ruy_7_mavx512bw_mavx512cd_mavx512dq_mavx512f_mavx512vl_arch_AVX512| rule
# since there's too few consumer machines that it would apply to, while still
# eating the binary size for everybody.

# Analogous to cmake's |ruy_8_mavx2_mfma_arch_AVX2|.
# Note: No MSVC style flags are used since it is not supported by Chrome.
config("ruy_avx2_flags") {
  if (current_cpu == "x86_64" || current_cpu == "x64" ||
      current_cpu == "amd64") {
    cflags = [
      "-mavx2",
      "-mfma",
    ]
  }
}

# Analogous to cmake's |ruy_9_mavx_arch_AVX|.
# Note: No MSVC style flags are used since it is not supported by Chrome.
config("ruy_avx_flags") {
  if (current_cpu == "x86_64" || current_cpu == "x64" ||
      current_cpu == "amd64") {
    cflags = [ "-mavx" ]
  }
}

# We skip cmake's |ruy_10_lm| rule since those flags are covered by Chromium's
# build system.

source_set("ruy_trace") {
  sources = [ "src/ruy/trace.h" ]
  configs += [ ":ruy_shared_config" ]
  deps = [
    ":ruy_mat",
    ":ruy_matrix",
    ":ruy_path",
    ":ruy_platform",
    ":ruy_side_pair",
  ]
}

source_set("ruy_platform") {
  sources = [ "src/ruy/platform.h" ]
  configs += [ ":ruy_shared_config" ]
}

source_set("ruy_check_macros") {
  sources = [ "src/ruy/check_macros.h" ]
  configs += [ ":ruy_shared_config" ]
}

source_set("ruy_opt_set") {
  sources = [ "src/ruy/opt_set.h" ]
  configs += [ ":ruy_shared_config" ]
}

source_set("ruy_time") {
  sources = [ "src/ruy/time.h" ]
  configs += [ ":ruy_shared_config" ]
}

source_set("ruy_wait") {
  sources = [
    "src/ruy/wait.cc",
    "src/ruy/wait.h",
  ]
  configs += [ ":ruy_shared_config" ]
  deps = [ ":ruy_time" ]
}

source_set("ruy_size_util") {
  sources = [ "src/ruy/size_util.h" ]
  configs += [ ":ruy_shared_config" ]
  deps = [ ":ruy_check_macros" ]
}

source_set("ruy_tune") {
  sources = [
    "src/ruy/tune.cc",
    "src/ruy/tune.h",
  ]
  configs += [ ":ruy_shared_config" ]
  deps = [
    ":ruy_cpu_cache_params",
    ":ruy_cpuinfo",
    ":ruy_opt_set",
    ":ruy_platform",
    ":ruy_time",
  ]
}

source_set("ruy_system_aligned_alloc") {
  sources = [
    "src/ruy/system_aligned_alloc.cc",
    "src/ruy/system_aligned_alloc.h",
  ]
  configs += [ ":ruy_shared_config" ]
}

source_set("ruy_prepacked_cache") {
  sources = [
    "src/ruy/prepacked_cache.cc",
    "src/ruy/prepacked_cache.h",
  ]
  configs += [ ":ruy_shared_config" ]
  deps = [
    ":ruy_mat",
    ":ruy_profiler_instrumentation",
    ":ruy_system_aligned_alloc",
  ]
}

source_set("ruy_allocator") {
  sources = [
    "src/ruy/allocator.cc",
    "src/ruy/allocator.h",
  ]
  configs += [ ":ruy_shared_config" ]
  deps = [
    ":ruy_opt_set",
    ":ruy_size_util",
    ":ruy_system_aligned_alloc",
  ]
}

source_set("ruy_side_pair") {
  sources = [ "src/ruy/side_pair.h" ]
  configs += [ ":ruy_shared_config" ]
  deps = [ ":ruy_check_macros" ]
}

source_set("ruy_block_map") {
  sources = [
    "src/ruy/block_map.cc",
    "src/ruy/block_map.h",
  ]
  configs -= [ "//build/config/compiler:chromium_code" ]
  configs += [
    "//build/config/compiler:no_chromium_code",
    ":ruy_shared_config",
  ]
  deps = [
    ":ruy_check_macros",
    ":ruy_cpu_cache_params",
    ":ruy_opt_set",
    ":ruy_profiler_instrumentation",
    ":ruy_side_pair",
    ":ruy_size_util",
    ":ruy_trace",
  ]
}

source_set("ruy_blocking_counter") {
  sources = [
    "src/ruy/blocking_counter.cc",
    "src/ruy/blocking_counter.h",
  ]
  configs += [ ":ruy_shared_config" ]
  deps = [
    ":ruy_check_macros",
    ":ruy_time",
    ":ruy_wait",
  ]
}

source_set("ruy_thread_pool") {
  sources = [
    "src/ruy/thread_pool.cc",
    "src/ruy/thread_pool.h",
  ]
  configs += [ ":ruy_shared_config" ]
  deps = [
    ":ruy_blocking_counter",
    ":ruy_check_macros",
    ":ruy_denormal",
    ":ruy_time",
    ":ruy_trace",
    ":ruy_wait",
  ]
}

source_set("ruy_cpu_cache_params") {
  sources = [ "src/ruy/cpu_cache_params.h" ]
  configs += [ ":ruy_shared_config" ]
}

source_set("ruy_cpuinfo") {
  sources = [
    "src/ruy/cpuinfo.cc",
    "src/ruy/cpuinfo.h",
  ]
  configs += [
    ":ruy_shared_config",
    ":ruy_cpuinfo_config",
  ]
  deps = [
    ":ruy_check_macros",
    ":ruy_cpu_cache_params",
    ":ruy_platform",
  ]

  if (use_cpuinfo) {
    deps += [ "//third_party/cpuinfo" ]
  }
}

source_set("ruy_path") {
  sources = [ "src/ruy/path.h" ]
  configs += [ ":ruy_shared_config" ]
  deps = [
    ":ruy_platform",
    ":ruy_size_util",
  ]
}

source_set("ruy_denormal") {
  sources = [
    "src/ruy/denormal.cc",
    "src/ruy/denormal.h",
  ]
  configs += [ ":ruy_shared_config" ]
}

source_set("ruy_performance_advisory") {
  sources = [ "src/ruy/performance_advisory.h" ]
  configs += [ ":ruy_shared_config" ]
}

source_set("ruy_matrix") {
  sources = [ "src/ruy/matrix.h" ]
  configs += [ ":ruy_shared_config" ]
  deps = [ ":ruy_check_macros" ]
}

source_set("ruy_mul_params") {
  sources = [ "src/ruy/mul_params.h" ]
  configs += [ ":ruy_shared_config" ]
  deps = [
    ":ruy_check_macros",
    ":ruy_size_util",
  ]
}

source_set("ruy_mat") {
  sources = [ "src/ruy/mat.h" ]
  configs += [ ":ruy_shared_config" ]
  deps = [
    ":ruy_check_macros",
    ":ruy_matrix",
    ":ruy_size_util",
  ]
}

source_set("ruy_asm_helpers") {
  sources = [ "src/ruy/asm_helpers.h" ]
  configs += [ ":ruy_shared_config" ]
  deps = [ ":ruy_opt_set" ]
}

source_set("ruy_apply_multiplier") {
  sources = [
    "src/ruy/apply_multiplier.cc",
    "src/ruy/apply_multiplier.h",
  ]
  configs += [ ":ruy_shared_config" ]
  deps = [
    ":ruy_check_macros",
    ":ruy_mul_params",
  ]
}

source_set("ruy_kernel_common") {
  sources = [ "src/ruy/kernel_common.h" ]
  configs += [ ":ruy_shared_config" ]
  deps = [
    ":ruy_apply_multiplier",
    ":ruy_check_macros",
    ":ruy_instrumentation",
    ":ruy_mat",
    ":ruy_matrix",
    ":ruy_mul_params",
    ":ruy_opt_set",
    ":ruy_path",
    ":ruy_platform",
    ":ruy_profiler_instrumentation",
    ":ruy_side_pair",
    ":ruy_size_util",
    ":ruy_tune",
  ]
}

source_set("ruy_pack_common") {
  sources = [ "src/ruy/pack_common.h" ]
  configs += [ ":ruy_shared_config" ]
  deps = [
    ":ruy_check_macros",
    ":ruy_mat",
    ":ruy_matrix",
    ":ruy_opt_set",
    ":ruy_path",
    ":ruy_platform",
    ":ruy_profiler_instrumentation",
    ":ruy_tune",
  ]
}

source_set("ruy_kernel_arm") {
  sources = [
    "src/ruy/kernel_arm.h",
    "src/ruy/kernel_arm32.cc",
    "src/ruy/kernel_arm64.cc",
  ]
  configs += [ ":ruy_shared_config" ]
  deps = [
    ":ruy_asm_helpers",
    ":ruy_check_macros",
    ":ruy_kernel_common",
    ":ruy_mat",
    ":ruy_mul_params",
    ":ruy_opt_set",
    ":ruy_path",
    ":ruy_platform",
    ":ruy_profiler_instrumentation",
    ":ruy_side_pair",
    ":ruy_size_util",
    ":ruy_tune",
  ]
}

source_set("ruy_pack_arm") {
  sources = [
    "src/ruy/pack_arm.cc",
    "src/ruy/pack_arm.h",
  ]
  configs += [ ":ruy_shared_config" ]
  deps = [
    ":ruy_asm_helpers",
    ":ruy_check_macros",
    ":ruy_mat",
    ":ruy_opt_set",
    ":ruy_pack_common",
    ":ruy_path",
    ":ruy_platform",
    ":ruy_profiler_instrumentation",
    ":ruy_tune",
  ]
}

source_set("ruy_kernel_avx512") {
  sources = [
    "src/ruy/kernel_avx512.cc",
    "src/ruy/kernel_x86.h",
  ]
  configs += [ ":ruy_shared_config" ]
  deps = [
    ":ruy_check_macros",
    ":ruy_instrumentation",
    ":ruy_kernel_common",
    ":ruy_mat",
    ":ruy_mul_params",
    ":ruy_opt_set",
    ":ruy_path",
    ":ruy_platform",
    ":ruy_profiler_instrumentation",
    ":ruy_tune",
  ]
}

source_set("ruy_pack_avx512") {
  sources = [
    "src/ruy/pack_avx512.cc",
    "src/ruy/pack_x86.h",
  ]
  configs += [ ":ruy_shared_config" ]
  deps = [
    ":ruy_check_macros",
    ":ruy_mat",
    ":ruy_opt_set",
    ":ruy_pack_common",
    ":ruy_path",
    ":ruy_platform",
    ":ruy_profiler_instrumentation",
    ":ruy_tune",
  ]
}

source_set("ruy_have_built_path_for_avx512") {
  sources = [
    "src/ruy/have_built_path_for.h",
    "src/ruy/have_built_path_for_avx512.cc",
  ]
  configs += [ ":ruy_shared_config" ]
  deps = [
    ":ruy_opt_set",
    ":ruy_platform",
  ]
}

source_set("ruy_kernel_avx2_fma") {
  sources = [
    "src/ruy/kernel_avx2_fma.cc",
    "src/ruy/kernel_x86.h",
  ]
  configs += [
    ":ruy_shared_config",
    ":ruy_avx2_flags",
  ]
  deps = [
    ":ruy_check_macros",
    ":ruy_kernel_common",
    ":ruy_mat",
    ":ruy_mul_params",
    ":ruy_opt_set",
    ":ruy_path",
    ":ruy_platform",
    ":ruy_profiler_instrumentation",
    ":ruy_tune",
  ]
}

source_set("ruy_pack_avx2_fma") {
  sources = [
    "src/ruy/pack_avx2_fma.cc",
    "src/ruy/pack_x86.h",
  ]
  configs += [
    ":ruy_shared_config",
    ":ruy_avx2_flags",
  ]
  deps = [
    ":ruy_check_macros",
    ":ruy_mat",
    ":ruy_opt_set",
    ":ruy_pack_common",
    ":ruy_path",
    ":ruy_platform",
    ":ruy_profiler_instrumentation",
    ":ruy_tune",
  ]
}

source_set("ruy_have_built_path_for_avx2_fma") {
  sources = [
    "src/ruy/have_built_path_for.h",
    "src/ruy/have_built_path_for_avx2_fma.cc",
  ]
  configs += [
    ":ruy_shared_config",
    ":ruy_avx2_flags",
  ]
  deps = [
    ":ruy_opt_set",
    ":ruy_platform",
  ]
}

source_set("ruy_kernel_avx") {
  sources = [
    "src/ruy/kernel_avx.cc",
    "src/ruy/kernel_x86.h",
  ]
  configs += [
    ":ruy_shared_config",
    ":ruy_avx_flags",
  ]
  deps = [
    ":ruy_check_macros",
    ":ruy_kernel_common",
    ":ruy_mat",
    ":ruy_mul_params",
    ":ruy_opt_set",
    ":ruy_path",
    ":ruy_platform",
    ":ruy_profiler_instrumentation",
    ":ruy_tune",
  ]
}

source_set("ruy_pack_avx") {
  sources = [
    "src/ruy/pack_avx.cc",
    "src/ruy/pack_x86.h",
  ]
  configs += [
    ":ruy_shared_config",
    ":ruy_avx_flags",
  ]
  deps = [
    ":ruy_check_macros",
    ":ruy_mat",
    ":ruy_opt_set",
    ":ruy_pack_common",
    ":ruy_path",
    ":ruy_platform",
    ":ruy_profiler_instrumentation",
    ":ruy_tune",
  ]
}

source_set("ruy_have_built_path_for_avx") {
  sources = [
    "src/ruy/have_built_path_for.h",
    "src/ruy/have_built_path_for_avx.cc",
  ]
  configs += [
    ":ruy_shared_config",
    ":ruy_avx_flags",
  ]
  deps = [
    ":ruy_opt_set",
    ":ruy_platform",
  ]
}

source_set("ruy_kernel") {
  sources = [ "src/ruy/kernel.h" ]
  configs += [ ":ruy_shared_config" ]
  deps = [
    ":ruy_apply_multiplier",
    ":ruy_check_macros",
    ":ruy_kernel_arm",
    ":ruy_kernel_avx",
    ":ruy_kernel_avx2_fma",
    ":ruy_kernel_avx512",
    ":ruy_kernel_common",
    ":ruy_mat",
    ":ruy_matrix",
    ":ruy_mul_params",
    ":ruy_opt_set",
    ":ruy_path",
    ":ruy_platform",
    ":ruy_profiler_instrumentation",
    ":ruy_side_pair",
    ":ruy_size_util",
    ":ruy_trace",
    ":ruy_tune",
  ]
}

source_set("ruy_pack") {
  sources = [ "src/ruy/pack.h" ]
  configs += [ ":ruy_shared_config" ]
  deps = [
    ":ruy_check_macros",
    ":ruy_mat",
    ":ruy_matrix",
    ":ruy_opt_set",
    ":ruy_pack_arm",
    ":ruy_pack_avx",
    ":ruy_pack_avx2_fma",
    ":ruy_pack_avx512",
    ":ruy_pack_common",
    ":ruy_path",
    ":ruy_platform",
    ":ruy_profiler_instrumentation",
    ":ruy_trace",
    ":ruy_tune",
  ]
}

source_set("ruy_have_built_path_for") {
  sources = [ "src/ruy/have_built_path_for.h" ]
  deps = [
    ":ruy_have_built_path_for_avx",
    ":ruy_have_built_path_for_avx2_fma",
    ":ruy_have_built_path_for_avx512",
    ":ruy_platform",
  ]
}

source_set("ruy_context") {
  sources = [
    "src/ruy/context.cc",
    "src/ruy/context.h",
  ]
  configs += [ ":ruy_shared_config" ]
  deps = [
    ":ruy_allocator",
    ":ruy_check_macros",
    ":ruy_ctx",
    ":ruy_path",
    ":ruy_performance_advisory",
    ":ruy_platform",
    ":ruy_prepacked_cache",
    ":ruy_thread_pool",
    ":ruy_tune",
  ]
}

source_set("ruy_ctx") {
  sources = [
    "src/ruy/ctx.cc",
    "src/ruy/ctx.h",
    "src/ruy/ctx_impl.h",
  ]
  configs += [ ":ruy_shared_config" ]
  deps = [
    ":ruy_allocator",
    ":ruy_check_macros",
    ":ruy_cpuinfo",
    ":ruy_have_built_path_for",
    ":ruy_path",
    ":ruy_performance_advisory",
    ":ruy_platform",
    ":ruy_prepacked_cache",
    ":ruy_thread_pool",
    ":ruy_trace",
    ":ruy_tune",
  ]
}

source_set("ruy_context_get_ctx") {
  sources = [
    "src/ruy/context_get_ctx.cc",
    "src/ruy/context_get_ctx.h",
  ]
  configs += [ ":ruy_shared_config" ]
  deps = [
    ":ruy_context",
    ":ruy_ctx",
  ]
}

source_set("ruy_trmul_params") {
  sources = [ "src/ruy/trmul_params.h" ]
  configs += [ ":ruy_shared_config" ]
  deps = [
    ":ruy_instrumentation",
    ":ruy_mat",
    ":ruy_mul_params",
    ":ruy_path",
    ":ruy_side_pair",
    ":ruy_tune",
  ]
}

source_set("ruy_trmul") {
  sources = [
    "src/ruy/trmul.cc",
    "src/ruy/trmul.h",
  ]
  configs += [ ":ruy_shared_config" ]
  deps = [
    ":ruy_allocator",
    ":ruy_block_map",
    ":ruy_check_macros",
    ":ruy_cpu_cache_params",
    ":ruy_cpuinfo",
    ":ruy_ctx",
    ":ruy_denormal",
    ":ruy_mat",
    ":ruy_matrix",
    ":ruy_mul_params",
    ":ruy_opt_set",
    ":ruy_profiler_instrumentation",
    ":ruy_side_pair",
    ":ruy_size_util",
    ":ruy_thread_pool",
    ":ruy_trace",
    ":ruy_trmul_params",
    ":ruy_tune",
  ]
}

source_set("ruy_prepare_packed_matrices") {
  sources = [
    "src/ruy/prepare_packed_matrices.cc",
    "src/ruy/prepare_packed_matrices.h",
  ]
  configs += [ ":ruy_shared_config" ]
  deps = [
    ":ruy_allocator",
    ":ruy_ctx",
    ":ruy_matrix",
    ":ruy_prepacked_cache",
    ":ruy_side_pair",
    ":ruy_trace",
    ":ruy_trmul_params",
  ]
}

source_set("ruy_create_trmul_params") {
  sources = [ "src/ruy/create_trmul_params.h" ]
  configs += [ ":ruy_shared_config" ]
  deps = [
    ":ruy_allocator",
    ":ruy_check_macros",
    ":ruy_ctx",
    ":ruy_kernel",
    ":ruy_mat",
    ":ruy_mul_params",
    ":ruy_pack",
    ":ruy_path",
    ":ruy_performance_advisory",
    ":ruy_platform",
    ":ruy_side_pair",
    ":ruy_trace",
    ":ruy_trmul_params",
  ]
}

source_set("ruy_validate") {
  sources = [ "src/ruy/validate.h" ]
  configs += [ ":ruy_shared_config" ]
  deps = [
    ":ruy_check_macros",
    ":ruy_mat",
    ":ruy_mul_params",
    ":ruy_side_pair",
  ]
}

source_set("ruy_frontend") {
  sources = [
    "src/ruy/frontend.cc",
    "src/ruy/frontend.h",
  ]
  configs += [ ":ruy_shared_config" ]
  deps = [
    ":ruy_allocator",
    ":ruy_create_trmul_params",
    ":ruy_ctx",
    ":ruy_mat",
    ":ruy_mul_params",
    ":ruy_prepare_packed_matrices",
    ":ruy_profiler_instrumentation",
    ":ruy_trace",
    ":ruy_trmul",
    ":ruy_trmul_params",
    ":ruy_validate",
  ]
}

source_set("ruy_instrumentation") {
  sources = [
    "src/ruy/profiler/instrumentation.cc",
    "src/ruy/profiler/instrumentation.h",
  ]
  configs += [ ":ruy_shared_config" ]
  defines = [ "RUY_PROFILER" ]
}

source_set("ruy_profiler_instrumentation") {
  sources = [
    "src/ruy/profiler/profiler.cc",
    "src/ruy/profiler/profiler.h",
    "src/ruy/profiler/treeview.cc",
    "src/ruy/profiler/treeview.h",
  ]
  public_deps = [ ":ruy_instrumentation" ]
  configs += [ ":ruy_shared_config" ]
}

source_set("ruy") {
  sources = [
    "src/ruy/context.h",
    "src/ruy/matrix.h",
    "src/ruy/mul_params.h",
    "src/ruy/path.h",
    "src/ruy/ruy.h",
  ]
  configs += [ ":ruy_shared_config" ]

  # All the deps are public so that tflite can refer to the headers without
  # failing `gn check`.
  public_deps = [
    ":ruy_check_macros",
    ":ruy_context",
    ":ruy_context_get_ctx",
    ":ruy_denormal",
    ":ruy_frontend",
    ":ruy_instrumentation",
    ":ruy_mat",
    ":ruy_matrix",
    ":ruy_mul_params",
    ":ruy_path",
    ":ruy_platform",
    ":ruy_profiler_instrumentation",
    ":ruy_size_util",
    ":ruy_trace",
  ]

  configs -= [ "//build/config/compiler:chromium_code" ]
  configs += [ "//build/config/compiler:no_chromium_code" ]

  public_configs = [ ":ruy_include" ]
}