Mirrors
1. Overview
Mirrors are views that reference data in a possibly different memory space. They are used to access data in a different memory space without copying it.
Mirroring schematic
Kokkos::View<double**, Space> view(...);
auto host_mirror = Kokkos::create_mirror_view(view);
Two views are created: view
in the memory space Space
and host_mirror
in the host memory space.
The data are copied back and forth between the two views using the Kokkos::deep_copy
function.
2. Mirroring pattern
-
Create a
view
in a specific memory space.
Kokkos::View<double**, Space> view(...);
-
Create a mirror view in the host memory space,
host_mirror
.
auto host_mirror = Kokkos::create_mirror_view(view);
-
Populate
host_mirror
with data (from file, user input, etc.). -
Copy data from
host_mirror
toview
usingKokkos::deep_copy
. -
Perform computations on
view
:
Kokkos::parallel_for("Operation",
RangePolicy<Space>(0, view.extent(0)),
KOKKOS_LAMBDA(...) { /* use and change view */ }
);
-
If nedded, copy data back to
host_mirror
usingKokkos::deep_copy
.
Kokkos::deep_copy(host_mirror, view);
create_mirror_view allocates data only if the host process cannon access view 's data.
Otherwise, it returns a view that references the same data as view .
The command create_mirror makes always make data allocation.
|
C++