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

Sid: dimension to tuple like #1750

Merged
merged 35 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
c0a022d
basic implementation
havogt Apr 5, 2023
a5a0261
add comment
havogt Apr 5, 2023
29cce97
copy_stencil_tuple
havogt Apr 5, 2023
17a3a32
fn nabla test
havogt Apr 5, 2023
ec58277
try fix cuda clang compilation
havogt Apr 5, 2023
73ff485
compile time size and second layout
havogt Apr 5, 2023
78dbd2c
remove test case with wrong layout
havogt Apr 6, 2023
45ca850
fix includes
havogt Apr 6, 2023
7b46c5b
fix verification
havogt Apr 6, 2023
9a2c1b7
add an array test to understand bad float4 performance
havogt Apr 12, 2023
963aca2
make it a tuple of size 5 to destroy float4 aos behavior
havogt Apr 12, 2023
df63e7a
rely on constexpr for correct host/device
havogt Apr 12, 2023
7a78fa1
Revert "make it a tuple of size 5 to destroy float4 aos behavior"
havogt Apr 12, 2023
006f9a2
another try for copy_tuple
havogt Apr 12, 2023
2cf44ac
review comment: struct -> function
havogt Apr 12, 2023
a3f406d
undo verify_with_bounds
havogt Apr 12, 2023
4510e4d
update references
havogt Apr 12, 2023
f374b42
fix construction from rvalue
havogt Apr 13, 2023
124d96a
copy if rvalue
havogt Apr 13, 2023
f783025
fix missing ref
havogt Apr 13, 2023
fb008bf
alternative copy_if_rvalue
havogt Apr 13, 2023
b0f1464
fix
havogt Apr 14, 2023
473562f
total_size(tuple<>) == 1
havogt Apr 17, 2023
d2c12bd
Merge remote-tracking branch 'upstream/total_size_empty_tuple' into s…
havogt Apr 17, 2023
9a961a2
add test
havogt Apr 17, 2023
ba83a8b
support integral_constants
havogt Apr 17, 2023
171940e
Fix dummy thread_pool
havogt Apr 18, 2023
04f9ae1
Update tests/regression/fn/fn_domain.cpp
havogt Apr 18, 2023
993e8e7
protections
havogt Apr 20, 2023
643cd0b
Merge branch 'total_size_empty_tuple' into sid_dimension_to_tuple_like
havogt Apr 20, 2023
9488b2c
Merge remote-tracking branch 'upstream/master' into sid_dimension_to_…
havogt Apr 20, 2023
446cd20
address review comments
havogt Apr 20, 2023
0d68a60
fix has_value
havogt Apr 20, 2023
48c928a
Merge branch 'total_size_empty_tuple' into sid_dimension_to_tuple_like
havogt Apr 20, 2023
ead6a63
Merge remote-tracking branch 'upstream/master' into sid_dimension_to_…
havogt Apr 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/gridtools/common/tuple_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
* ```
* Also tuple algorithms works with `foo` as expected:
* ```
* auto x = tuple_util::trasnform([](auto x) { return x * 2; }, foo{1, 2.5});
* auto x = tuple_util::transform([](auto x) { return x * 2; }, foo{1, 2.5});
* assert(x.a == 2);
* assert(x.b == 5.);
* ```
Expand Down
2 changes: 1 addition & 1 deletion include/gridtools/sid/composite.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ namespace gridtools {

struct sum {
template <class Lhs, class Rhs>
GT_FUNCTION constexpr auto operator()(Lhs &&lhs, Rhs &&rhs) const {
GT_FORCE_INLINE constexpr auto operator()(Lhs &&lhs, Rhs &&rhs) const {
havogt marked this conversation as resolved.
Show resolved Hide resolved
return std::forward<Lhs>(lhs) + std::forward<Rhs>(rhs);
}
};
Expand Down
71 changes: 71 additions & 0 deletions include/gridtools/sid/dimension_to_tuple_like.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* 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
*/

#pragma once

#include <type_traits>
#include <utility>

#include "../common/host_device.hpp"
#include "../common/hymap.hpp"
#include "../meta.hpp"
#include "composite.hpp"
#include "concept.hpp"
#include "delegate.hpp"
#include "sid_shift_origin.hpp"

namespace gridtools {
namespace sid {
namespace dimension_to_tuple_like_impl_ {
template <class Dim, class Sid>
struct remove_dimension_sid : sid::delegate<Sid> {
friend decltype(hymap::canonicalize_and_remove_key<Dim>(std::declval<sid::strides_type<Sid>>()))
havogt marked this conversation as resolved.
Show resolved Hide resolved
sid_get_strides(remove_dimension_sid const &obj) {
return hymap::canonicalize_and_remove_key<Dim>(sid::get_strides(obj.m_impl));
}
friend decltype(hymap::canonicalize_and_remove_key<Dim>(std::declval<sid::lower_bounds_type<Sid>>()))
sid_get_lower_bounds(remove_dimension_sid const &obj) {
return hymap::canonicalize_and_remove_key<Dim>(sid::get_lower_bounds(obj.m_impl));
}
friend decltype(hymap::canonicalize_and_remove_key<Dim>(std::declval<sid::upper_bounds_type<Sid>>()))
sid_get_upper_bounds(remove_dimension_sid const &obj) {
return hymap::canonicalize_and_remove_key<Dim>(sid::get_upper_bounds(obj.m_impl));
}

using sid::delegate<Sid>::delegate;
};

template <class Dim, class Sid>
remove_dimension_sid<Dim, Sid> remove_dimension(Sid &&sid) {
return {std::forward<Sid>(sid)};
}

template <class Dim, class Sid, size_t... Is>
constexpr auto as_tuple_like_helper(Sid &&sid, std::index_sequence<Is...>) {
using keys = sid::composite::keys<integral_constant<int, Is>...>;
return keys::make_values(remove_dimension<Dim>(
sid::shift_sid_origin(std::forward<Sid>(sid), hymap::keys<Dim>::make_values(Is)))...);
}
} // namespace dimension_to_tuple_like_impl_

/**
* Returns a SID, where `Dim` of `sid` is mapped to a tuple-like of size `N`.
*
* TODO(havogt):
* - Currently, no bounds check is implemented.
* - In case bounds are compile-time known we could infer `N`.
*/
template <class Dim, size_t N, class Sid>
auto dimension_to_tuple_like(Sid &&sid) {
return dimension_to_tuple_like_impl_::as_tuple_like_helper<Dim>(
std::forward<Sid>(sid), std::make_index_sequence<N>{});
}
} // namespace sid
} // namespace gridtools
5 changes: 5 additions & 0 deletions include/gridtools/stencil/common/intent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ namespace gridtools {
template <intent Intent, class T>
struct apply_intent_type;

template <class T>
struct apply_intent_type<intent::inout, T> {
using type = T; // in case T is wrapping a reference (e.g. sid::composite)
};

template <class T>
struct apply_intent_type<intent::inout, T &> {
using type = T &;
Expand Down
11 changes: 8 additions & 3 deletions tests/include/fn_mesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,21 @@ namespace gridtools {
}
constexpr int nlevels() const { return m_nz; }

template <class T = FloatType, class Init, class... Dims, std::enable_if_t<!std::is_integral_v<Init>, int> = 0>
template <class T = FloatType,
class Init,
class... Dims,
std::enable_if_t<!(std::is_integral_v<Init> || is_integral_constant<Init>::value), int> = 0>
auto make_storage(Init const &init, Dims... dims) const {
return storage::builder<StorageTraits>.dimensions(dims...).template type<T>().initializer(init).unknown_id().build();
}

template <class T = FloatType,
class... Dims,
std::enable_if_t<std::conjunction_v<std::is_integral<Dims>...>, int> = 0>
std::enable_if_t<std::conjunction_v<std::bool_constant<std::is_integral<Dims>::value ||
is_integral_constant<Dims>::value>...>,
int> = 0>
auto make_storage(Dims... dims) const {
return make_storage<T>([](int, int) { return T(); }, dims...);
return make_storage<T>([](int...) { return T(); }, dims...);
}

template <class T = FloatType, class... Args>
Expand Down
10 changes: 5 additions & 5 deletions tests/include/test_environment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,11 @@ namespace gridtools {
EXPECT_TRUE(verify_data_store(expected, actual, halos, equal_to));
}

template <class T = FloatType>
static auto builder() {
return storage::builder<storage_traits_t> //
.dimensions(d(0), d(1), k_size()) //
.halos(Halo, Halo, 0) //
template <class T = FloatType, class... ExtraDims>
static auto builder(ExtraDims... extra_dims) {
return storage::builder<storage_traits_t> //
.dimensions(d(0), d(1), k_size(), extra_dims...) //
.halos(Halo, Halo, 0, [](auto) { return 0; }(extra_dims)...) //
havogt marked this conversation as resolved.
Show resolved Hide resolved
.template type<T>();
}

Expand Down
34 changes: 21 additions & 13 deletions tests/include/verifier.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,23 +108,15 @@ namespace gridtools {
return out;
}

template <class Expected, class DataStore, class Halos, class EqualTo = default_equal_to>
std::enable_if_t<storage::is_data_store<DataStore>::value &&
is_view_compatible<Expected, DataStore::ndims>::value,
bool>
verify_data_store(Expected const &expected,
std::shared_ptr<DataStore> const &actual,
Halos const &halos,
template <class Expected, class Actual, size_t NDims, class EqualTo = default_equal_to>
bool verify_generic(Expected const &expected,
fthaler marked this conversation as resolved.
Show resolved Hide resolved
Actual const &actual,
array<array<size_t, 2>, NDims> const &bounds,
EqualTo equal_to = {}) {
array<array<size_t, 2>, DataStore::ndims> bounds;
auto &&lengths = actual->lengths();
for (size_t i = 0; i < bounds.size(); ++i)
bounds[i] = {halos[i][0], lengths[i] - halos[i][1]};
auto view = actual->const_host_view();
static constexpr size_t err_lim = 20;
size_t err_count = 0;
for (auto &&pos : make_hypercube_view(bounds)) {
auto a = verify_impl_::apply(view, pos);
auto a = verify_impl_::apply(actual, pos);
decltype(a) e = verify_impl_::apply(expected, pos);
if (equal_to(e, a))
continue;
Expand All @@ -138,6 +130,22 @@ namespace gridtools {
return err_count == 0;
}

template <class Expected, class DataStore, class Halos, class EqualTo = default_equal_to>
std::enable_if_t<storage::is_data_store<DataStore>::value &&
is_view_compatible<Expected, DataStore::ndims>::value,
bool>
verify_data_store(Expected const &expected,
std::shared_ptr<DataStore> const &actual,
Halos const &halos,
EqualTo equal_to = {}) {
array<array<size_t, 2>, DataStore::ndims> bounds;
auto &&lengths = actual->lengths();
for (size_t i = 0; i < bounds.size(); ++i)
bounds[i] = {halos[i][0], lengths[i] - halos[i][1]};
auto view = actual->const_host_view();
return verify_generic(expected, view, bounds, equal_to);
}

template <class DataStore, class Halos, class EqualTo = default_equal_to>
std::enable_if_t<storage::is_data_store_ptr<DataStore>::value, bool> verify_data_store(
DataStore const &expected, DataStore const &actual, Halos const &halos, EqualTo equal_to = {}) {
Expand Down
1 change: 1 addition & 0 deletions tests/regression/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ gridtools_add_cartesian_regression_test(horizontal_diffusion SOURCES horizontal_
gridtools_add_cartesian_regression_test(horizontal_diffusion_fused SOURCES horizontal_diffusion_fused.cpp PERFTEST)
gridtools_add_cartesian_regression_test(simple_hori_diff SOURCES simple_hori_diff.cpp PERFTEST)
gridtools_add_cartesian_regression_test(copy_stencil SOURCES copy_stencil.cpp PERFTEST)
gridtools_add_cartesian_regression_test(copy_stencil_tuple SOURCES copy_stencil_tuple.cpp PERFTEST)
gridtools_add_cartesian_regression_test(vertical_advection_dycore SOURCES vertical_advection_dycore.cpp PERFTEST)
gridtools_add_cartesian_regression_test(advection_pdbott_prepare_tracers SOURCES advection_pdbott_prepare_tracers.cpp PERFTEST)
gridtools_add_cartesian_regression_test(parallel_multistage_fusion SOURCES parallel_multistage_fusion.cpp)
Expand Down
Loading