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

Get rid of global parameter call operator #1256

Merged
merged 13 commits into from
Apr 5, 2019
13 changes: 0 additions & 13 deletions docs_src/manuals/user_manual/global_accessor.hrst
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,3 @@ in the do method
.. note::
All the member functions defined in the user-defined data structure must be labeled with ``GT_FUNCTION``, in order for
them to be callable from devices.

There is a special case for which we have a dedicated API: i.e. when the user defined object
(the global parameter)
defines the parenthesis operator ``operator()``, and we want to call that operator from the :term:`Apply-Method`.
In that case the :term:`Accessor's<Accessor>` parenthesis operator can be used and the arguments will be
automatically forwarded to the global parameter. An example is the case in which we want to pass
a small matrix as a global parameter:

.. code-block:: gridtools

using matrix = global_accessor<0>;
auto elem = eval(matrix(i, j));

2 changes: 0 additions & 2 deletions include/gridtools/stencil_composition/accessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,3 @@
#else
#include "./icosahedral_grids/accessor.hpp"
#endif

#include "./global_accessor.hpp"
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "../../common/host_device.hpp"
#include "../../meta/type_traits.hpp"
#include "../is_accessor.hpp"
#include "../is_global_accessor.hpp"

namespace gridtools {

Expand Down Expand Up @@ -51,8 +50,7 @@ namespace gridtools {
struct is_expr<expr<Ts...>> : std::true_type {};

template <class Arg>
using expr_or_accessor =
bool_constant<is_expr<Arg>::value || is_accessor<Arg>::value || is_global_accessor<Arg>::value>;
using expr_or_accessor = bool_constant<is_expr<Arg>::value || is_accessor<Arg>::value>;

template <class Op, class... Args, enable_if_t<disjunction<expr_or_accessor<Args>...>::value, int> = 0>
GT_FUNCTION constexpr expr<Op, Args...> make_expr(Op, Args... args) {
Expand Down
108 changes: 0 additions & 108 deletions include/gridtools/stencil_composition/global_accessor.hpp

This file was deleted.

8 changes: 2 additions & 6 deletions include/gridtools/stencil_composition/global_parameter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,11 @@
namespace gridtools {
template <class Backend, class T>
using global_parameter = typename storage_traits<Backend>::template data_store_t<T,
typename storage_traits<Backend>::template special_storage_info_t<0, selector<0>, zero_halo<1>>>;
typename storage_traits<Backend>::template special_storage_info_t<0, selector<0>, halo<0>>>;

template <class Backend, class T>
global_parameter<Backend, T> make_global_parameter(T const &value) {
typename global_parameter<Backend, T>::storage_info_t si(1);
global_parameter<Backend, T> ds(si);
make_host_view(ds)(0) = value;
ds.sync();
return ds;
return {{1}, value};
}

template <class GlobalParameter, class T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace gridtools {
using ij_cache_args_t = GT_META_CALL(ij_cache_args, typename IterateDomainArguments::cache_sequence_t);

// the number of different storage metadatas used in the current functor
static const uint_t n_meta_storages = meta::length<typename local_domain_t::storage_infos_t>::value;
static const uint_t n_meta_storages = meta::length<typename local_domain_t::strides_kinds_t>::value;

GT_STATIC_ASSERT(is_local_domain<local_domain_t>::value, GT_INTERNAL_ERROR);

Expand Down Expand Up @@ -64,7 +64,7 @@ namespace gridtools {

/**@brief method for initializing the index */
GT_FUNCTION void initialize(pos3<uint_t> begin, pos3<uint_t> block_no, pos3<int_t> pos_in_block) {
host_device::for_each_type<typename local_domain_t::storage_infos_t>(
host_device::for_each_type<typename local_domain_t::strides_kinds_t>(
initialize_index<backend_t, local_domain_t>(
m_local_domain.m_strides_map, begin, block_no, pos_in_block, m_index));
}
Expand Down Expand Up @@ -115,7 +115,7 @@ namespace gridtools {
// this index here describes the position of the storage info in the m_index array (can be different to the
// storage info id)
static constexpr auto storage_info_index =
meta::st_position<typename local_domain_t::storage_infos_t, storage_info_t>::value;
meta::st_position<typename local_domain_t::strides_kinds_t, storage_info_t>::value;

int_t pointer_offset = m_index[storage_info_index];
sid::multi_shift(pointer_offset, host_device::at_key<storage_info_t>(m_local_domain.m_strides_map), acc);
Expand Down
6 changes: 3 additions & 3 deletions include/gridtools/stencil_composition/intermediate_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ namespace gridtools {
enable_if_t<meta::st_contains<typename LocalDomain::esf_args_t, Arg>::value> operator()(
arg_storage_pair<Arg, DataStore> const &src, LocalDomain &local_domain) const {
const auto &storage = src.m_value;
using storage_info_t = typename DataStore::storage_info_t;
using strides_kind_t = GT_META_CALL(sid::strides_kind, DataStore);

at_key<Arg>(local_domain.m_ptr_holder_map) = sid::get_origin(storage);
at_key<storage_info_t>(local_domain.m_strides_map) = sid::get_strides(storage);
at_key<storage_info_t>(local_domain.m_total_length_map) = storage.info().padded_total_length();
at_key<strides_kind_t>(local_domain.m_strides_map) = sid::get_strides(storage);
at_key<strides_kind_t>(local_domain.m_total_length_map) = storage.info().padded_total_length();
}
// do nothing if arg is not in this local domain
template <class Arg, class DataStore, class LocalDomain>
Expand Down
17 changes: 0 additions & 17 deletions include/gridtools/stencil_composition/is_global_accessor.hpp

This file was deleted.

39 changes: 19 additions & 20 deletions include/gridtools/stencil_composition/iterate_domain_aux.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@

namespace gridtools {
namespace _impl {
template <class StorageInfo, class LocalDomain>
struct get_index : meta::st_position<typename LocalDomain::storage_infos_t, StorageInfo> {};
template <class StridesKind, class LocalDomain>
struct get_index : meta::st_position<typename LocalDomain::strides_kinds_t, StridesKind> {};

} // namespace _impl

Expand All @@ -51,19 +51,19 @@ namespace gridtools {
ArrayIndex &GT_RESTRICT m_index_array;
StridesMap const &m_strides_map;

template <typename StorageInfo>
template <typename StridesKind>
GT_FUNCTION void operator()() const {
static constexpr auto index = _impl::get_index<StorageInfo, LocalDomain>::value;
static constexpr auto index = _impl::get_index<StridesKind, LocalDomain>::value;
GT_STATIC_ASSERT(index < ArrayIndex::size(), "Accessing an index out of bound in fusion tuple");
sid::shift(
m_index_array[index], sid::get_stride<Dim>(host_device::at_key<StorageInfo>(m_strides_map)), m_offset);
m_index_array[index], sid::get_stride<Dim>(host_device::at_key<StridesKind>(m_strides_map)), m_offset);
}
};

template <class Dim, class LocalDomain, class StridesMap, class ArrayIndex, class Offset>
GT_FUNCTION void do_increment(
Offset const &GT_RESTRICT offset, StridesMap const &strides_map, ArrayIndex &GT_RESTRICT index) {
host_device::for_each_type<typename LocalDomain::storage_infos_t>(
host_device::for_each_type<typename LocalDomain::strides_kinds_t>(
increment_index_functor<LocalDomain, Dim, StridesMap, ArrayIndex, Offset>{offset, index, strides_map});
}

Expand All @@ -75,11 +75,11 @@ namespace gridtools {
* @tparam StridesCached strides cached type
* @tparam StorageSequence sequence of storages
*/
template <class StorageInfo, class MaxExtent, bool IsTmp>
template <class StridesKind, class MaxExtent, bool IsTmp>
struct get_index_offset_f;

template <class StorageInfo, class MaxExtent>
struct get_index_offset_f<StorageInfo, MaxExtent, false> {
template <class StridesKind, class MaxExtent>
struct get_index_offset_f<StridesKind, MaxExtent, false> {
template <class Backend, class Stride, class Begin, class BlockNo, class PosInBlock>
GT_FUNCTION int_t operator()(Backend const &,
Stride const &GT_RESTRICT stride,
Expand All @@ -94,15 +94,15 @@ namespace gridtools {
}
};

template <class StorageInfo, class MaxExtent>
struct get_index_offset_f<StorageInfo, MaxExtent, true> {
template <class StridesKind, class MaxExtent>
struct get_index_offset_f<StridesKind, MaxExtent, true> {
template <class Backend, class Stride, class Begin, class BlockNo, class PosInBlock>
GT_FUNCTION int_t operator()(Backend const &backend,
Stride const &GT_RESTRICT stride,
Begin const &GT_RESTRICT /*begin*/,
BlockNo const &GT_RESTRICT block_no,
PosInBlock const &GT_RESTRICT pos_in_block) const {
return get_tmp_storage_offset<StorageInfo, MaxExtent>(backend, stride, block_no, pos_in_block);
return get_tmp_storage_offset<StridesKind, MaxExtent>(backend, stride, block_no, pos_in_block);
}
};

Expand All @@ -115,17 +115,16 @@ namespace gridtools {
pos3<int_t> const &m_pos_in_block;
ArrayIndex &m_index_array;

template <typename StorageInfo>
template <typename StridesKind>
GT_FUNCTION void operator()() const {
static constexpr auto index = _impl::get_index<StorageInfo, LocalDomain>::value;
static constexpr auto index = _impl::get_index<StridesKind, LocalDomain>::value;
GT_STATIC_ASSERT(index < ArrayIndex::size(), "Accessing an index out of bound in fusion tuple");
using layout_t = typename StorageInfo::layout_t;
static constexpr auto backend = Backend{};
static constexpr auto is_tmp =
meta::st_contains<typename LocalDomain::tmp_storage_infos_t, StorageInfo>::value;
auto const &strides = host_device::at_key<StorageInfo>(m_strides_map);
meta::st_contains<typename LocalDomain::tmp_strides_kinds_t, StridesKind>::value;
auto const &strides = host_device::at_key<StridesKind>(m_strides_map);
m_index_array[index] =
get_index_offset_f<StorageInfo, typename LocalDomain::max_extent_for_tmp_t, is_tmp>{}(backend,
get_index_offset_f<StridesKind, typename LocalDomain::max_extent_for_tmp_t, is_tmp>{}(backend,
make_pos3<int>(sid::get_stride<dim::i>(strides),
sid::get_stride<dim::j>(strides),
sid::get_stride<dim::k>(strides)),
Expand All @@ -151,9 +150,9 @@ namespace gridtools {
* once the base address is known it can be checked if the requested access lies within the
* storages allocated memory.
*/
template <typename StorageInfo, typename LocalDomain>
template <typename StridesKind, typename LocalDomain>
GT_FUNCTION bool pointer_oob_check(LocalDomain const &local_domain, int_t offset) {
return offset < gridtools::host_device::at_key<StorageInfo>(local_domain.m_total_length_map) && offset >= 0;
return offset < gridtools::host_device::at_key<StridesKind>(local_domain.m_total_length_map) && offset >= 0;
}

template <class Arg, intent Intent>
Expand Down
Loading