Skip to content

Commit

Permalink
Refactor test classes
Browse files Browse the repository at this point in the history
  • Loading branch information
j-stephan authored and bernhardmgruber committed Sep 12, 2023
1 parent 5b7eb0d commit bf976cb
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 41 deletions.
44 changes: 24 additions & 20 deletions include/alpaka/test/KernelExecutionFixture.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2022 Benjamin Worpitz, Andrea Bocci, Bernhard Manfred Gruber
/* Copyright 2023 Benjamin Worpitz, Andrea Bocci, Bernhard Manfred Gruber, Jan Stephan
* SPDX-License-Identifier: MPL-2.0
*/

Expand All @@ -25,6 +25,13 @@ namespace alpaka::test
template<typename TAcc>
class KernelExecutionFixture
{
#if defined(BOOST_COMP_GNUC) && BOOST_COMP_GNUC >= BOOST_VERSION_NUMBER(11, 0, 0) \
&& BOOST_COMP_GNUC < BOOST_VERSION_NUMBER(12, 0, 0)
// g++-11 (wrongly) believes that m_platformHost is used in an uninitialized state.
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif

public:
using Acc = TAcc;
using Dim = alpaka::Dim<Acc>;
Expand All @@ -34,25 +41,18 @@ namespace alpaka::test
using Queue = test::DefaultQueue<Device>;
using WorkDiv = WorkDivMembers<Dim, Idx>;

KernelExecutionFixture(WorkDiv workDiv)
: m_devHost{getDevByIdx(m_platformHost, 0)}
, m_device{getDevByIdx(m_platform, 0)}
, m_queue{m_device}
, m_workDiv{std::move(workDiv)}
KernelExecutionFixture(WorkDiv workDiv) : m_workDiv{std::move(workDiv)}
{
}

template<typename TExtent>
KernelExecutionFixture(TExtent const& extent)
: m_devHost{getDevByIdx(m_platformHost, 0)}
, m_device{getDevByIdx(m_platform, 0)}
, m_queue{m_device}
, m_workDiv{getValidWorkDiv<Acc>(
m_device,
extent,
Vec<Dim, Idx>::ones(),
false,
GridBlockExtentSubDivRestrictions::Unrestricted)}
: m_workDiv{getValidWorkDiv<Acc>(
m_device,
extent,
Vec<Dim, Idx>::ones(),
false,
GridBlockExtentSubDivRestrictions::Unrestricted)}
{
}

Expand All @@ -76,11 +76,15 @@ namespace alpaka::test
}

private:
PlatformCpu m_platformHost;
DevCpu m_devHost;
Platform m_platform;
Device m_device;
Queue m_queue;
PlatformCpu m_platformHost{};
DevCpu m_devHost{getDevByIdx(m_platformHost, 0)};
Platform m_platform{};
Device m_device{getDevByIdx(m_platform, 0)};
Queue m_queue{m_device};
WorkDiv m_workDiv;
#if defined(BOOST_COMP_GNUC) && BOOST_COMP_GNUC >= BOOST_VERSION_NUMBER(11, 0, 0) \
&& BOOST_COMP_GNUC < BOOST_VERSION_NUMBER(12, 0, 0)
# pragma GCC diagnostic pop
#endif
};
} // namespace alpaka::test
22 changes: 15 additions & 7 deletions include/alpaka/test/queue/QueueTestFixture.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2019 Benjamin Worpitz
/* Copyright 2023 Benjamin Worpitz, Jan Stephan
* SPDX-License-Identifier: MPL-2.0
*/

Expand All @@ -12,16 +12,24 @@ namespace alpaka::test
template<typename TDevQueue>
struct QueueTestFixture
{
#if defined(BOOST_COMP_GNUC) && BOOST_COMP_GNUC >= BOOST_VERSION_NUMBER(11, 0, 0) \
&& BOOST_COMP_GNUC < BOOST_VERSION_NUMBER(12, 0, 0)
// g++-11 (wrongly) believes that m_platform is used in an uninitialized state.
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
using Dev = std::tuple_element_t<0, TDevQueue>;
using Queue = std::tuple_element_t<1, TDevQueue>;
using Platform = alpaka::Platform<Dev>;

QueueTestFixture() : m_dev(getDevByIdx(m_platform, 0)), m_queue(m_dev)
{
}
QueueTestFixture() = default;

Platform m_platform;
Dev m_dev;
Queue m_queue;
Platform m_platform{};
Dev m_dev{getDevByIdx(m_platform, 0)};
Queue m_queue{m_dev};
#if defined(BOOST_COMP_GNUC) && BOOST_COMP_GNUC >= BOOST_VERSION_NUMBER(11, 0, 0) \
&& BOOST_COMP_GNUC < BOOST_VERSION_NUMBER(12, 0, 0)
# pragma GCC diagnostic pop
#endif
};
} // namespace alpaka::test
32 changes: 18 additions & 14 deletions test/unit/mem/copy/src/BufSlicing.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2023 Axel Huebl, Benjamin Worpitz, Jakob Krude, Bernhard Manfred Gruber, Jan Stephan, Andrea Bocci
/* Copyright 2023 Axel Hübl, Benjamin Worpitz, Jakob Krude, Bernhard Manfred Gruber, Jan Stephan, Andrea Bocci
* SPDX-License-Identifier: MPL-2.0
*/

Expand All @@ -20,6 +20,12 @@
template<typename TDim, typename TIdx, typename TAcc, typename TData, typename Vec = alpaka::Vec<TDim, TIdx>>
struct TestContainer
{
#if defined(BOOST_COMP_GNUC) && BOOST_COMP_GNUC >= BOOST_VERSION_NUMBER(11, 0, 0) \
&& BOOST_COMP_GNUC < BOOST_VERSION_NUMBER(12, 0, 0)
// g++-11 (wrongly) believes that platformHost is used in an uninitialized state.
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
using AccQueueProperty = alpaka::Blocking;
using DevQueue = alpaka::Queue<TAcc, AccQueueProperty>;
using DevAcc = alpaka::Dev<TAcc>;
Expand All @@ -33,19 +39,13 @@ struct TestContainer

using SubView = alpaka::ViewSubView<DevAcc, TData, TDim, TIdx>;

PlatformAcc const platformAcc{};
DevAcc const devAcc;
PlatformHost const platformHost{};
DevHost const devHost;
DevQueue devQueue;

// Constructor
TestContainer()
: devAcc(alpaka::getDevByIdx(platformAcc, 0))
, devHost(alpaka::getDevByIdx(platformHost, 0u))
, devQueue(devAcc)
{
}
PlatformAcc platformAcc{};
DevAcc devAcc{alpaka::getDevByIdx(platformAcc, 0)};
PlatformHost platformHost{};
DevHost devHost{alpaka::getDevByIdx(platformHost, 0u)};
DevQueue devQueue{devAcc};

TestContainer() = default;

auto createHostBuffer(Vec extents, bool indexed) -> BufHost
{
Expand Down Expand Up @@ -108,6 +108,10 @@ struct TestContainer
REQUIRE(ptrA[i] == Catch::Approx(ptrB[i]));
}
}
#if defined(BOOST_COMP_GNUC) && BOOST_COMP_GNUC >= BOOST_VERSION_NUMBER(11, 0, 0) \
&& BOOST_COMP_GNUC < BOOST_VERSION_NUMBER(12, 0, 0)
# pragma GCC diagnostic pop
#endif
};

using DataTypes = std::tuple<int, float, double>;
Expand Down

0 comments on commit bf976cb

Please sign in to comment.