From 1b8710ec574279564f624eb868f5d756c4558f6e Mon Sep 17 00:00:00 2001 From: Andrea Bocci Date: Mon, 19 Aug 2024 09:42:06 +0200 Subject: [PATCH] Fix boolean values after copying from device to host --- test/unit/exec/src/Once.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/unit/exec/src/Once.cpp b/test/unit/exec/src/Once.cpp index 682140db7f6..1c9461f3381 100644 --- a/test/unit/exec/src/Once.cpp +++ b/test/unit/exec/src/Once.cpp @@ -33,6 +33,13 @@ class KernelOncePerGrid } }; +// MSVC does not seem to recognize as "true" a value set to "true" in device code, +// so force all object representations different from zero to evaluate as "true". +inline void fixBooleanValue(bool& value) +{ + value = reinterpret_cast(value) == 0x00 ? false : true; +} + TEMPLATE_LIST_TEST_CASE("oncePerGrid", "[exec]", alpaka::test::TestAccs) { using Host = alpaka::DevCpu; @@ -66,6 +73,7 @@ TEMPLATE_LIST_TEST_CASE("oncePerGrid", "[exec]", alpaka::test::TestAccs) alpaka::exec(queue, workDiv, kernel, std::data(status), std::data(value)); alpaka::wait(queue); + fixBooleanValue(*status); REQUIRE(*status == true); REQUIRE(*value == 1); } @@ -130,6 +138,7 @@ TEMPLATE_LIST_TEST_CASE("oncePerBlock", "[exec]", alpaka::test::TestAccs) alpaka::exec(queue, workDiv, kernel, std::data(status), std::data(value)); alpaka::wait(queue); + fixBooleanValue(*status); REQUIRE(*status == true); REQUIRE(*value == blocks); }