Tests: Make the concurrent GEMM watchdog count finished products libeigen/eigen!3668 Co-authored-by: Rasmus Munk Larsen <rmlarsen@gmail.com>
diff --git a/test/product_threaded.cpp b/test/product_threaded.cpp index a1b1e42..54d48e3 100644 --- a/test/product_threaded.cpp +++ b/test/product_threaded.cpp
@@ -12,6 +12,7 @@ #include "main.h" #include "product_test_helpers.h" +#include <atomic> #include <condition_variable> #include <mutex> #include <thread> @@ -351,7 +352,8 @@ // Independent caller threads share one pool. The parts of one product wait for each other's packed panels, so two // products must not both hold the pool's workers: with 3 workers and 3 callers each worker used to pick up the first -// part of a different product, and no product could finish. A watchdog turns such a hang into a failure. +// part of a different product, and no product could finish. A watchdog turns such a hang into a failure. It counts +// finished products instead of timing the whole test, which takes minutes under emulation on a loaded machine. template <typename = void> void test_parallelize_gemm_concurrent_callers() { constexpr int pool_threads = 3, callers = 4, n = 192; @@ -362,19 +364,25 @@ std::mutex mutex; std::condition_variable cv; bool finished = false; + std::atomic<int> products(0); std::thread watchdog([&] { std::unique_lock<std::mutex> lock(mutex); - if (!cv.wait_for(lock, std::chrono::seconds(60), [&] { return finished; })) { - std::fprintf(stderr, "concurrent GEMM callers on one pool made no progress for 60 s\n"); - std::fflush(stderr); - std::_Exit(1); + int seen = 0; + while (!cv.wait_for(lock, std::chrono::seconds(60), [&] { return finished; })) { + const int now = products.load(); + if (now == seen) { + std::fprintf(stderr, "concurrent GEMM callers on one pool made no progress for 60 s\n"); + std::fflush(stderr); + std::_Exit(1); + } + seen = now; } }); std::vector<int> wrong(callers, 0); std::vector<std::thread> threads; for (int c = 0; c < callers; ++c) - threads.emplace_back([&wrong, c, n] { + threads.emplace_back([&wrong, &products, c, n] { // Declared in the lambda: MSVC rejects the use of an uncaptured constexpr local of the enclosing function // template, and clang warns when it is captured. constexpr int iterations = 300; @@ -383,6 +391,7 @@ for (int i = 0; i < iterations; ++i) { r.noalias() = a * b; if (r(5, 7) != float(n) * (1.f + c) || r(n - 1, n - 1) != float(n) * (1.f + c)) ++wrong[c]; + ++products; } }); for (std::thread& t : threads) t.join();