-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch from LocalArray -> ArrayND (#1339)
- Loading branch information
Showing
48 changed files
with
448 additions
and
414 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
#ifndef ARRAY_ND_H | ||
#define ARRAY_ND_H | ||
|
||
#include "Kokkos_Macros.hpp" | ||
#include <type_traits> | ||
|
||
namespace sierra::nalu { | ||
|
||
// stack array set to interoperate with Kokkos views | ||
template <typename ArrayType, typename = void> | ||
struct ArrayND | ||
{ | ||
}; | ||
|
||
template <typename ArrayType, decltype(std::rank_v<ArrayType>) r> | ||
using enable_if_rank = std::enable_if_t<std::rank_v<ArrayType> == r>; | ||
|
||
template <typename ArrayType> | ||
struct ArrayND<ArrayType, enable_if_rank<ArrayType, 1>> | ||
{ | ||
KOKKOS_DEFAULTED_FUNCTION constexpr ArrayND() = default; | ||
|
||
static constexpr int rank = 1; | ||
using value_type = std::remove_all_extents_t<ArrayType>; | ||
value_type internal_data_[std::extent_v<ArrayType, 0>]; | ||
|
||
[[nodiscard]] static constexpr int extent_int(int /*unused*/) | ||
{ | ||
return int(std::extent_v<ArrayType, 0>); | ||
} | ||
|
||
[[nodiscard]] KOKKOS_FORCEINLINE_FUNCTION constexpr value_type | ||
operator()(int i) const noexcept | ||
{ | ||
return internal_data_[i]; | ||
} | ||
|
||
[[nodiscard]] KOKKOS_FORCEINLINE_FUNCTION constexpr value_type | ||
operator[](int i) const noexcept | ||
{ | ||
return internal_data_[i]; | ||
} | ||
|
||
[[nodiscard]] KOKKOS_FORCEINLINE_FUNCTION constexpr value_type& | ||
operator()(int i) noexcept | ||
{ | ||
return internal_data_[i]; | ||
} | ||
}; | ||
|
||
template <typename ArrayType> | ||
struct ArrayND<ArrayType, enable_if_rank<ArrayType, 2>> | ||
{ | ||
KOKKOS_DEFAULTED_FUNCTION constexpr ArrayND() = default; | ||
|
||
static constexpr int rank = 2; | ||
|
||
using value_type = std::remove_all_extents_t<ArrayType>; | ||
value_type internal_data_[std::extent_v<ArrayType, 0>] | ||
[std::extent_v<ArrayType, 1>]; | ||
|
||
[[nodiscard]] static constexpr int extent_int(int n) | ||
{ | ||
return (n == 0) ? int(std::extent_v<ArrayType, 0>) | ||
: int(std::extent_v<ArrayType, 1>); | ||
} | ||
|
||
[[nodiscard]] KOKKOS_FORCEINLINE_FUNCTION constexpr value_type | ||
operator()(int j, int i) const noexcept | ||
{ | ||
return internal_data_[j][i]; | ||
} | ||
|
||
[[nodiscard]] KOKKOS_FORCEINLINE_FUNCTION constexpr value_type& | ||
operator()(int j, int i) noexcept | ||
{ | ||
return internal_data_[j][i]; | ||
} | ||
}; | ||
|
||
template <typename ArrayType> | ||
struct ArrayND<ArrayType, enable_if_rank<ArrayType, 3>> | ||
{ | ||
KOKKOS_DEFAULTED_FUNCTION constexpr ArrayND() = default; | ||
|
||
static constexpr int rank = 3; | ||
[[nodiscard]] static constexpr int extent_int(int n) | ||
{ | ||
return (n == 0) ? int(std::extent_v<ArrayType, 0>) | ||
: (n == 1) ? int(std::extent_v<ArrayType, 1>) | ||
: int(std::extent_v<ArrayType, 2>); | ||
} | ||
|
||
using value_type = std::remove_all_extents_t<ArrayType>; | ||
value_type internal_data_[std::extent_v<ArrayType, 0>] | ||
[std::extent_v<ArrayType, 1>] | ||
[std::extent_v<ArrayType, 2>]; | ||
|
||
[[nodiscard]] KOKKOS_FORCEINLINE_FUNCTION constexpr auto | ||
operator()(int k, int j, int i) const noexcept | ||
{ | ||
return internal_data_[k][j][i]; | ||
} | ||
|
||
[[nodiscard]] KOKKOS_FORCEINLINE_FUNCTION constexpr auto& | ||
operator()(int k, int j, int i) noexcept | ||
{ | ||
return internal_data_[k][j][i]; | ||
} | ||
}; | ||
|
||
template <typename ArrayType> | ||
struct ArrayND<ArrayType, enable_if_rank<ArrayType, 4>> | ||
{ | ||
KOKKOS_DEFAULTED_FUNCTION constexpr ArrayND() = default; | ||
|
||
static constexpr int rank = 4; | ||
[[nodiscard]] static constexpr int extent_int(int n) | ||
{ | ||
return (n == 0) ? int(std::extent_v<ArrayType, 0>) | ||
: (n == 1) ? int(std::extent_v<ArrayType, 1>) | ||
: (n == 2) ? int(std::extent_v<ArrayType, 2>) | ||
: int(std::extent_v<ArrayType, 3>); | ||
} | ||
|
||
using value_type = std::remove_all_extents_t<ArrayType>; | ||
value_type | ||
internal_data_[std::extent_v<ArrayType, 0>][std::extent_v<ArrayType, 1>] | ||
[std::extent_v<ArrayType, 2>][std::extent_v<ArrayType, 3>]; | ||
|
||
[[nodiscard]] KOKKOS_FORCEINLINE_FUNCTION constexpr value_type | ||
operator()(int l, int k, int j, int i) const noexcept | ||
{ | ||
return internal_data_[l][k][j][i]; | ||
} | ||
|
||
[[nodiscard]] KOKKOS_FORCEINLINE_FUNCTION constexpr value_type& | ||
operator()(int l, int k, int j, int i) noexcept | ||
{ | ||
return internal_data_[l][k][j][i]; | ||
} | ||
}; | ||
|
||
template <typename ArrayType> | ||
struct ArrayND<ArrayType, enable_if_rank<ArrayType, 5>> | ||
{ | ||
KOKKOS_DEFAULTED_FUNCTION constexpr ArrayND() = default; | ||
|
||
static constexpr int rank = 5; | ||
[[nodiscard]] static constexpr int extent_int(int n) | ||
{ | ||
return (n == 0) ? int(std::extent_v<ArrayType, 0>) | ||
: (n == 1) ? int(std::extent_v<ArrayType, 1>) | ||
: (n == 2) ? int(std::extent_v<ArrayType, 2>) | ||
: (n == 3) ? int(std::extent_v<ArrayType, 3>) | ||
: int(std::extent_v<ArrayType, 4>); | ||
} | ||
|
||
using value_type = std::remove_all_extents_t<ArrayType>; | ||
value_type | ||
internal_data_[std::extent_v<ArrayType, 0>][std::extent_v<ArrayType, 1>] | ||
[std::extent_v<ArrayType, 2>][std::extent_v<ArrayType, 3>] | ||
[std::extent_v<ArrayType, 4>]; | ||
|
||
[[nodiscard]] KOKKOS_FORCEINLINE_FUNCTION constexpr value_type | ||
operator()(int m, int l, int k, int j, int i) const noexcept | ||
{ | ||
return internal_data_[m][l][k][j][i]; | ||
} | ||
|
||
[[nodiscard]] KOKKOS_FORCEINLINE_FUNCTION constexpr value_type& | ||
operator()(int m, int l, int k, int j, int i) noexcept | ||
{ | ||
return internal_data_[m][l][k][j][i]; | ||
} | ||
}; | ||
|
||
} // namespace sierra::nalu | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.