File: test_target_view.cu

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 (57 lines) | stat: -rw-r--r-- 1,606 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
/*
 * 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 <gridtools/storage/gpu.hpp>

#include <multiplet.hpp>

using namespace gridtools;

constexpr int c_x = 3 /* < 32 for this test */, c_y = 5, c_z = 7;

template <class View>
__global__ void mul2(View s) {
    auto &&lengths = s.lengths();
    bool expected_dims = lengths[0] == c_x && lengths[1] == c_y && lengths[2] == c_z;
    bool expected_size = s.length() <= 32 * c_y * c_z && s.length() >= c_x * c_y * c_z;
    s(0, 0, 0) *= 2 * expected_dims * expected_size;
    s(1, 0, 0) *= 2 * expected_dims * expected_size;
}

TEST(DataViewTest, Simple) {
    // create and allocate a data_store
    auto ds = storage::builder<storage::gpu>.type<double>().layout<2, 1, 0>().dimensions(c_x, c_y, c_z)();
    // create a rw view and fill with some data
    auto dv = ds->host_view();
    dv(0, 0, 0) = 50;
    dv(1, 0, 0) = 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(60, dv(1, 0, 0));
    // 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(60, dvro(1, 0, 0));

    mul2<<<1, 1>>>(ds->target_view());

    dvro = ds->const_host_view();
    // check if data is the same
    EXPECT_EQ(100, dvro(0, 0, 0));
    EXPECT_EQ(120, dvro(1, 0, 0));
}