forked from kokkos/kokkos
-
Notifications
You must be signed in to change notification settings - Fork 0
Kokkos::deep_copy
Christian Trott edited this page May 1, 2020
·
11 revisions
Header File: Kokkos_Core.hpp
Usage:
Kokkos::deep_copy(exec_space, dest, src);
Kokkos::deep_copy(dest, src);
Copies data from src
to dest
, where src
and dest
can be Kokkos::Views or scalars under certain circumstances.
template <class ExecSpace, class ViewDest, class ViewSrc>
void Kokkos::deep_copy(const ExecSpace& exec_space,
const ViewDest& dest,
const ViewSrc& src);
template <class ExecSpace, class ViewDest>
void Kokkos::deep_copy(const ExecSpace& exec_space,
const ViewDest& dest,
const typename ViewDest::value_type& src);
template <class ExecSpace, class ViewSrc>
void Kokkos::deep_copy(const ExecSpace& exec_space,
ViewSrc::value_type& dest,
const ViewSrc& src);
template <class ViewDest, class ViewSrc>
void Kokkos::deep_copy(const ViewDest& dest,
const ViewSrc& src);
template <class ViewDest>
void Kokkos::deep_copy(const ViewDest& dest,
const typename ViewDest::value_type& src);
template <class ViewSrc>
void Kokkos::deep_copy(ViewSrc::value_type& dest,
const ViewSrc& src);
- ExecSpace: An ExecutionSpace
- ViewDest: A Kokkos::View of non-const data i.e.
- ViewSrc: A Kokkos::View.
- If
src
anddest
are Kokkos::Views, then all the following are true:std::is_same<ViewDest::non_const_value_type,ViewSrc::non_const_value_type>::value == true
ViewDest::rank == ViewSrc::rank
- For all
k
in[0, ViewDest::rank)
dest.extent(k) == src.extent(k)
-
src.span_is_contiguous() && dest.span_is_contiguous()
OR there exists an ExecutionSpacecopy_space
such that bothSpaceAccessibility<copy_space,ViewDest::memory_space>::accessible == true
andSpaceAccessibility<copy_space,ViewSrc::memory_space>::accessible == true
.
- If
src
is a Kokkos::View anddest
is a scalar, thensrc.rank == 0
is true.
- If no ExecutionSpace argument is provided, all outstanding operations (kernels, copy operation) will be finished before the copy is executed, and the copy operation is finished before the call returns.
- If an ExecutionSpace argument
exec_space
is provided the call is potentially asynchronous - i.e. the call returns before the copy operation is executed. In that case the copy operation will occur only after any already submitted work toexec_space
is finished, and the copy operation will be finished before any work submitted toexec_space
after thedeep_copy
call returns is executed.
#include<Kokkos_Core.hpp>
#include<cstdio>
int main(int argc, char* argv[]) {
Kokkos::initialize(argc,argv);
{
int N = argc>1?atoi(argv[1]):12;
if(N<6) N = 12;
// Contiguous Device View
Kokkos::View<int**, Kokkos::LayoutLeft> d_a("A",N,10);
// Non Contiguous Device View
auto d_a_2 = Kokkos::subview(d_a,2,Kokkos::ALL);
auto d_a_5 = Kokkos::subview(d_a,5,Kokkos::ALL);
// Contiguous Host View
auto h_a = Kokkos::create_mirror_view(d_a);
// Non Contiguous Host Views
auto h_d_a_2 = Kokkos::subview(h_a,2,Kokkos::ALL);
auto h_a_5 = Kokkos::subview(h_a,5,Kokkos::ALL);
// A Scalar View
auto d_a_2_5 = Kokkos::subview(d_a,2,5);
int scalar;
// Deep Copy Scalar into every element of a view
Kokkos::deep_copy(d_a,3);
Kokkos::deep_copy(d_a_2,5);
// Deep Copy between two non-contiguous views with a common execution space
Kokkos::deep_copy(d_a_2,d_a5);
// Deep Copy between two non-contiguous views with potentially no common execution space
// This fails for example if you compile the code with Cuda
// Kokkos::deep_copy(h_a_2,d_a_2);
// Deep Copy contiguous views
Kokkos::deep_copy(h_a,d_a);
// Deep Copy Scalar View into a scalar
Kokkos::deep_copy(scalar,d_a_2_5);
}
Kokkos::finalize();
}
Home:
- Introduction
- Machine Model
- Programming Model
- Compiling
- Initialization
- View
- Parallel Dispatch
- Hierarchical Parallelism
- Custom Reductions
- Atomic Operations
- Subviews
- Interoperability
- Kokkos and Virtual Functions
- Initialization and Finalization
- View
- Data Parallelism
- Execution Policies
- Spaces
- Task Parallelism
- Utilities
- STL Compatibility
- Numerics
- Detection Idiom