From 8dbe7c42c647e4b67f22c10a39c36b160f654ecf Mon Sep 17 00:00:00 2001 From: Andrea Bocci Date: Fri, 3 May 2024 09:06:20 +0200 Subject: [PATCH] Implement a unit test for isSingleThreadAcc and isMultiThreadAcc Implement a unit test for alpaka::isSingleThreadAcc and alpaka::isMultiThreadAcc. Signed-off-by: Andrea Bocci --- test/unit/acc/src/AccTraitTest.cpp | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 test/unit/acc/src/AccTraitTest.cpp diff --git a/test/unit/acc/src/AccTraitTest.cpp b/test/unit/acc/src/AccTraitTest.cpp new file mode 100644 index 000000000000..57ef5b2c9ef1 --- /dev/null +++ b/test/unit/acc/src/AccTraitTest.cpp @@ -0,0 +1,35 @@ +/* Copyright 2024 Andrea Bocci + * SPDX-License-Identifier: MPL-2.0 + */ + +#include +#include + +#include +#include + +TEMPLATE_LIST_TEST_CASE("isSingleThreadAcc", "[acc]", alpaka::test::TestAccs) +{ + using Acc = TestType; + + // Check that both traits are defined, and that only one is true. + REQUIRE(alpaka::isSingleThreadAcc != alpaka::isMultiThreadAcc); + + auto const platform = alpaka::Platform{}; + auto const dev = alpaka::getDevByIdx(platform, 0); + auto const devProps = alpaka::getAccDevProps(dev); + + // Compare the runtime properties with the compile time trait. + INFO("Accelerator: " << alpaka::core::demangled); + if constexpr(alpaka::isSingleThreadAcc) + { + // Require a single thread per block. + REQUIRE(devProps.m_blockThreadCountMax == 1); + } + else + { + // Assume multiple threads per block, but allow a single thread per block. + // For example, the AccCpuOmp2Threads accelerator may report a single thread on a single core system. + REQUIRE(devProps.m_blockThreadCountMax >= 1); + } +}