Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimizations for temporaries with non-scalar datatype #1662

Open
havogt opened this issue Oct 26, 2021 · 0 comments
Open

Optimizations for temporaries with non-scalar datatype #1662

havogt opened this issue Oct 26, 2021 · 0 comments

Comments

@havogt
Copy link
Contributor

havogt commented Oct 26, 2021

To represent (small) matrices and vectors per gridpoint we allow higher (than 3) dimensional storages (with backend specific) layout (typically structure-of-array like, i.e. the matrix/vector dimensions are outermost). For temporaries, we can only express 3D temporaries, but we allow non-scalar element type. Temporaries with non-scalar element type have a natural API, but will have non-optimal data layout (array-of-structure).

If the user expresses the non-scalar datatype (see example below) with (nested) arrays we can do custom allocation with backend specific layout, without changing the API.

/*
 * GridTools
 *
 * Copyright (c) 2014-2021, ETH Zurich
 * All rights reserved.
 *
 * Please, refer to the LICENSE file in the root directory.
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include "gridtools/stencil/frontend/cartesian/tmp_arg.hpp"
#include "gridtools/stencil/frontend/run.hpp"
#include <gtest/gtest.h>

#include <gridtools/common/array.hpp>
#include <gridtools/stencil/cartesian.hpp>

#include <stencil_select.hpp>
#include <test_environment.hpp>

namespace {
    using namespace gridtools;
    using namespace stencil;
    using namespace cartesian;

    struct copy_functor {
        using in = in_accessor<0>;
        using out = inout_accessor<1>;
        using tmp = inout_accessor<2>;

        using param_list = make_param_list<in, out, tmp>;

        template <class Eval>
        GT_FUNCTION static void apply(Eval &&eval) {
            eval(tmp())[0] = eval(in());
            eval(out()) = eval(tmp())[0];
        }
    };

    GT_REGRESSION_TEST(copy_stencil_higher_dim, test_environment<>, stencil_backend_t) {
        auto in = [](int i, int j, int k) { return i + j + k; };
        auto out = TypeParam::make_storage();
        run(
            [](auto out, auto in) {
                GT_DECLARE_TMP((array<typename TypeParam::float_t, 2>), tmp);
                return execute_parallel().stage(copy_functor(), in, out, tmp);
            },
            stencil_backend_t(),
            TypeParam::make_grid(),
            out,
            TypeParam::make_storage(in));
        TypeParam::verify(in, out);
    }
} // namespace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant