From c3eebea23127f4f96992537329cb983e0daceda1 Mon Sep 17 00:00:00 2001 From: Simeon Ehrig Date: Mon, 27 May 2024 16:57:40 +0200 Subject: [PATCH] add buffer visibility tests --- include/alpaka/acc/Tag.hpp | 1 + include/alpaka/mem/Visibility.hpp | 3 +- test/unit/mem/src/Visibility.cpp | 67 +++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 1 deletion(-) diff --git a/include/alpaka/acc/Tag.hpp b/include/alpaka/acc/Tag.hpp index f7880afd6f15..73575daa0a4d 100644 --- a/include/alpaka/acc/Tag.hpp +++ b/include/alpaka/acc/Tag.hpp @@ -31,6 +31,7 @@ namespace alpaka CREATE_ACC_TAG(TagGpuCudaRt); CREATE_ACC_TAG(TagGpuHipRt); CREATE_ACC_TAG(TagGpuSyclIntel); +#undef CREATE_ACC_TAG namespace trait { diff --git a/include/alpaka/mem/Visibility.hpp b/include/alpaka/mem/Visibility.hpp index f5cf7c0d024a..349beb719e20 100644 --- a/include/alpaka/mem/Visibility.hpp +++ b/include/alpaka/mem/Visibility.hpp @@ -34,6 +34,7 @@ namespace alpaka CREATE_MEM_VISIBILITY(MemVisibleGpuCudaRt); CREATE_MEM_VISIBILITY(MemVisibleGpuHipRt); CREATE_MEM_VISIBILITY(MemVisibleGpuSyclIntel); +#undef CREATE_MEM_VISIBILITY namespace trait { @@ -62,7 +63,7 @@ namespace alpaka typename = std::enable_if_t< alpaka::isPlatform> || alpaka::isDevice> || alpaka::isAccelerator> || alpaka::internal::isView>>> - [[maybe_unused]] static std::string getMemVisiblityName() + inline std::string getMemVisiblityName() { using MemVisibilityType = typename alpaka::trait::MemVisibility>::type; if constexpr(alpaka::meta::isList) diff --git a/test/unit/mem/src/Visibility.cpp b/test/unit/mem/src/Visibility.cpp index 2a46ab35577a..097f7ec60b88 100644 --- a/test/unit/mem/src/Visibility.cpp +++ b/test/unit/mem/src/Visibility.cpp @@ -174,3 +174,70 @@ TEMPLATE_LIST_TEST_CASE("testMemView", "[mem][visibility]", EnabledTagTagMemVisi STATIC_REQUIRE_FALSE(alpaka::hasSameMemView(plt2, data_view1)); } } + +TEMPLATE_LIST_TEST_CASE("testMemBuf", "[mem][visibility]", EnabledTagTagMemVisibilityList) +{ + using Tag1 = std::tuple_element_t<0, std::tuple_element_t<0, TestType>>; + using ExpectedMemVisibilityForTag1 = std::tuple_element_t<1, std::tuple_element_t<0, TestType>>; + using Tag2 = std::tuple_element_t<0, std::tuple_element_t<1, TestType>>; + using ExpectedMemVisibilityForTag2 = std::tuple_element_t<1, std::tuple_element_t<1, TestType>>; + + SUCCEED( + "Tag1: " << Tag1::get_name() << " + " << ExpectedMemVisibilityForTag1::get_name() + << "\nTag2: " << Tag2::get_name() << " + " << ExpectedMemVisibilityForTag1::get_name()); + + constexpr Idx data_size = 10; + + using Acc1 = alpaka::TagToAcc; + using Acc2 = alpaka::TagToAcc; + + auto const plt1 = alpaka::Platform{}; + auto const plt2 = alpaka::Platform{}; + + auto const dev1 = alpaka::getDevByIdx(plt1, 0); + auto const dev2 = alpaka::getDevByIdx(plt2, 0); + + using Vec1D = alpaka::Vec, Idx>; + Vec1D const extents(Vec1D::all(data_size)); + + // we need only to test the first tag, because the second tag contains the same acc's + auto buf1 = alpaka::allocBuf(dev1, extents); + + STATIC_REQUIRE(std::is_same_v< + typename alpaka::trait::MemVisibility::type, + std::tuple>); + + STATIC_REQUIRE(alpaka::hasSameMemView(plt1, buf1)); + + if constexpr(!std::is_same_v) + { + alpaka::Queue queue1(dev1); + + auto buf1Async = alpaka::allocAsyncBuf(queue1, extents); + + alpaka::wait(queue1); + + STATIC_REQUIRE(std::is_same_v< + typename alpaka::trait::MemVisibility::type, + std::tuple>); + + STATIC_REQUIRE(alpaka::hasSameMemView(plt1, buf1Async)); + } + + if constexpr(isCpuTag::value && alpaka::hasMappedBufSupport>) + { + auto mappedBuffer = alpaka::allocMappedBuf, float, Idx>(dev1, plt2, extents); + + using expectedMappedBufferMemView + = alpaka::meta::Unique>; + + STATIC_REQUIRE(std::is_same_v< + typename alpaka::trait::MemVisibility::type, + expectedMappedBufferMemView>); + + STATIC_REQUIRE(alpaka::hasSameMemView(plt1, mappedBuffer)); + STATIC_REQUIRE(alpaka::hasSameMemView(plt2, mappedBuffer)); + STATIC_REQUIRE(alpaka::hasSameMemView(dev1, mappedBuffer)); + STATIC_REQUIRE(alpaka::hasSameMemView(dev2, mappedBuffer)); + } +}