Skip to content

Commit

Permalink
Fix more view of views
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrete committed Nov 7, 2024
1 parent e632f6b commit 120ceef
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Parthenon -- a performance portable block-structured adaptive mesh refinement fr

* CMake 3.16 or greater
* C++17 compatible compiler
* Kokkos 4.1.1 or greater
* Kokkos 4.4.1 or greater

## Optional (enabling features)

Expand Down
3 changes: 0 additions & 3 deletions src/bvals/bvals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,6 @@ class BoundarySwarm : public BoundaryCommunication {
explicit BoundarySwarm(std::weak_ptr<MeshBlock> pmb, const std::string &label);
~BoundarySwarm() = default;

std::vector<ParArrayND<int>> vars_int;
std::vector<ParArrayND<Real>> vars_real;

// (usuallly the std::size_t unsigned integer type)
std::vector<BoundaryCommunication *>::size_type bswarm_index;

Expand Down
2 changes: 1 addition & 1 deletion src/bvals/comms/bnd_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
namespace parthenon {

void ProResCache_t::Initialize(int n_regions, StateDescriptor *pkg) {
prores_info = ParArray1D<ProResInfo>("prores_info", n_regions);
prores_info = ProResInfoArr_t(ViewOfViewAlloc("prores_info"), n_regions);
prores_info_h = Kokkos::create_mirror_view(
Kokkos::view_alloc(Kokkos::SequentialHostInit), prores_info);
int nref_funcs = pkg->NumRefinementFuncs();
Expand Down
5 changes: 3 additions & 2 deletions src/bvals/comms/bnd_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "bvals/neighbor_block.hpp"
#include "coordinates/coordinates.hpp"
#include "interface/variable_state.hpp"
#include "kokkos_abstraction.hpp"
#include "mesh/domain.hpp"
#include "mesh/forest/logical_coordinate_transformation.hpp"
#include "utils/communication_buffer.hpp"
Expand Down Expand Up @@ -130,8 +131,8 @@ int GetBufferSize(MeshBlock *pmb, const NeighborBlock &nb,
using BndInfoArr_t = Kokkos::View<BndInfo *, LayoutWrapper, DevMemSpace>;
using BndInfoArrHost_t = typename BndInfoArr_t::HostMirror;

using ProResInfoArr_t = ParArray1D<ProResInfo>;
using ProResInfoArrHost_t = typename ParArray1D<ProResInfo>::HostMirror;
using ProResInfoArr_t = Kokkos::View<ProResInfo *, LayoutWrapper, DevMemSpace>;
using ProResInfoArrHost_t = typename ProResInfoArr_t::HostMirror;
class StateDescriptor;
struct ProResCache_t {
ProResInfoArr_t prores_info{};
Expand Down
3 changes: 2 additions & 1 deletion src/bvals/comms/bvals_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "bvals/comms/bnd_info.hpp"
#include "bvals/comms/bvals_in_one.hpp"
#include "interface/variable.hpp"
#include "kokkos_abstraction.hpp"
#include "mesh/domain.hpp"
#include "mesh/mesh.hpp"
#include "mesh/meshblock.hpp"
Expand Down Expand Up @@ -215,7 +216,7 @@ inline void RebuildBufferCache(std::shared_ptr<MeshData<Real>> md, int nbound,
using namespace loops;
using namespace loops::shorthands;
BvarsSubCache_t &cache = md->GetBvarsCache().GetSubCache(BOUND_TYPE, SENDER);
cache.bnd_info = BndInfoArr_t("bnd_info", nbound);
cache.bnd_info = BndInfoArr_t(ViewOfViewAlloc("bnd_info"), nbound);
cache.bnd_info_h = Kokkos::create_mirror_view(
Kokkos::view_alloc(Kokkos::SequentialHostInit), cache.bnd_info);

Expand Down
4 changes: 3 additions & 1 deletion src/interface/mesh_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "interface/sparse_pack_base.hpp"
#include "interface/swarm_pack_base.hpp"
#include "interface/variable_pack.hpp"
#include "kokkos_abstraction.hpp"
#include "mesh/domain.hpp"
#include "mesh/meshblock.hpp"
#include "mesh/meshblock_pack.hpp"
Expand Down Expand Up @@ -149,7 +150,8 @@ const MeshBlockPack<P> &PackOnMesh(M &map, BlockDataList_t<Real> &block_data_,
}

if (make_new_pack) {
ParArray1D<P> packs("MeshData::PackVariables::packs", nblocks);
Kokkos::View<P *, LayoutWrapper, DevMemSpace> packs(
ViewOfViewAlloc("MeshData::PackVariables::packs"), nblocks);
auto packs_host =
Kokkos::create_mirror_view(Kokkos::view_alloc(Kokkos::SequentialHostInit), packs);

Expand Down
5 changes: 3 additions & 2 deletions src/interface/sparse_pack_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "interface/sparse_pack_base.hpp"
#include "interface/state_descriptor.hpp"
#include "interface/variable.hpp"
#include "kokkos_abstraction.hpp"
#include "utils/utils.hpp"
namespace parthenon {
namespace impl {
Expand Down Expand Up @@ -151,7 +152,7 @@ SparsePackBase SparsePackBase::Build(T *pmd, const PackDescriptor &desc,
} else if (contains_face_or_edge) {
leading_dim += 2;
}
pack.pack_ = pack_t("data_ptr", leading_dim, pack.nblocks_, max_size);
pack.pack_ = pack_t(ViewOfViewAlloc("data_ptr"), leading_dim, pack.nblocks_, max_size);
pack.pack_h_ = Kokkos::create_mirror_view(
Kokkos::view_alloc(Kokkos::SequentialHostInit), pack.pack_);

Expand All @@ -168,7 +169,7 @@ SparsePackBase SparsePackBase::Build(T *pmd, const PackDescriptor &desc,
pack.block_props_ = block_props_t("block_props", nblocks, 27 + 1);
pack.block_props_h_ = Kokkos::create_mirror_view(pack.block_props_);

pack.coords_ = coords_t("coords", desc.flat ? max_size : nblocks);
pack.coords_ = coords_t(ViewOfViewAlloc("coords"), desc.flat ? max_size : nblocks);
auto coords_h = Kokkos::create_mirror_view(
Kokkos::view_alloc(Kokkos::SequentialHostInit), pack.coords_);

Expand Down
4 changes: 3 additions & 1 deletion src/interface/sparse_pack_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "interface/state_descriptor.hpp"
#include "interface/variable.hpp"
#include "interface/variable_state.hpp"
#include "kokkos_abstraction.hpp"
#include "utils/utils.hpp"

namespace parthenon {
Expand All @@ -55,7 +56,8 @@ class SparsePackBase {

using alloc_t = std::vector<int>;
using include_t = std::vector<bool>;
using pack_t = ParArray3D<ParArray3D<Real, VariableState>>;
using pack_t =
Kokkos::View<ParArray3D<Real, VariableState> ***, LayoutWrapper, DevMemSpace>;
using pack_h_t = typename pack_t::HostMirror;
using bounds_t = ParArray3D<int>;
using bounds_h_t = typename bounds_t::HostMirror;
Expand Down
11 changes: 6 additions & 5 deletions src/interface/swarm_pack_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "interface/state_descriptor.hpp"
#include "interface/swarm_device_context.hpp"
#include "interface/variable.hpp"
#include "kokkos_abstraction.hpp"
#include "utils/utils.hpp"

namespace parthenon {
Expand All @@ -43,10 +44,10 @@ class SwarmPackBase {
SwarmPackBase() = default;
virtual ~SwarmPackBase() = default;

using pack_t = ParArray3D<ParArray1D<TYPE>>;
using pack_t = Kokkos::View<ParArray1D<TYPE> ***, LayoutWrapper, DevMemSpace>;
using bounds_t = ParArray3D<int>;
using contexts_t = ParArray1D<SwarmDeviceContext>;
using contexts_h_t = typename ParArray1D<SwarmDeviceContext>::HostMirror;
using contexts_t = Kokkos::View<SwarmDeviceContext *, LayoutWrapper, DevMemSpace>;
using contexts_h_t = typename contexts_t::HostMirror;
using max_active_indices_t = ParArray1D<int>;
using desc_t = impl::SwarmPackDescriptor<TYPE>;
using idx_map_t = std::unordered_map<std::string, std::size_t>;
Expand Down Expand Up @@ -108,7 +109,7 @@ class SwarmPackBase {

// Allocate the views
int leading_dim = 1;
pack.pack_ = pack_t("data_ptr", leading_dim, nblocks, max_size);
pack.pack_ = pack_t(ViewOfViewAlloc("data_ptr"), leading_dim, nblocks, max_size);
auto pack_h = Kokkos::create_mirror_view(
Kokkos::view_alloc(Kokkos::SequentialHostInit), pack.pack_);

Expand Down Expand Up @@ -154,7 +155,7 @@ class SwarmPackBase {
Kokkos::deep_copy(pack.pack_, pack_h);
Kokkos::deep_copy(pack.bounds_, bounds_h);

pack.contexts_ = contexts_t("contexts", nblocks);
pack.contexts_ = contexts_t(ViewOfViewAlloc("contexts"), nblocks);
pack.contexts_h_ = Kokkos::create_mirror_view(
Kokkos::view_alloc(Kokkos::SequentialHostInit), pack.contexts_);
pack.max_active_indices_ = max_active_indices_t("max_active_indices", nblocks);
Expand Down
2 changes: 2 additions & 0 deletions tst/unit/test_pararrays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,8 @@ TEST_CASE("Check registry pressure", "[ParArrayND][performance]") {

// view of views. See:
// https://github.com/kokkos/kokkos/wiki/View#6232-whats-the-problem-with-a-view-of-views
// TODO(PG) depending on the results of the view of view discussion, we should add
// destructor or ViewOfViewAlloc with SequentialHostInit
using view_3d_t =
Kokkos::View<Real ***, parthenon::LayoutWrapper, parthenon::DevMemSpace>;
using arrays_t = Kokkos::View<parthenon::ParArray6D<Real> *, UVMSpace>;
Expand Down

0 comments on commit 120ceef

Please sign in to comment.