Header file: <Kokkos_DynRankView.hpp>
DynRankView
is a potential reference counted multidimensional array with compile time layouts and memory space. Its semantics are similar to that of std::shared_ptr
. The DynRankView
differs from the [[View|Kokkos::View]] in that its rank is not provided with the DataType
template parameter; it is determined dynamically based on the number of extent arguments passed to the constructor. The rank has an upper bound of 7 dimensions.
Assignment rules cover the assignment operator as well as copy constructors. We aim at making all logically legal assignments possible, while intercepting illegal assignments if possible at compile time, otherwise at runtime. In the following, we use DstType
and SrcType
as the type of the destination view and source view respectively. dst_view
and src_view
refer to the runtime instances of the destination and source views, i.e.:
ScrType src_view(...);
DstType dst_view(src_view);
dst_view = src_view;
The following conditions must be met at and are evaluated at compile time:
DstType::rank == SrcType::rank
DstType::non_const_value_type
is the same asSrcType::non_const_value_type
- If
std::is_const<SrcType::value_type>::value == true
thanstd::is_const<DstType::value_type>::value == true
. MemorySpaceAccess<DstType::memory_space,SrcType::memory_space>::assignable == true
Furthermore there are rules which must be met if DstType::array_layout
is not the same as SrcType::array_layout
. These rules only cover cases where both layouts are one of LayoutLeft
, LayoutRight
or LayoutStride
- If neither
DstType::array_layout
norSrcType::array_layout
isLayoutStride
: - If
DstType::rank > 1
thanDstType::array_layout
must be the same asSrcType::array_layout
.
- If
- If neither
- If either
DstType::array_layout
orSrcType::array_layout
isLayoutStride
- For each dimension
k
it must hold thatdst_view.extent(k) == src_view.extent(k)
- For each dimension
- If either
#include<Kokkos_Core.hpp>
#include<cstdio>
int main(int argc, char* argv[]) {
Kokkos::initialize(argc,argv);
int N0 = atoi(argv[1]);
int N1 = atoi(argv[2]);
Kokkos::DynRankView<double> a("A",N0);
Kokkos::DynRankView<double> b("B",N1);
Kokkos::parallel_for("InitA", N0, KOKKOS_LAMBDA (const int& i) {
a(i) = i;
});
Kokkos::parallel_for("InitB", N1, KOKKOS_LAMBDA (const int& i) {
b(i) = i;
});
Kokkos::DynRankView<double,Kokkos::LayoutLeft> c("C",N0,N1);
{
Kokkos::DynRankView<const double> const_a(a);
Kokkos::DynRankView<const double> const_b(b);
Kokkos::parallel_for("SetC", Kokkos::MDRangePolicy<Kokkos::Rank<2,Kokkos::Iterate::Left>>({0,0},{N0,N1}),
KOKKOS_LAMBDA (const int& i0, const int& i1) {
c(i0,i1) = a(i0) * b(i1);
});
}
Kokkos::finalize();
}