| 1 | # SIMD Tests |
| 2 | |
| 3 | To execute the simd testsuite, call `make check-simd`, typically with `-j N` |
| 4 | argument. |
| 5 | |
| 6 | For more control over verbosity, compiler flags, and use of a simulator, use |
| 7 | the environment variables documented below. |
| 8 | |
| 9 | ## Environment variables |
| 10 | |
| 11 | ### `target_list` |
| 12 | |
| 13 | Similar to dejagnu target lists: E.g. |
| 14 | `target_list="unix{-march=sandybridge,-march=native/-ffast-math,-march=native/-ffinite-math-only}"` |
| 15 | would create three subdirs in `testsuite/simd/` to run the complete simd |
| 16 | testsuite first with `-march=sandybridge`, then with `-march=native |
| 17 | -ffast-math`, and finally with `-march=native -ffinite-math-only`. |
| 18 | |
| 19 | |
| 20 | ### `CHECK_SIMD_CONFIG` |
| 21 | |
| 22 | This variable can be set to a path to a file which is equivalent to a dejagnu |
| 23 | board. The file needs to be a valid `sh` script since it is sourced from the |
| 24 | `scripts/check_simd` script. Its purpose is to set the `target_list` variable |
| 25 | depending on `$target_triplet` (or whatever else makes sense for you). Example: |
| 26 | |
| 27 | ```sh |
| 28 | case "$target_triplet" in |
| 29 | x86_64-*) |
| 30 | target_list="unix{-march=sandybridge,-march=skylake-avx512,-march=native/-ffast-math,-march=athlon64,-march=core2,-march=nehalem,-march=skylake,-march=native/-ffinite-math-only,-march=knl}" |
| 31 | ;; |
| 32 | |
| 33 | powerpc64le-*) |
| 34 | define_target power7 "-mcpu=power7 -static" "$HOME/bin/run_on_gccfarm gcc112" |
| 35 | define_target power8 "-mcpu=power8 -static" "$HOME/bin/run_on_gccfarm gcc112" |
| 36 | define_target power9 "-mcpu=power9 -static" "$HOME/bin/run_on_gccfarm gcc135" |
| 37 | target_list="power7 power8 power9{,-ffast-math}" |
| 38 | ;; |
| 39 | |
| 40 | powerpc64-*) |
| 41 | define_target power7 "-mcpu=power7 -static" "$HOME/bin/run_on_gccfarm gcc110" |
| 42 | define_target power8 "-mcpu=power8 -static" "$HOME/bin/run_on_gccfarm gcc110" |
| 43 | target_list="power7 power8{,-ffast-math}" |
| 44 | ;; |
| 45 | esac |
| 46 | ``` |
| 47 | |
| 48 | The `unix` target is pre-defined to have no initial flags and no simulator. Use |
| 49 | the `define_target(name, flags, sim)` function to define your own targets for |
| 50 | the `target_list` variable. In the example above `define_target power7 |
| 51 | "-mcpu=power7 -static" "$HOME/bin/run_on_gccfarm gcc112"` defines the target |
| 52 | `power7` which always uses the flags `-mcpu=power7` and `-static` when |
| 53 | compiling tests and prepends `$HOME/bin/run_on_gccfarm gcc112` to test |
| 54 | executables. In `target_list` you can now use the name `power7`. E.g. |
| 55 | `target_list="power7 power7/-ffast-math"` or its shorthand |
| 56 | `target_list="power7{,-ffast-math}"`. |
| 57 | |
| 58 | |
| 59 | ### `DRIVEROPTS` |
| 60 | |
| 61 | This variable affects the `Makefile`s generated per target (as defined above). |
| 62 | It's a string of flags that are prepended to the `driver.sh` invocation which |
| 63 | builds and runs the tests. You `cd` into a simd test subdir and use `make help` |
| 64 | to see possible options and a list of all valid targets. |
| 65 | |
| 66 | ``` |
| 67 | use DRIVEROPTS=<options> to pass the following options: |
| 68 | -q, --quiet Disable same-line progress output (default if stdout is |
| 69 | not a tty). |
| 70 | -p, --percentage Add percentage to default same-line progress output. |
| 71 | -v, --verbose Print one line per test and minimal extra information on |
| 72 | failure. |
| 73 | -vv Print all compiler and test output. |
| 74 | -k, --keep-failed Keep executables of failed tests. |
| 75 | --sim <executable> Path to an executable that is prepended to the test |
| 76 | execution binary (default: the value of |
| 77 | GCC_TEST_SIMULATOR). |
| 78 | --timeout-factor <x> |
| 79 | Multiply the default timeout with x. |
| 80 | -x, --run-expensive Compile and run tests marked as expensive (default: |
| 81 | true if GCC_TEST_RUN_EXPENSIVE is set, false otherwise). |
| 82 | -o <pattern>, --only <pattern> |
| 83 | Compile and run only tests matching the given pattern. |
| 84 | ``` |
| 85 | |
| 86 | |
| 87 | ### `TESTFLAGS` |
| 88 | |
| 89 | This variable also affects the `Makefile`s generated per target. It's a list of |
| 90 | compiler flags that are appended to `CXXFLAGS`. |
| 91 | |
| 92 | |
| 93 | ### `GCC_TEST_SIMULATOR` |
| 94 | |
| 95 | If `--sim` is not passed via `DRIVEROPTS`, then this variable is prepended to |
| 96 | test invocations. If a simulator was defined via the `CHECK_SIMD_CONFIG` |
| 97 | script, then then generated `Makefile` sets the `GCC_TEST_SIMULATOR` variable. |
| 98 | |
| 99 | |
| 100 | ### `GCC_TEST_RUN_EXPENSIVE` |
| 101 | |
| 102 | If set to any non-empty string, run tests marked as expensive, otherwise treat |
| 103 | these tests as `UNSUPPORTED`. |
| 104 | |
| 105 | |
| 106 | ## Writing new tests |
| 107 | |
| 108 | A test starts with the copyright header, directly followed by directives |
| 109 | influencing the set of tests to generate and whether the test driver should |
| 110 | expect a failure. |
| 111 | |
| 112 | Then the test must at least `#include "bits/verify.h"`, which provides `main` |
| 113 | and declares a `template <typename V> void test()` function, which the test has |
| 114 | to define. The template parameter is set to `simd<T, Abi>` type where `T` and |
| 115 | `Abi` are determined by the type and ABI subset dimensions. |
| 116 | |
| 117 | The `test()` functions are typically implemented using the `COMPARE(x, |
| 118 | reference)`, `VERIFY(boolean)`, and `ULP_COMPARE(x, reference, |
| 119 | allowed_distance)` macros. |
| 120 | |
| 121 | ### Directives |
| 122 | |
| 123 | * `// skip: <type pattern> <ABI subset pattern> <target triplet pattern> |
| 124 | <CXXFLAGS pattern>` |
| 125 | If all patterns match, the test is silently skipped. |
| 126 | |
| 127 | * `// only: <type pattern> <ABI subset pattern> <target triplet pattern> |
| 128 | <CXXFLAGS pattern>` |
| 129 | If any pattern doesn't match, the test is silently skipped. |
| 130 | |
| 131 | * `// expensive: <type pattern> <ABI subset pattern> <target triplet pattern> |
| 132 | <CXXFLAGS pattern>` |
| 133 | If all patterns match, the test is `UNSUPPORTED` unless expensive tests are |
| 134 | enabled. |
| 135 | |
| 136 | * `// xfail: run|compile <type pattern> <ABI subset pattern> <target triplet |
| 137 | pattern> <CXXFLAGS pattern>` |
| 138 | If all patterns match, test compilation or execution is expected to fail. The |
| 139 | test then shows as "XFAIL: ...". If the test passes, the test shows "XPASS: |
| 140 | ...". |
| 141 | |
| 142 | * `timeout: <number>` |
| 143 | Set the timeout of this test to `<number>` seconds. |
| 144 | |
| 145 | * `timeout-factor: <number>` |
| 146 | Multiply the default timeout with `<number>`. |
| 147 | |
| 148 | All patterns except `timeout` and `timeout-factor` are matched via |
| 149 | ```sh |
| 150 | case '<test context>' in |
| 151 | <pattern>) |
| 152 | # treat as match |
| 153 | ;; |
| 154 | esac |
| 155 | ``` |
| 156 | The `<CXXFLAGS pattern>` implicitly adds a `*` wildcard before and after the |
| 157 | pattern. Thus, the `CXXFLAGS` pattern matches a substring and all other |
| 158 | patterns require a full match. |
| 159 | |
| 160 | Examples: |
| 161 | ```cpp |
| 162 | // The test is only valid for floating-point types: |
| 163 | // only: float|double|ldouble * * * |
| 164 | |
| 165 | // Skip the test for long double for all powerpc64* targets: |
| 166 | // skip: ldouble * powerpc64* * |
| 167 | |
| 168 | // The test is expected to unconditionally fail on execution: |
| 169 | // xfail: run * * * * |
| 170 | |
| 171 | // ABI subsets 1-9 are considered expensive: |
| 172 | // expensive: * [1-9] * * |
| 173 | ``` |
| 174 | |
| 175 | |
| 176 | ## Implementation sketch |
| 177 | |
| 178 | * `scripts/create_testsuite_files` collects all `*.c` and `*.cc` files with |
| 179 | `simd/tests/` in their path into the file `testsuite_file_simd` (and at the |
| 180 | same time removes them from `testsuite_files`. |
| 181 | |
| 182 | * The `check-simd` target in `testsuite/Makefile.am` calls |
| 183 | `scripts/check_simd`. This script calls |
| 184 | `testsuite/experimental/simd/generate_makefile.sh` to generate `Makefile`s in |
| 185 | all requested subdirectories. The subdirectories are communicated back to the |
| 186 | make target via a `stdout` pipe. The `check-simd` rule then spawns sub-make |
| 187 | in these subdirectories. Finally it collects all summaries |
| 188 | (`simd_testsuite.sum`) to present them at the end of the rule. |
| 189 | |
| 190 | * The generated Makefiles define targets for each file in `testsuite_file_simd` |
| 191 | (you can edit this file after it was generated, though that's not |
| 192 | recommended) while adding two test dimensions: type and ABI subset. The type |
| 193 | is a list of all arithmetic types, potentially reduced via `only` and/or |
| 194 | `skip` directives in the test's source file. The ABI subset is a number |
| 195 | between 0 and 9 (inclusive) mapping to a set of `simd_abi`s in |
| 196 | `testsuite/experimental/simd/tests/bits/verify.h` (`iterate_abis()`). The |
| 197 | tests are thus potentially compiled 170 (17 arithmetic types * 10 ABI |
| 198 | subsets) times. This is necessary to limit the memory usage of GCC to |
| 199 | reasonable numbers and keep the compile time below 1 minute (per compiler |
| 200 | invocation). |
| 201 | |
| 202 | * When `make` executes in the generated subdir, the `all` target depends on |
| 203 | building and running all tests via `testsuite/experimental/simd/driver.sh` |
| 204 | and collecting their logs into a `simd_testsuite.log` and then extracting |
| 205 | `simd_testsuite.sum` from it. |
| 206 | |
| 207 | * The `driver.sh` script builds and runs the test, parses the compiler and test |
| 208 | output, and prints progress information to the terminal. |
| 209 | |
| 210 | ## Appendix |
| 211 | |
| 212 | ### `run_on_gccfarm` script |
| 213 | |
| 214 | ```sh |
| 215 | #!/bin/sh |
| 216 | usage() { |
| 217 | cat <<EOF |
| 218 | Usage $0 <hostname> <executable> [arguments] |
| 219 | |
| 220 | Copies <executable> to $host, executes it and cleans up again. |
| 221 | EOF |
| 222 | } |
| 223 | |
| 224 | [ $# -lt 2 ] && usage && exit 1 |
| 225 | case "$1" in |
| 226 | -h|--help) |
| 227 | usage |
| 228 | exit |
| 229 | ;; |
| 230 | esac |
| 231 | |
| 232 | host="$1" |
| 233 | exe="$2" |
| 234 | shift 2 |
| 235 | |
| 236 | # Copy executable locally to strip it before scp to remote host |
| 237 | local_tmpdir=$(mktemp -d) |
| 238 | cp "$exe" $local_tmpdir |
| 239 | cd $local_tmpdir |
| 240 | exe="${exe##*/}" |
| 241 | powerpc64le-linux-gnu-strip "$exe" |
| 242 | |
| 243 | ssh_controlpath=~/.local/run_on_gccfarm/$host |
| 244 | if [ ! -S $ssh_controlpath ]; then |
| 245 | mkdir -p ~/.local/run_on_gccfarm |
| 246 | ( |
| 247 | flock -n 9 |
| 248 | if [ ! -S $ssh_controlpath ]; then |
| 249 | ssh -o ControlMaster=yes -o ControlPath=$ssh_controlpath -o ControlPersist=10m $host.fsffrance.org true |
| 250 | fi |
| 251 | ) 9> ~/.local/run_on_gccfarm/lockfile |
| 252 | fi |
| 253 | opts="-o ControlPath=$ssh_controlpath" |
| 254 | |
| 255 | remote_tmpdir=$(ssh $opts $host.fsffrance.org mktemp -d -p .) |
| 256 | scp $opts -C -q "$exe" $host.fsffrance.org:$remote_tmpdir/ |
| 257 | cd |
| 258 | rm -r "$local_tmpdir" & |
| 259 | ssh $opts $host.fsffrance.org $remote_tmpdir/$exe "$@" |
| 260 | ret=$? |
| 261 | ssh $opts $host.fsffrance.org rm -r $remote_tmpdir & |
| 262 | exit $ret |
| 263 | ``` |