11 #include <catch2/catch_test_macros.hpp>
14 #include <type_traits>
19 template<
typename TElem,
typename TDim,
typename TIdx,
typename TDev,
typename TView>
30 "The device type of the view has to be equal to the specified one.");
35 REQUIRE(dev ==
getDev(view));
42 "The dimensionality of the view has to be equal to the specified one.");
49 "The element type of the view has to be equal to the specified one.");
59 auto const pitchMinimum = alpaka::detail::calculatePitchesFromExtents<TElem>(extent);
62 for(TIdx i = TDim::value; i >
static_cast<TIdx
>(0u); --i)
64 REQUIRE(pitchView[i - 1] >= pitchMinimum[i - 1]);
72 static_assert(std::is_pointer_v<NativePtr>,
"The value returned by getPtrNative has to be a pointer.");
74 std::is_const_v<std::remove_pointer_t<NativePtr>>,
75 "The value returned by getPtrNative has to be const when the view is const.");
80 TElem
const*
const invalidPtr(
nullptr);
99 "The idx type of the view has to be equal to the specified one.");
107 template<
typename TAcc,
typename TIter>
109 TAcc
const& acc [[maybe_unused]],
113 std::uint8_t
const&
byte)
const
115 constexpr
auto elemSizeInByte =
static_cast<unsigned>(
sizeof(decltype(*
begin)));
116 for(
auto it =
begin; it !=
end; ++it)
118 auto const& elem = *it;
119 auto const pBytes =
reinterpret_cast<std::uint8_t const*
>(&elem);
120 for(
unsigned i = 0; i < elemSizeInByte; ++i)
122 if(pBytes[i] !=
byte)
124 printf(
"Byte at offset %u is different: %u != %u\n", i,
unsigned{pBytes[i]},
unsigned{
byte});
132 template<
typename TAcc,
typename TView>
147 # pragma GCC diagnostic push
148 # pragma GCC diagnostic ignored "-Wfloat-equal"
153 template<
typename TAcc,
typename TIterA,
typename TIterB>
155 TAcc
const& acc [[maybe_unused]],
161 for(; beginA != endA; ++beginA, ++beginB)
164 # pragma clang diagnostic push
165 # pragma clang diagnostic ignored "-Wfloat-equal"
169 # pragma clang diagnostic pop
175 # pragma GCC diagnostic pop
178 template<
typename TAcc,
typename TViewB,
typename TViewA>
183 static_assert(DimA::value == DimB::value,
"viewA and viewB are required to have identical Dim");
186 static_assert(std::is_same_v<IdxA, IdxB>,
"viewA and viewB are required to have identical Idx");
196 template<
typename TView,
typename TQueue>
207 std::vector<Elem> v(
static_cast<std::size_t
>(extent.prod()),
static_cast<Elem>(0));
209 auto plainBuf =
createView(devHost, v, extent);
212 memcpy(queue, view, plainBuf);
217 template<
typename TAcc,
typename TView,
typename TQueue>
224 static_assert(std::is_pointer_v<NativePtr>,
"The value returned by getPtrNative has to be a pointer.");
226 !std::is_const_v<std::remove_pointer_t<NativePtr>>,
227 "The value returned by getPtrNative has to be non-const when the view is non-const.");
232 auto const byte(
static_cast<uint8_t
>(42u));
233 memset(queue, view,
byte);
235 verifyBytesSet<TAcc>(view,
byte);
243 auto const devAcc =
getDev(view);
248 auto srcBufAcc = allocBuf<Elem, Idx>(devAcc, extent);
250 memcpy(queue, view, srcBufAcc);
252 verifyViewsEqual<TAcc>(view, srcBufAcc);
257 auto dstBufAcc = allocBuf<Elem, Idx>(devAcc, extent);
258 memcpy(queue, dstBufAcc, view);
260 verifyViewsEqual<TAcc>(dstBufAcc, view);
#define ALPAKA_CHECK(success, expression)
The fixture for executing a kernel on a given accelerator.
#define ALPAKA_FN_ACC
All functions that can be used on an accelerator have to be attributed with ALPAKA_FN_ACC or ALPAKA_F...
#define ALPAKA_NO_HOST_ACC_WARNING
Disable nvcc warning: 'calling a host function from host device function.' Usage: ALPAKA_NO_HOST_ACC_...
ALPAKA_FN_HOST auto verifyBytesSet(TView const &view, std::uint8_t const &byte) -> void
ALPAKA_FN_HOST auto iotaFillView(TQueue &queue, TView &view) -> void
Fills the given view with increasing values starting at 0.
ALPAKA_FN_HOST auto end(TView &view) -> Iterator< TView >
ALPAKA_FN_HOST auto testViewMutable(TQueue &queue, TView &view) -> void
ALPAKA_FN_HOST auto verifyViewsEqual(TViewA const &viewA, TViewB const &viewB) -> void
ALPAKA_FN_HOST auto testViewImmutable(TView const &view, TDev const &dev, Vec< TDim, TIdx > const &extent, Vec< TDim, TIdx > const &offset) -> void
ALPAKA_FN_HOST auto begin(TView &view) -> Iterator< TView >
typename trait::IdxType< T >::type Idx
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto getExtentProduct(T const &object) -> Idx< T >
ALPAKA_FN_HOST auto memcpy(TQueue &queue, alpaka::detail::DevGlobalImplGeneric< TTag, TTypeDst > &viewDst, TViewSrc const &viewSrc) -> void
typename trait::DevType< T >::type Dev
The device type trait alias template to remove the ::type.
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto getExtents(T const &object) -> Vec< Dim< T >, Idx< T >>
ALPAKA_FN_HOST auto getPitchesInBytes(TView const &view) -> Vec< Dim< TView >, Idx< TView >>
ALPAKA_FN_HOST auto getPtrNative(TView const &view) -> Elem< TView > const *
Gets the native pointer of the memory view.
std::remove_volatile_t< typename trait::ElemType< TView >::type > Elem
The element type trait alias template to remove the ::type.
ALPAKA_FN_HOST auto memset(TQueue &queue, TViewFwd &&view, std::uint8_t const &byte, TExtent const &extent) -> void
Sets the bytes of the memory of view, described by extent, to the given value.
ALPAKA_FN_HOST auto getDevByIdx(TPlatform const &platform, std::size_t const &devIdx) -> Dev< TPlatform >
ALPAKA_FN_HOST auto getDev(T const &t)
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto getOffsets(T const &object) -> Vec< Dim< T >, Idx< T >>
ALPAKA_FN_HOST auto wait(TAwaited const &awaited) -> void
Waits the thread for the completion of the given awaited action to complete.
auto createView(TDev const &dev, TElem *pMem, TExtent const &extent)
Creates a view to a device pointer.
typename trait::DimType< T >::type Dim
The dimension type trait alias template to remove the ::type.
Compares element-wise that all bytes are set to the same value.
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_ACC void operator()(TAcc const &acc[[maybe_unused]], bool *success, TIter const &begin, TIter const &end, std::uint8_t const &byte) const
Compares iterators element-wise.
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_ACC void operator()(TAcc const &acc[[maybe_unused]], bool *success, TIterA beginA, TIterA const &endA, TIterB beginB) const