• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""Build definitions for Ruy."""
2
3# Helper for ruy_copts().
4# Returns warnings flags to use for all ruy code.
5def ruy_copts_warnings():
6    return select({
7        "//tools/cc_target_os:windows": [
8            # We run into trouble on Windows toolchains with warning flags,
9            # as mentioned in the comments below on each flag.
10            # We could be more aggressive in enabling supported warnings on each
11            # Windows toolchain, but we compromise with keeping BUILD files simple
12            # by limiting the number of config_setting's.
13        ],
14        "//conditions:default": [
15            "-Wall",
16            # Some clang-based Windows toolchains have more warnings in -Wextra.
17            "-Wextra",
18            # Warn on preprocessor expansion of an undefined token, e.g. catching
19            # typos such as `#ifdef __linus__` instead of `#ifdef __linux__`.
20            # Not supported by MSVC.
21            "-Wundef",
22        ],
23    })
24
25# Helper for ruy_copts().
26# Returns flags to use to enable NEON if applicable, for all ruy code.
27def ruy_copts_neon():
28    return select({
29        # OK to crash old devices that lack full NEON support.
30        # No need to pass -mfloat-abi=softfp, that is already on.
31        "//ruy:arm32_assuming_neon": [
32            "-mfpu=neon",
33        ],
34        "//conditions:default": [],
35    })
36
37# Helper for ruy_copts().
38# Returns optimization flags to use for all ruy code.
39def ruy_copts_optimize():
40    return select({
41        # On some toolchains, typically mobile, "-c opt" is interpreted by
42        # default as "optimize for size, not for speed". For Ruy code,
43        # optimizing for speed is the better compromise, so we override that.
44        # Careful to keep debug builds debuggable, whence the select based
45        # on the compilation mode.
46        "//ruy:do_not_want_O3": [],
47        "//conditions:default": ["-O3"],
48    })
49
50# Returns compiler flags to use for all ruy code.
51def ruy_copts():
52    return ruy_copts_warnings() + ruy_copts_neon() + ruy_copts_optimize()
53
54def ruy_copts_avx():
55    return select({
56        "//ruy:x86_64_and_not_msvc": ["-mavx"],
57        "//tools/cc_target_os:windows_msvc": ["/arch:AVX"],
58        "//conditions:default": [],
59    })
60
61def ruy_copts_avx2_fma():
62    return select({
63        "//ruy:x86_64_and_not_msvc": ["-mavx2", "-mfma"],
64        "//tools/cc_target_os:windows_msvc": ["/arch:AVX2"],
65        "//conditions:default": [],
66    })
67
68def ruy_copts_avx512():
69    # In some clang-based toolchains, in the default compilation mode (not -c opt),
70    # heavy spillage in the AVX512 kernels results in stack frames > 50k. This issue does not exist
71    # in optimized builds (-c opt).
72    return select({
73        "//ruy:x86_64_and_not_msvc": ["$(STACK_FRAME_UNLIMITED)", "-mavx512f", "-mavx512vl", "-mavx512cd", "-mavx512bw", "-mavx512dq"],
74        "//tools/cc_target_os:windows_msvc": ["/arch:AVX512"],
75        "//conditions:default": [],
76    })
77