Skip to content

Commit

Permalink
Simplify the template prototype of Field
Browse files Browse the repository at this point in the history
Reorder the template arguments of `Field` so the layout (which is rarely used) is last.
Fixes #356

See merge request gysela-developpers/gyselalibxx!740

--------------------------------------------
  • Loading branch information
EmilyBourne committed Oct 23, 2024
1 parent 6ba879a commit 72e13f5
Show file tree
Hide file tree
Showing 35 changed files with 205 additions and 252 deletions.
6 changes: 3 additions & 3 deletions ci_tools/gyselalib_static_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,11 +638,11 @@ def check_exec_space_usage(file):
attribs['exec_space'] = 'DefaultHostExecutionSpace'
else:
attribs['exec_space'] = space
elif 'Mem' not in type_descr and len(args) > 3:
if args[-1].strip() == 'Kokkos :: HostSpace':
elif 'Mem' not in type_descr and len(args) > 2:
if args[2].strip() == 'Kokkos :: HostSpace':
attribs['exec_space'] = 'DefaultHostExecutionSpace'
else:
attribs['exec_space'] = args[-1]
attribs['exec_space'] = args[2]
else:
attribs['exec_space'] = 'DefaultExecutionSpace'
else:
Expand Down
2 changes: 0 additions & 2 deletions src/collisions/CollisionSpVparMu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,11 @@ class CollisionSpVparMu /* : public IRightHandSide */
/// Type alias for a constant field on GPU defined on a grid of magnetic moments.
using DConstFieldMu = DConstField<
IdxRangeMu,
std::experimental::layout_right,
Kokkos::DefaultExecutionSpace::
memory_space>; // Equivalent to Field<double const, IdxRangeMu>
/// Type alias for a constant field on GPU defined on a grid of parallel velocities.
using DConstFieldVpar = DConstField<
IdxRangeVpar,
std::experimental::layout_right,
Kokkos::DefaultExecutionSpace::
memory_space>; // Equivalent to Field<double const, IdxRangeMu>

Expand Down
20 changes: 10 additions & 10 deletions src/collisions/collisions_dimensions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ struct ExtractRDim<double>
/// If radial profile is stored in a 1D chunk then the grid tag is extracted.
template <class GridR, class Layout>
struct ExtractRDim<
ConstField<double, IdxRange<GridR>, Layout, Kokkos::DefaultExecutionSpace::memory_space>>
ConstField<double, IdxRange<GridR>, Kokkos::DefaultExecutionSpace::memory_space, Layout>>
{
using type = GridR;
};

/// If radial profile is stored in a chunk then information about why the chunk has the wrong type is provided
template <class ElementType, class IdxRange, class Layout, class MemSpace>
struct ExtractRDim<Field<ElementType, IdxRange, Layout, MemSpace>>
template <class ElementType, class IdxRange, class MemSpace, class Layout>
struct ExtractRDim<Field<ElementType, IdxRange, MemSpace, Layout>>
{
static_assert(
std::is_same_v<ElementType, const double>,
Expand All @@ -126,7 +126,7 @@ struct ExtractThetaDim<double, InternalSpoofGridR>
/// If the profile on the poloidal plane is stored in a chunk on radial values then the grid tag must be spoofed.
template <class GridR, class Layout>
struct ExtractThetaDim<
ConstField<double, IdxRange<GridR>, Layout, Kokkos::DefaultExecutionSpace::memory_space>,
ConstField<double, IdxRange<GridR>, Kokkos::DefaultExecutionSpace::memory_space, Layout>,
GridR>
{
using type = InternalSpoofGridTheta;
Expand All @@ -138,8 +138,8 @@ struct ExtractThetaDim<
ConstField<
double,
IdxRange<GridTheta>,
Layout,
Kokkos::DefaultExecutionSpace::memory_space>,
Kokkos::DefaultExecutionSpace::memory_space,
Layout>,
GridR>
{
using type = GridTheta;
Expand All @@ -151,16 +151,16 @@ struct ExtractThetaDim<
ConstField<
double,
IdxRange<GridTheta, GridR>,
Layout,
Kokkos::DefaultExecutionSpace::memory_space>,
Kokkos::DefaultExecutionSpace::memory_space,
Layout>,
GridR>
{
using type = GridTheta;
};

/// If poloidal profile is stored in a chunk then information about why the chunk has the wrong type is provided
template <class GridR, class ElementType, class IdxRange, class Layout, class MemSpace>
struct ExtractThetaDim<Field<ElementType, IdxRange, Layout, MemSpace>, GridR>
template <class GridR, class ElementType, class IdxRange, class MemSpace, class Layout>
struct ExtractThetaDim<Field<ElementType, IdxRange, MemSpace, Layout>, GridR>
{
static_assert(
std::is_same_v<ElementType, const double>,
Expand Down
52 changes: 26 additions & 26 deletions src/data_types/derivative_field.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ class DerivFieldMem;
template <
class ElementType,
class SupportType,
class LayoutStridedPolicy = std::experimental::layout_right,
class MemorySpace = Kokkos::HostSpace>
class MemorySpace = Kokkos::HostSpace,
class LayoutStridedPolicy = std::experimental::layout_right>
class DerivField;

template <class ElementType, class SupportType, class LayoutStridedPolicy, class MemorySpace>
template <class ElementType, class SupportType, class MemorySpace, class LayoutStridedPolicy>
inline constexpr bool enable_deriv_field<
DerivField<ElementType, SupportType, LayoutStridedPolicy, MemorySpace>> = true;
DerivField<ElementType, SupportType, MemorySpace, LayoutStridedPolicy>> = true;

template <class ElementType, class SupportType, class LayoutStridedPolicy, class MemorySpace>
template <class ElementType, class SupportType, class MemorySpace, class LayoutStridedPolicy>
inline constexpr bool enable_borrowed_deriv_field<
DerivField<ElementType, SupportType, LayoutStridedPolicy, MemorySpace>> = true;
DerivField<ElementType, SupportType, MemorySpace, LayoutStridedPolicy>> = true;

template <class ElementType, class SupportType, class LayoutStridedPolicy, class MemorySpace>
template <class ElementType, class SupportType, class MemorySpace, class LayoutStridedPolicy>
inline constexpr bool enable_data_access_methods<
DerivField<ElementType, SupportType, LayoutStridedPolicy, MemorySpace>> = true;
DerivField<ElementType, SupportType, MemorySpace, LayoutStridedPolicy>> = true;

namespace ddcHelper {

Expand Down Expand Up @@ -95,20 +95,20 @@ auto deepcopy(ExecSpace const& execution_space, FieldDst&& dst, FieldSrc&& src)
* @tparam IdxRange<DDims...> The index range on which the internal fields are defined.
* This index range is the physical index range on which the values are defined combined with
* the index range of the derivatives of interest (e.g. IdxRange<Deriv<IDimX>, IDimX, IDimY>).
* @tparam MemorySpace The memory space where the data is saved (CPU/GPU).
* @tparam LayoutStridedPolicy The way in which the memory is laid out in memory (contiguous in
* the leading/trailing dimension, strided, etc).
* @tparam MemorySpace The memory space where the data is saved (CPU/GPU).
*/
template <class ElementType, class... DDims, class LayoutStridedPolicy, class MemorySpace>
class DerivField<ElementType, IdxRange<DDims...>, LayoutStridedPolicy, MemorySpace>
template <class ElementType, class... DDims, class MemorySpace, class LayoutStridedPolicy>
class DerivField<ElementType, IdxRange<DDims...>, MemorySpace, LayoutStridedPolicy>
: public DerivFieldCommon<
Field<ElementType, IdxRange<DDims...>, LayoutStridedPolicy, MemorySpace>,
Field<ElementType, IdxRange<DDims...>, MemorySpace, LayoutStridedPolicy>,
IdxRange<DDims...>>
{
private:
/// @brief The class from which this object inherits.
using base_type = DerivFieldCommon<
Field<ElementType, IdxRange<DDims...>, LayoutStridedPolicy, MemorySpace>,
Field<ElementType, IdxRange<DDims...>, MemorySpace, LayoutStridedPolicy>,
IdxRange<DDims...>>;

public:
Expand Down Expand Up @@ -155,11 +155,11 @@ class DerivField<ElementType, IdxRange<DDims...>, LayoutStridedPolicy, MemorySpa
using chunk_type = typename base_type::chunk_type;

/// @brief The type of a modifiable span of this field. This is a DDC keyword used to make this class interchangeable with Field.
using span_type = DerivField<ElementType, IdxRange<DDims...>, LayoutStridedPolicy, MemorySpace>;
using span_type = DerivField<ElementType, IdxRange<DDims...>, MemorySpace, LayoutStridedPolicy>;

/// @brief The type of a constant view of this field. This is a DDC keyword used to make this class interchangeable with Field.
using view_type
= DerivField<ElementType const, IdxRange<DDims...>, LayoutStridedPolicy, MemorySpace>;
= DerivField<ElementType const, IdxRange<DDims...>, MemorySpace, LayoutStridedPolicy>;

private:
/// @brief The IdxRange which describes the derivatives present on each chunk.
Expand Down Expand Up @@ -296,7 +296,7 @@ class DerivField<ElementType, IdxRange<DDims...>, LayoutStridedPolicy, MemorySpa
*/
template <class OElementType>
KOKKOS_FUNCTION constexpr DerivField(
DerivField<OElementType, index_range_type, LayoutStridedPolicy, MemorySpace> const&
DerivField<OElementType, index_range_type, MemorySpace, LayoutStridedPolicy> const&
field)
: base_type(
field.m_physical_idx_range,
Expand Down Expand Up @@ -327,7 +327,7 @@ class DerivField<ElementType, IdxRange<DDims...>, LayoutStridedPolicy, MemorySpa
*/
template <class OElementType, class OLayoutStridedPolicy, class OMemorySpace>
void deepcopy(
DerivField<OElementType, index_range_type, OLayoutStridedPolicy, OMemorySpace> src)
DerivField<OElementType, index_range_type, OMemorySpace, OLayoutStridedPolicy> src)
{
for (int i(0); i < n_fields; ++i) {
auto kokkos_span = get_kokkos_view_from_internal_chunk(i);
Expand All @@ -342,10 +342,10 @@ class DerivField<ElementType, IdxRange<DDims...>, LayoutStridedPolicy, MemorySpa
* @param execution_space The execution space on which the copy will be carried out.
* @param src The DerivField containing the data to be copied.
*/
template <class ExecSpace, class OElementType, class OLayoutStridedPolicy, class OMemorySpace>
template <class ExecSpace, class OElementType, class OMemorySpace, class OLayoutStridedPolicy>
void deepcopy(
ExecSpace const& execution_space,
DerivField<OElementType, index_range_type, OLayoutStridedPolicy, OMemorySpace> src)
DerivField<OElementType, index_range_type, OMemorySpace, OLayoutStridedPolicy> src)
{
for (int i(0); i < n_fields; ++i) {
auto kokkos_span = get_kokkos_view_from_internal_chunk(i);
Expand Down Expand Up @@ -402,20 +402,20 @@ class DerivField<ElementType, IdxRange<DDims...>, LayoutStridedPolicy, MemorySpa
template <
class ElementType,
class SupportType,
class LayoutStridedPolicy = std::experimental::layout_right,
class MemorySpace = Kokkos::HostSpace>
class MemorySpace = Kokkos::HostSpace,
class LayoutStridedPolicy = std::experimental::layout_right>
using DerivConstField
= DerivField<ElementType const, SupportType, LayoutStridedPolicy, MemorySpace>;
= DerivField<ElementType const, SupportType, MemorySpace, LayoutStridedPolicy>;

namespace detail {
template <
class NewMemorySpace,
class ElementType,
class SupportType,
class Layout,
class MemorySpace>
struct OnMemorySpace<NewMemorySpace, DerivField<ElementType, SupportType, Layout, MemorySpace>>
class MemorySpace,
class Layout>
struct OnMemorySpace<NewMemorySpace, DerivField<ElementType, SupportType, MemorySpace, Layout>>
{
using type = DerivField<ElementType, SupportType, Layout, NewMemorySpace>;
using type = DerivField<ElementType, SupportType, NewMemorySpace, Layout>;
};
}; // namespace detail
8 changes: 4 additions & 4 deletions src/data_types/derivative_field_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@ class DerivFieldCommon<FieldType, IdxRange<DDims...>>
// Create a Field with the expected index range
Field<element_type,
index_range_type,
typename decltype(subview)::layout_type,
typename chunk_type::memory_space>
typename chunk_type::memory_space,
typename decltype(subview)::layout_type>
local_field(subview, full_idx_range);

// If necessary, slice off the derivative dimensions deduced implicitly
Expand Down Expand Up @@ -424,8 +424,8 @@ class DerivFieldCommon<FieldType, IdxRange<DDims...>>
// Create a Field with the expected index range
Field<element_type,
final_idx_range_type,
typename decltype(subview)::layout_type,
typename chunk_type::memory_space>
typename chunk_type::memory_space,
typename decltype(subview)::layout_type>
local_field(subview, final_idx_range);

return local_field;
Expand Down
8 changes: 4 additions & 4 deletions src/data_types/derivative_field_mem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ class DerivFieldMem<ElementType, IdxRange<DDims...>, NDerivs, MemSpace>
using span_type = DerivField<
ElementType,
IdxRange<DDims...>,
typename chunk_type::layout_type,
typename chunk_type::memory_space>;
typename chunk_type::memory_space,
typename chunk_type::layout_type>;

/// @brief The type of a constant view of this field. This is a DDC keyword used to make this class interchangeable with Field.
using view_type = DerivField<
ElementType const,
IdxRange<DDims...>,
typename chunk_type::layout_type,
typename chunk_type::memory_space>;
typename chunk_type::memory_space,
typename chunk_type::layout_type>;

private:
/**
Expand Down
54 changes: 27 additions & 27 deletions src/data_types/vector_field.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,36 @@ template <
class ElementType,
class IdxRangeType,
class NDTag,
class LayoutStridedPolicy = std::experimental::layout_right,
class MemorySpace = Kokkos::DefaultExecutionSpace::memory_space>
class MemorySpace = Kokkos::DefaultExecutionSpace::memory_space,
class LayoutStridedPolicy = std::experimental::layout_right>
class VectorField;

template <
class ElementType,
class IdxRangeType,
class NDTag,
class LayoutStridedPolicy,
class MemorySpace>
class MemorySpace,
class LayoutStridedPolicy>
inline constexpr bool enable_vector_field<
VectorField<ElementType, IdxRangeType, NDTag, LayoutStridedPolicy, MemorySpace>> = true;
VectorField<ElementType, IdxRangeType, NDTag, MemorySpace, LayoutStridedPolicy>> = true;

template <
class ElementType,
class IdxRangeType,
class NDTag,
class LayoutStridedPolicy,
class MemorySpace>
class MemorySpace,
class LayoutStridedPolicy>
inline constexpr bool enable_data_access_methods<
VectorField<ElementType, IdxRangeType, NDTag, LayoutStridedPolicy, MemorySpace>> = true;
VectorField<ElementType, IdxRangeType, NDTag, MemorySpace, LayoutStridedPolicy>> = true;

template <
class ElementType,
class IdxRangeType,
class NDTag,
class LayoutStridedPolicy,
class MemorySpace>
class MemorySpace,
class LayoutStridedPolicy>
inline constexpr bool enable_borrowed_vector_field<
VectorField<ElementType, IdxRangeType, NDTag, LayoutStridedPolicy, MemorySpace>> = true;
VectorField<ElementType, IdxRangeType, NDTag, MemorySpace, LayoutStridedPolicy>> = true;


/**
Expand All @@ -48,25 +48,25 @@ inline constexpr bool enable_borrowed_vector_field<
* @tparam ElementType The data type of a scalar element of the vector field.
* @tparam IdxRangeType
* @tparam NDTag A NDTag describing the dimensions described by the scalar elements of a vector field element.
* @tparam LayoutStridedPolicy The memory layout. See DDC.
* @tparam MemorySpace The memory space (CPU/GPU).
* @tparam LayoutStridedPolicy The memory layout. See DDC.
*/
template <
class ElementType,
class IdxRangeType,
class NDTag,
class LayoutStridedPolicy,
class MemorySpace>
class MemorySpace,
class LayoutStridedPolicy>
class VectorField
: public VectorFieldCommon<
Field<ElementType, IdxRangeType, LayoutStridedPolicy, MemorySpace>,
Field<ElementType, IdxRangeType, MemorySpace, LayoutStridedPolicy>,
NDTag>
{
public:
/**
* @brief Type describing the object which can be extracted from this VectorField using the get<> function.
*/
using field_type = Field<ElementType, IdxRangeType, LayoutStridedPolicy, MemorySpace>;
using field_type = Field<ElementType, IdxRangeType, MemorySpace, LayoutStridedPolicy>;

private:
using base_type = VectorFieldCommon<field_type, NDTag>;
Expand All @@ -89,13 +89,13 @@ class VectorField
* This is a DDC keyword used to make this class interchangeable with Field.
*/
using span_type
= VectorField<ElementType, IdxRangeType, NDTag, LayoutStridedPolicy, MemorySpace>;
= VectorField<ElementType, IdxRangeType, NDTag, MemorySpace, LayoutStridedPolicy>;
/**
* @brief A type which can hold a constant reference to a VectorFieldMem.
* This is a DDC keyword used to make this class interchangeable with Field.
*/
using view_type
= VectorField<const ElementType, IdxRangeType, NDTag, LayoutStridedPolicy, MemorySpace>;
= VectorField<const ElementType, IdxRangeType, NDTag, MemorySpace, LayoutStridedPolicy>;

/**
* @brief Type describing the way in which the data is laid out in the Field memory.
Expand Down Expand Up @@ -157,8 +157,8 @@ class VectorField
OElementType,
index_range_type,
NDTag,
LayoutStridedPolicy,
MemorySpace> const& other,
MemorySpace,
LayoutStridedPolicy> const& other,
std::index_sequence<Is...> const&) noexcept
: base_type((field_type(ddcHelper::get<ddc::type_seq_element_t<Is, NDTag>>(other)))...)
{
Expand All @@ -174,8 +174,8 @@ class VectorField
ElementType,
typename FieldType::discrete_domain_type,
NDTag,
typename FieldType::layout_type,
typename FieldType::memory_space>(std::move(std::get<Is>(chunk_slices))...);
typename FieldType::memory_space,
typename FieldType::layout_type>(std::move(std::get<Is>(chunk_slices))...);
}

/** Element access using a multi-dimensional Idx
Expand Down Expand Up @@ -242,8 +242,8 @@ class VectorField
OElementType,
index_range_type,
NDTag,
LayoutStridedPolicy,
MemorySpace> const& other) noexcept
MemorySpace,
LayoutStridedPolicy> const& other) noexcept
: VectorField(other, std::make_index_sequence<base_type::NDims> {})
{
}
Expand Down Expand Up @@ -383,7 +383,7 @@ template <
class ElementType,
class IdxRangeType,
class NDTag,
class LayoutStridedPolicy = std::experimental::layout_right,
class MemorySpace = Kokkos::DefaultExecutionSpace::memory_space>
class MemorySpace = Kokkos::DefaultExecutionSpace::memory_space,
class LayoutStridedPolicy = std::experimental::layout_right>
using VectorConstField
= VectorField<const ElementType, IdxRangeType, NDTag, LayoutStridedPolicy, MemorySpace>;
= VectorField<const ElementType, IdxRangeType, NDTag, MemorySpace, LayoutStridedPolicy>;
Loading

0 comments on commit 72e13f5

Please sign in to comment.