From 354af50446393d53138024d2dd652f6ec5ad89d6 Mon Sep 17 00:00:00 2001 From: Bernhard Manfred Gruber Date: Wed, 28 Sep 2022 00:17:20 +0200 Subject: [PATCH] Add a few explicit tests on pitches --- test/unit/mem/buf/src/PitchTest.cpp | 75 +++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 test/unit/mem/buf/src/PitchTest.cpp diff --git a/test/unit/mem/buf/src/PitchTest.cpp b/test/unit/mem/buf/src/PitchTest.cpp new file mode 100644 index 000000000000..a608f7ccae74 --- /dev/null +++ b/test/unit/mem/buf/src/PitchTest.cpp @@ -0,0 +1,75 @@ +/* Copyright 2022 Bernhard Manfred Gruber + * + * This file is part of alpaka. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include + +#include +#include +#include + +namespace +{ + using Idx = int; + + template + void checkBufferPitches(const Dev& dev, alpaka::Vec extent, alpaka::Vec expectedPitches) + { + auto buf = alpaka::allocBuf(dev, extent); + CAPTURE(extent); + const auto pitches = alpaka::getPitchBytesVec(buf); + CHECK(pitches == expectedPitches); + boost::mp11::mp_for_each>( + [&](auto ic) + { + constexpr auto i = decltype(ic)::value; + CHECK(alpaka::getPitchBytes(buf) == pitches[i]); + }); + } +} // namespace + +#ifdef ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLED +TEST_CASE("memBufPitchTest.AccCpuSerial", "[memBuf]") +{ + using Acc = alpaka::AccCpuSerial, Idx>; + const auto dev = alpaka::getDevByIdx>>(0); + + checkBufferPitches(dev, alpaka::Vec, Idx>{}, alpaka::Vec, Idx>{}); + + checkBufferPitches(dev, alpaka::Vec{10}, alpaka::Vec{40}); + + checkBufferPitches(dev, alpaka::Vec{42, 10}, alpaka::Vec{1680, 40}); + checkBufferPitches(dev, alpaka::Vec{10, 42}, alpaka::Vec{1680, 168}); + + checkBufferPitches(dev, alpaka::Vec{42, 10, 2}, alpaka::Vec{3360, 80, 8}); + checkBufferPitches(dev, alpaka::Vec{2, 10, 42}, alpaka::Vec{3360, 1680, 168}); +} +#endif + +#ifdef ALPAKA_ACC_GPU_CUDA_ENABLED +TEST_CASE("memBufPitchTest.AccGpuCudaRt", "[memBuf]") +{ + using Idx = int; + using Acc = alpaka::AccGpuCudaRt, Idx>; + + const auto dev = alpaka::getDevByIdx>>(0); + + checkBufferPitches(dev, alpaka::Vec, Idx>{}, alpaka::Vec, Idx>{}); + + checkBufferPitches(dev, alpaka::Vec{10}, alpaka::Vec{40}); + + constexpr auto pitch = 512; + + checkBufferPitches(dev, alpaka::Vec{42, 10}, alpaka::Vec{42 * pitch, pitch}); + checkBufferPitches(dev, alpaka::Vec{10, 42}, alpaka::Vec{10 * pitch, pitch}); + + checkBufferPitches(dev, alpaka::Vec{42, 10, 2}, alpaka::Vec{42 * 10 * pitch, 10 * pitch, pitch}); + checkBufferPitches(dev, alpaka::Vec{2, 10, 42}, alpaka::Vec{2 * 10 * pitch, 10 * pitch, pitch}); +} +#endif