Skip to content

Commit

Permalink
fn: introduce fn::index as alias to positional (#1806)
Browse files Browse the repository at this point in the history
The `index` builtin is meant to be used in the frontend.

---------

Co-authored-by: Felix Thaler <thaler@cscs.ch>
  • Loading branch information
havogt and fthaler authored Oct 29, 2024
1 parent fde30fc commit 805897d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 8 additions & 0 deletions include/gridtools/fn/common_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
*/
#pragma once

#include <type_traits>

#include "../common/tuple.hpp"
#include "../common/tuple_util.hpp"
#include "../stencil/positional.hpp"
#include "./backend/common.hpp"

namespace gridtools::fn {
Expand All @@ -30,4 +33,9 @@ namespace gridtools::fn {
return {std::forward<Args>(args)...};
}

template <class D>
constexpr auto index(D) {
return gridtools::stencil::positional<D>();
}

} // namespace gridtools::fn
8 changes: 3 additions & 5 deletions include/gridtools/fn/unstructured.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "../common/ldg_ptr.hpp"
#include "../meta/logical.hpp"
#include "../sid/concept.hpp"
#include "../stencil/positional.hpp"
#include "./common_interface.hpp"
#include "./executor.hpp"
#include "./neighbor_table.hpp"
Expand All @@ -28,7 +27,6 @@ namespace gridtools::fn {
} // namespace unstructured::dim

namespace unstructured_impl_ {
using gridtools::stencil::positional;
namespace dim = unstructured::dim;

template <class Tables, class Sizes>
Expand Down Expand Up @@ -145,13 +143,13 @@ namespace gridtools::fn {
Domain m_domain;
TmpAllocator m_allocator;

static constexpr auto index = positional<dim::horizontal>();
static constexpr auto horizontal_index = index(dim::horizontal{});

auto stencil_executor() const {
return [&] {
return make_stencil_executor<1>(
m_backend, m_domain.m_sizes, m_domain.m_offsets, make_iterator(m_domain.without_offsets()))
.arg(index); // the horizontal index is passed as the first argument
.arg(horizontal_index); // the horizontal index is passed as the first argument
};
}

Expand All @@ -160,7 +158,7 @@ namespace gridtools::fn {
return [&] {
return make_vertical_executor<Vertical, 1>(
m_backend, m_domain.m_sizes, m_domain.m_offsets, make_iterator(m_domain.without_offsets()))
.arg(index); // the horizontal index is passed as the first argument
.arg(horizontal_index); // the horizontal index is passed as the first argument
};
}
};
Expand Down

0 comments on commit 805897d

Please sign in to comment.