diff --git a/Dockerfile b/Dockerfile index 151fd6ba..a3e09394 100644 --- a/Dockerfile +++ b/Dockerfile @@ -202,21 +202,28 @@ RUN echo 1000 > /proc/self/oom_score_adj 2>/dev/null || true; \ # ------------------------------------------------------------------------------------------- test FROM build AS test ARG JOBS= +# Tests at a time when it should differ from JOBS (below). +ARG TEST_JOBS= +# A factor on every test's CPU budget (RAD_TEST_CPU_BUDGET_SCALE, tests/rad_test.h), for a host +# slower per thread than the one the budgets were set on: a VM on an EPYC 7302 spends 4.6x the +# quoted CPU time on tokenizer_test's reference pass. +ARG TEST_CPU_BUDGET_SCALE= # Host-only: a build container has no /dev/kfd. The `gpu`-labelled tests (the *_card entries, # r4d_selftest, kbench) run against a card from this stage: # docker buildx build --target build -t radiance-build . && docker run --rm \ # --device /dev/kfd --device /dev/dri --security-opt seccomp=unconfined radiance-build \ # ctest --test-dir /build -L gpu --output-on-failure -# Tests run JOBS at a time (default one per two hardware threads, about one per core on an SMT -# machine: the per-binary CPU budgets in tests/CMakeLists.txt hold for tests that do not share a -# core); the `perf` entries, which assert wall-clock costs, run alone (RUN_SERIAL). The build +# Tests run TEST_JOBS at a time, else JOBS (default one per two hardware threads, about one per +# core on an SMT machine: the per-binary CPU budgets in tests/CMakeLists.txt hold for tests that do +# not share a core); the `perf` entries, which assert wall-clock costs, run alone (RUN_SERIAL). The build # sandbox forbids io_uring, so avx_check skips its file-backed gather case, and perf_event_open, so # the tests that bound work count CPU time rather than instructions (tests/work_counter.h). The # `oot` suite (every shipped plugin rebuilt against the installed package) repeats this stage's # whole compile, so it runs from the development tree instead (tests/oot_plugins.sh). RUN echo 1000 > /proc/self/oom_score_adj 2>/dev/null || true; \ bash /src/docker/llvm-check.sh /build \ - && ctest --test-dir /build -LE 'gpu|oot' -j"${JOBS:-$(( ($(nproc) + 1) / 2 ))}" --output-on-failure \ + && RAD_TEST_CPU_BUDGET_SCALE="${TEST_CPU_BUDGET_SCALE}" \ + ctest --test-dir /build -LE 'gpu|oot' -j"${TEST_JOBS:-${JOBS:-$(( ($(nproc) + 1) / 2 ))}}" --output-on-failure \ && touch /build/host-tests-passed # ----------------------------------------------------------------------------------------- rootfs diff --git a/docker/build.sh b/docker/build.sh index 5a632e7e..1befd3ca 100755 --- a/docker/build.sh +++ b/docker/build.sh @@ -11,6 +11,9 @@ # docker/build.sh -r COMMIT another commit # docker/build.sh -t 'gfx1200;gfx1201' other GPU architectures (default gfx1201) # docker/build.sh -j 8 fewer compile jobs, for a host that is also serving +# docker/build.sh -J 4 fewer tests at a time (default: the compile jobs) +# docker/build.sh -B 5 multiply every test's CPU budget, for a host slower per +# thread than the one the budgets were set on # docker/build.sh --target build stop at a stage (tagged radiance-), e.g. for the # GPU test suites # @@ -22,6 +25,8 @@ REV=HEAD HOST= TARGETS=gfx1201 JOBS= +TEST_JOBS= +BUDGET_SCALE= STAGE= while [ $# -gt 0 ]; do case "$1" in @@ -29,6 +34,8 @@ while [ $# -gt 0 ]; do -r) shift; REV="$1" ;; -t) shift; TARGETS="$1" ;; -j) shift; JOBS="$1" ;; + -J) shift; TEST_JOBS="$1" ;; + -B) shift; BUDGET_SCALE="$1" ;; --target) shift; STAGE="$1" ;; *) echo "docker/build.sh: unknown option $1" >&2; exit 2 ;; esac @@ -45,6 +52,7 @@ else TAGS="-t radiance:$VERSION -t radiance:$SHA -t radiance:latest" fi CMD="docker buildx build --load --build-arg GPU_TARGETS='$TARGETS' --build-arg JOBS='$JOBS'" +CMD="$CMD --build-arg TEST_JOBS='$TEST_JOBS' --build-arg TEST_CPU_BUDGET_SCALE='$BUDGET_SCALE'" CMD="$CMD --build-arg VERSION='$VERSION' --build-arg REVISION='$SHA' $TAGS -" echo "radiance $VERSION ($SHA) for $TARGETS${HOST:+ on $HOST}${STAGE:+, stage $STAGE}" diff --git a/docs/DOCKER.md b/docs/DOCKER.md index d57937e1..152dbfbc 100644 --- a/docs/DOCKER.md +++ b/docs/DOCKER.md @@ -23,6 +23,8 @@ the build if a file in the image cannot be traced to a package. docker/build.sh # HEAD, tagged radiance:, radiance:, radiance:latest docker/build.sh -s gpu-host # stream the commit over ssh; gpu-host builds and keeps the image docker/build.sh -j 8 # cap compile jobs (a device kernel takes 2-3 GB under hipcc) +docker/build.sh -J 4 # tests at a time (default: the compile jobs) +docker/build.sh -B 5 # every test's CPU budget times 5, for a host slower per thread docker/build.sh -t 'gfx1200;gfx1201' # GPU architectures to compile kernels for (default gfx1201) docker/build.sh -r # any other commit docker/build.sh --target build # stop at a stage, tagged radiance- diff --git a/tests/harness_test.cpp b/tests/harness_test.cpp index e2245705..df74d726 100644 --- a/tests/harness_test.cpp +++ b/tests/harness_test.cpp @@ -23,7 +23,7 @@ struct Run { * inherited from ctest. */ Run fixture(const std::string& args, const std::string& env = "") { const std::string cmd = "env -u RAD_TEST_FILTER -u RAD_TEST_STRICT -u RAD_TEST_LEVEL " - "-u RAD_TEST_CPU_BUDGET " + env + " '" RAD_HARNESS_FIXTURE "' " + + "-u RAD_TEST_CPU_BUDGET -u RAD_TEST_CPU_BUDGET_SCALE " + env + " '" RAD_HARNESS_FIXTURE "' " + args + " 2>&1"; Run r; FILE* p = popen(cmd.c_str(), "r"); @@ -194,6 +194,12 @@ TEST(a_binary_over_its_cpu_budget_fails) { CHECK(has(r.out, "slowest: burns_cpu ")); r = fixture("passes_one", "RAD_TEST_CPU_BUDGET=60"); CHECK_EQ(r.status, 0); + /* A slower host scales every budget by one factor. */ + r = fixture("burns_cpu passes_one", "RAD_TEST_CPU_BUDGET=0.05 RAD_TEST_CPU_BUDGET_SCALE=2"); + CHECK_EQ(r.status, 1); + CHECK(has(r.out, "over its budget of 0.1 s")); + r = fixture("burns_cpu passes_one", "RAD_TEST_CPU_BUDGET=0.05 RAD_TEST_CPU_BUDGET_SCALE=100"); + CHECK_EQ(r.status, 0); } /* A command line the harness does not understand is refused rather than read as a filter. */ diff --git a/tests/rad_test.h b/tests/rad_test.h index 426064a8..5872ad56 100644 --- a/tests/rad_test.h +++ b/tests/rad_test.h @@ -14,6 +14,8 @@ * RAD_TEST_TMPDIR where tmpdir() is made, before $TMPDIR and /tmp * RAD_TEST_CPU_BUDGET seconds of process CPU time the binary may spend; over it, it fails * tests/CMakeLists.txt sets the last three for every ctest entry. + * RAD_TEST_CPU_BUDGET_SCALE a factor on that budget, for a host slower per thread than the + * one the budgets were set on; unset or 0 is 1 * * Exit status: 1 when a check failed (an exception escaping a case is a failed check), 77 when * nothing failed and no check ran, 2 for a command line it does not understand, else 0. 77 is @@ -288,7 +290,9 @@ inline int run_all(int argc, char** argv) { * so a slow case or a spinning thread pool is caught when it lands. CPU time rather than wall * time, so a loaded machine does not fail a correct binary. */ if (const char* b = std::getenv("RAD_TEST_CPU_BUDGET")) { - const double budget = std::atof(b); + double budget = std::atof(b); + if (const char* s = std::getenv("RAD_TEST_CPU_BUDGET_SCALE"); s && std::atof(s) > 0) + budget *= std::atof(s); if (budget > 0 && cpu > budget && rc != 1) { fprintf(stderr, " FAIL the binary spent %.2f s of CPU, over its budget of %g s " "(RAD_TEST_CPU_BUDGET)\n", cpu, budget);