Skip to content

Commit

Permalink
Fix boolean values after copying from device to host
Browse files Browse the repository at this point in the history
  • Loading branch information
fwyzard authored and psychocoderHPC committed Aug 27, 2024
1 parent 621e8f9 commit 1b8710e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions test/unit/exec/src/Once.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char const&>(value) == 0x00 ? false : true;
}

TEMPLATE_LIST_TEST_CASE("oncePerGrid", "[exec]", alpaka::test::TestAccs)
{
using Host = alpaka::DevCpu;
Expand Down Expand Up @@ -66,6 +73,7 @@ TEMPLATE_LIST_TEST_CASE("oncePerGrid", "[exec]", alpaka::test::TestAccs)
alpaka::exec<Acc>(queue, workDiv, kernel, std::data(status), std::data(value));
alpaka::wait(queue);

fixBooleanValue(*status);
REQUIRE(*status == true);
REQUIRE(*value == 1);
}
Expand Down Expand Up @@ -130,6 +138,7 @@ TEMPLATE_LIST_TEST_CASE("oncePerBlock", "[exec]", alpaka::test::TestAccs)
alpaka::exec<Acc>(queue, workDiv, kernel, std::data(status), std::data(value));
alpaka::wait(queue);

fixBooleanValue(*status);
REQUIRE(*status == true);
REQUIRE(*value == blocks);
}

0 comments on commit 1b8710e

Please sign in to comment.