create_mirror[_view]#
Header File: Kokkos_Core.hpp
A common desired use case is to have a memory allocation in GPU memory and an identical memory allocation in CPU memory, such that copying from one to another is straightforward. To satisfy this use case and others, Kokkos has facilities for dealing with “mirrors” of View. A “mirror” of a View type A is loosely defined a View type B such that Views of type B are accessible from the CPU and deep_copy between Views of type A and B are direct. The most common functions for dealing with mirrors are create_mirror, create_mirror_view and create_mirror_view_and_copy.
Usage:
auto host_mirror = create_mirror(a_view);
auto host_mirror_view = create_mirror_view(a_view);
auto host_mirror_space = create_mirror(ExecSpace(),a_view);
auto host_mirror_view_space = create_mirror_view(ExecSpace(),a_view);
Synopsis#
template <class ViewType>
typename ViewType::HostMirror create_mirror(ViewType const&);
template <class ViewType>
typename ViewType::HostMirror create_mirror(decltype(Kokkos::WithoutInitializing),
ViewType const&);
template <class Space, class ViewType>
ImplMirrorType create_mirror(Space const& space, ViewType const&);
template <class Space, class ViewType>
ImplMirrorType create_mirror(decltype(Kokkos::WithoutInitializing),
Space const& space, ViewType const&);
template <class ViewType, class... ViewCtorArgs>
auto create_mirror(Impl::ViewCtorProp<ViewCtorArgs...> const& arg_prop,
ViewType const& v);
template <class ViewType>
typename ViewType::HostMirror create_mirror_view(ViewType const&);
template <class ViewType>
typename ViewType::HostMirror create_mirror_view(decltype(Kokkos::WithoutInitializing),
ViewType const&);
template <class Space, class ViewType>
ImplMirrorType create_mirror_view(Space const& space, ViewType const&);
template <class Space, class ViewType>
ImplMirrorType create_mirror_view(decltype(Kokkos::WithoutInitializing),
Space const& space, ViewType const&);
template <class ViewType, class... ViewCtorArgs>
auto create_mirror_view(Impl::ViewCtorProp<ViewCtorArgs...> const& arg_prop,
ViewType const& v);
template <class Space, class ViewType>
ImplMirrorType create_mirror_view_and_copy(Space const& space, ViewType const&);
template <class ViewType, class... ViewCtorArgs>
auto create_mirror_view_and_copy(Impl::ViewCtorProp<ViewCtorArgs...> const& arg_prop,
ViewType const& v);
Description#
template <class ViewType> typename ViewType::HostMirror create_mirror(ViewType const& src);
Creates a new host accessible
Viewwith the same layout and padding assrc.src: aKokkos::View.
template <class ViewType> typename ViewType::HostMirror create_mirror(decltype(Kokkos::WithoutInitializing), ViewType const& src);
Creates a new host accessible
Viewwith the same layout and padding assrc. The new view will have uninitialized data.src: aKokkos::View.
template <class Space, class ViewType> ImplMirrorType create_mirror(Space const& space, ViewType const&);
Creates a new
Viewwith the same layout and padding assrcbut with a device type ofSpace::device_type.src: aKokkos::View.Space: a class meeting the requirements ofExecutionSpaceConceptorMemorySpaceConceptImplMirrorType: an implementation defined specialization ofKokkos::View.
template <class Space, class ViewType> ImplMirrorType create_mirror(decltype(Kokkos::WithoutInitializing), Space const& space, ViewType const&);
Creates a new
Viewwith the same layout and padding assrcbut with a device type ofSpace::device_type. The new view will have uninitialized data.src: aKokkos::View.Space: a class meeting the requirements ofExecutionSpaceConceptorMemorySpaceConceptImplMirrorType: an implementation defined specialization ofKokkos::View.
template <class ViewType, class... ViewCtorArgs> auto create_mirror(Impl::ViewCtorProp<ViewCtorArgs...> const& arg_prop, ViewType const& v);
Creates a new
Viewwith the same layout and padding assrcusing theViewconstructor propertiesarg_prop, e.g.,Kokkos::view_alloc(Kokkos::WithoutInitializing). Ifarg_propcontains a memory space, aViewin that space is created. Otherwise, aViewin host-accessible memory is returned.src: aKokkos::View.arg_prop:Viewconstructor properties, e.g.,Kokkos::view_alloc(Kokkos::WithoutInitializing).
Restrictions:
arg_propmust not include a pointer to memory, or a label, or allow padding.template <class ViewType> typename ViewType::HostMirror create_mirror_view(ViewType const& src);
If
srcis not host accessible (i.e. ifSpaceAccessibility<HostSpace,ViewType::memory_space>::accessibleisfalse) it creates a new host accessibleViewwith the same layout and padding assrc. Otherwise returnssrc.src: aKokkos::View.
template <class ViewType> typename ViewType::HostMirror create_mirror_view(decltype(Kokkos::WithoutInitializing), ViewType const& src);
If
srcis not host accessible (i.e. ifSpaceAccessibility<HostSpace,ViewType::memory_space>::accessibleisfalse) it creates a new host accessibleViewwith the same layout and padding assrc. The new view will have uninitialized data. Otherwise returnssrc.src: aKokkos::View.
template <class Space, class ViewType> ImplMirrorType create_mirror_view(Space const& space, ViewType const&);
If
std::is_same<typename Space::memory_space, typename ViewType::memory_space>::valueisfalse, creates a newViewwith the same layout and padding assrcbut with a device type ofSpace::device_type. Otherwise returnssrc.src: aKokkos::View.Space: a class meeting the requirements ofExecutionSpaceConceptorMemorySpaceConceptImplMirrorType: an implementation defined specialization ofKokkos::View.
template <class Space, class ViewType> ImplMirrorType create_mirror_view(decltype(Kokkos::WithoutInitializing), Space const& space, ViewType const& src);
If
std::is_same<typename Space::memory_space, typename ViewType::memory_space>::valueisfalse, creates a newViewwith the same layout and padding assrcbut with a device type ofSpace::device_type. The new view will have uninitialized data. Otherwise returnssrc.src: aKokkos::View.Space: a class meeting the requirements ofExecutionSpaceConceptorMemorySpaceConceptImplMirrorType: an implementation defined specialization ofKokkos::View.
template <class ViewType, class... ViewCtorArgs> auto create_mirror_view(Impl::ViewCtorProp<ViewCtorArgs...> const& arg_prop, ViewType const& src);
If the
Viewconstructor argumentsarg_propinclude a memory space and the memory space doesn’t match the memory space ofsrc, creates a newViewin the specified memory_space. If thearg_propdon’t include a memory space and the memory space ofsrcis not host-accessible, creates a new host-accessibleView. Otherwise,srcis returned. If a newViewis created, the implicitly called constructor respectsarg_propand uses the same layout and padding assrc.src: aKokkos::View.arg_prop:Viewconstructor properties, e.g.,Kokkos::view_alloc(Kokkos::WithoutInitializing).
Restrictions:
arg_propmust not include a pointer to memory, or a label, or allow padding.template <class Space, class ViewType> ImplMirrorType create_mirror_view_and_copy(Space const& space, ViewType const&);
If
std::is_same<typename Space::memory_space, typename ViewType::memory_space>::valueisfalse, creates a newKokkos::Viewwith the same layout and padding assrcbut with a device type ofSpace::device_typeand conducts adeep_copyfromsrcto the new view if one was created. Otherwise returnssrc.src: aKokkos::View.Space: a class meeting the requirements ofExecutionSpaceConceptorMemorySpaceConceptImplMirrorType: an implementation defined specialization ofKokkos::View.
template <class ViewType, class... ViewCtorArgs> ImplMirrorType create_mirror_view_and_copy(Impl::ViewCtorProp<ViewCtorArgs...> const& arg_prop, ViewType const& src);
If the memory space included in the
Viewconstructor argumentsarg_propmatches the memory space ofsrc, creates a newViewin the specified memory space usingarg_propand the same layout andf padding assrc. Additionally, adeep_copyfromsrcto the new view is executed (using the execution space contained inarg_propif provided). Otherwise returnssrc.src: aKokkos::View.arg_prop:Viewconstructor properties, e.g.,Kokkos::view_alloc(Kokkos::HostSpace{}, Kokkos::WithoutInitializing).
Restrictions:
arg_propmust not include a pointer to memory, or a label, or allow padding.arg_propmust include a memory space.