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 24 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/stride_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace gridtools {

template <class Sizes>
auto total_size(Sizes const &sizes) {
return tuple_util::fold([](auto l, auto r) { return l * r; }, sizes);
return tuple_util::fold([](auto l, auto r) { return l * r; }, 1, sizes);
}
} // namespace stride_util
} // namespace gridtools
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
81 changes: 81 additions & 0 deletions include/gridtools/sid/dimension_to_tuple_like.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* 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 T, class U>
std::enable_if_t<std::is_reference_v<T>, T> copy_if_rvalue(U &p) {
return p;
}
template <class T, class U>
std::enable_if_t<!std::is_reference_v<T>, T> copy_if_rvalue(U const &p) {
return p;
}

template <class Dim, class Sid, size_t... Is>
constexpr decltype(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(
copy_if_rvalue<Sid>(sid), // copy required otherwise we move away from `sid` multiple times
havogt marked this conversation as resolved.
Show resolved Hide resolved
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>
decltype(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
3 changes: 1 addition & 2 deletions jenkins/update_references.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ for domain in 128 256; do
for label in ault dom daint-cn tsa; do
for env in cray hip nvcc_cray nvcc_cray_cxx20 nvcc_gcc; do
current="${label%-*}_$env/$domain.json"
src="https://jenkins-mch.cscs.ch/view/GridTools/job/GridTools_perftest_PR/$1/env=$env,label=$label/artifact/build/pyutils/perftest/results/$current"

src="https://jenkins-mch.cscs.ch/job/GridTools/job/GridTools_perftest_PR/$1/env=$env,label=$label/artifact/build/pyutils/perftest/results/$current"
tmp=$(mktemp)
curl -fs -u "$user:$password" -o "$tmp" "$src"

Expand Down
Loading