File: test_sid_contiguous.cpp

package info (click to toggle)
gridtools 2.3.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 29,480 kB
  • sloc: cpp: 228,792; python: 17,561; javascript: 9,164; ansic: 4,101; sh: 850; makefile: 231; f90: 201
file content (75 lines) | stat: -rw-r--r-- 2,318 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
 * GridTools
 *
 * Copyright (c) 2014-2023, ETH Zurich
 * All rights reserved.
 *
 * Please, refer to the LICENSE file in the root directory.
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <gridtools/sid/contiguous.hpp>

#include <memory>
#include <type_traits>

#include <gtest/gtest.h>

#include <gridtools/common/hymap.hpp>
#include <gridtools/common/integral_constant.hpp>
#include <gridtools/common/tuple_util.hpp>
#include <gridtools/sid/allocator.hpp>
#include <gridtools/sid/concept.hpp>

namespace gridtools {
    namespace {

        namespace tu = tuple_util;
        using namespace literals;

        struct a;
        struct b;
        struct c;

        using sid::property;

        TEST(contiguous, smoke) {
            auto alloc = sid::allocator(&std::make_unique<char[]>);
            hymap::keys<a, b, c>::values<integral_constant<int_t, 2>, int, int> sizes = {2_c, 3, 4};
            auto testee = sid::make_contiguous<int>(alloc, sizes);

            using testee_t = decltype(testee);
            using ptr_diff_t = sid::ptr_diff_type<testee_t>;
            using strides_t = sid::strides_type<testee_t>;
            using strides_kind_t = sid::strides_kind<testee_t>;

            static_assert(is_sid<testee_t>());
            static_assert(std::is_same_v<ptrdiff_t, ptr_diff_t>);
            static_assert(std::is_same_v<strides_kind_t, strides_t>);

            auto lower_bounds = sid::get_lower_bounds(testee);
            EXPECT_EQ(0, at_key<a>(lower_bounds));
            EXPECT_EQ(0, at_key<b>(lower_bounds));
            EXPECT_EQ(0, at_key<c>(lower_bounds));

            auto upper_bounds = sid::get_upper_bounds(testee);
            EXPECT_EQ(2, at_key<a>(upper_bounds));
            EXPECT_EQ(3, at_key<b>(upper_bounds));
            EXPECT_EQ(4, at_key<c>(upper_bounds));

            auto strides = sid::get_strides(testee);
            auto origin = sid::get_origin(testee)();

            *origin = 42;
            EXPECT_EQ(42, *origin);

            auto ptr = origin;
            sid::shift(ptr, sid::get_stride<a>(strides), 1);
            sid::shift(ptr, sid::get_stride<b>(strides), 2);
            sid::shift(ptr, sid::get_stride<c>(strides), 3);

            *ptr = 88;
            EXPECT_EQ(88, *ptr);
        }
    } // namespace
} // namespace gridtools