Skip to content

Latest commit

 

History

History
444 lines (253 loc) · 17 KB

DynRankView.rst

File metadata and controls

444 lines (253 loc) · 17 KB

DynRankView

Header file: <Kokkos_DynRankView.hpp>

Usage

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.

Description

Assignment Rules

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 as SrcType::non_const_value_type
  • If std::is_const<SrcType::value_type>::value == true than std::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 nor SrcType::array_layout is LayoutStride:
    • If DstType::rank > 1 than DstType::array_layout must be the same as SrcType::array_layout.
  • If either DstType::array_layout or SrcType::array_layout is LayoutStride
    • For each dimension k it must hold that dst_view.extent(k) == src_view.extent(k)

Examples

#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();
}