File: test_host_view.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,006 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 <gtest/gtest.h>

#include <gridtools/storage/builder.hpp>

#include <multiplet.hpp>
#include <storage_select.hpp>

using namespace gridtools;

const auto builder = storage::builder<storage_traits_t>.type<double>();

TEST(DataViewTest, Simple) {
    auto builder = ::builder.dimensions(3, 5, 7);
    // create and allocate a data_store
    auto ds = builder();
    // create a rw view and fill with some data
    auto dv = ds->host_view();
    dv(0, 0, 0) = 50;
    dv(0, 0, 1) = 60;

    // check if interface works
    EXPECT_TRUE(ds->lengths() == dv.lengths());

    // check if data is there
    EXPECT_EQ(50, dv(0, 0, 0));
    EXPECT_EQ(dv(0, 0, 1), 60);

    // create a ro view
    auto dvro = ds->const_host_view();
    // check if data is the same
    EXPECT_EQ(50, dvro(0, 0, 0));
    EXPECT_EQ(dvro(0, 0, 1), 60);

    // create  a second storage
    auto ds_tmp = builder();
    // again create a view
    auto dv_tmp = ds_tmp->const_host_view();
}

TEST(DataViewTest, ArrayAPI) {
    // create and allocate a data_store
    auto ds = builder.dimensions(2, 2, 2)();
    auto dvro = ds->host_view();

    dvro({1, 1, 1}) = 2.0;
    EXPECT_TRUE((dvro({1, 1, 1}) == 2.0));
}

TEST(DataViewTest, Looping) {
    auto ds = storage::builder<storage_traits_t >.type<triplet>().name("ds")
                  .dimensions(2 + 2, 2 + 4, 2 + 6)
                  .halos(1, 2, 3)
                  .initializer([](int i, int j, int k) {
                      return triplet{i, j, k};
                  })
                  .build();

    auto view = ds->const_host_view();

    auto &&lengths = view.lengths();
    for (int i = 0; i < lengths[0]; ++i)
        for (int j = 0; j < lengths[1]; ++j)
            for (int k = 0; k < lengths[2]; ++k)
                EXPECT_EQ(view(i, j, k), (triplet{i, j, k}));
}