Kokkos: issue with constructing std::tuple<Kokkos::DualView<>...>

Created on 19 Apr 2018  路  2Comments  路  Source: kokkos/kokkos

Consider the following:

#include <Kokkos_Core.hpp>
#include <Kokkos_Random.hpp>
#include <Kokkos_DualView.hpp>
#include <tuple>
#include <iostream>

using DVINT = Kokkos::DualView<int>;
using DVFLOAT = Kokkos::DualView<float>;
using HostMirrorSpace = typename DVINT::host_mirror_space;
using MemorySpace = typename DVINT::memory_space;
int main(int argc, char* argv[])
{
  // Initialize Kokkos
  Kokkos::initialize(argc,argv); {

  const std::size_t N = 10;
  std::tuple<DVINT,DVFLOAT> tupleDVs(DVINT{"dvint",N}, DVFLOAT{"dvfloat",N});
  //std::get<0>(tupleDVs).resize(N); //uncommenting leads to compilation error
  std::cout << std::get<0>(tupleDVs).extent(0) << std::endl;

  } Kokkos::finalize();
}

This prints 1 instead of 10. I thought the tuple construction would invoke the DualView copy constructor which assigns the tupled DualView to the allocated space of N but obviously that's not the case. Also, if I try resizing after the constructor, I will get the following compilation error:

kokkos/core/src/Kokkos_CopyViews.hpp: In instantiation of 'typename std::enable_if<(std::is_same<typename Kokkos::View<D, P ...>::array_layout, Kokkos::LayoutLeft>::value || std::is_same<typename Kokkos::View<D, P ...>::array_layout, Kokkos::LayoutRight>::value)>::type Kokkos::resize(Kokkos::View<D, P ...>&, size_t, size_t, size_t, size_t, size_t, size_t, size_t, size_t) [with T = int; P = {void, void, void}; typename std::enable_if<(std::is_same<typename Kokkos::View<D, P ...>::array_layout, Kokkos::LayoutLeft>::value || std::is_same<typename Kokkos::View<D, P ...>::array_layout, Kokkos::LayoutRight>::value)>::type = void; size_t = long unsigned int]':
/home/aznb/mycodes/kokkos/containers/src/Kokkos_DualView.hpp:496:22:   required from 'void Kokkos::DualView<DataType, Arg1Type, Arg2Type, Arg3Type>::resize(size_t, size_t, size_t, size_t, size_t, size_t, size_t, size_t) [with DataType = int; Arg1Type = void; Arg2Type = void; Arg3Type = void; size_t = long unsigned int]'
/home/aznb/mycodes/MC/testtuple.cpp:72:33:   required from here
/home/aznb/mycodes/kokkos/core/src/Kokkos_CopyViews.hpp:1654:17: error: invalid use of incomplete type 'struct Kokkos::Impl::ViewRemap<Kokkos::View<int, void, void, void>, Kokkos::View<int, void, void, void>, Kokkos::OpenMP, 0>'
   Kokkos::Impl::ViewRemap< view_type , view_type >( v_resized , v );
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/aznb/mycodes/kokkos/core/src/Kokkos_CopyViews.hpp:612:8: note: declaration of 'struct Kokkos::Impl::ViewRemap<Kokkos::View<int, void, void, void>, Kokkos::View<int, void, void, void>, Kokkos::OpenMP, 0>'
 struct ViewRemap;
        ^~~~~~~~~
/home/aznb/mycodes/kokkos/core/src/Kokkos_CopyViews.hpp: In instantiation of 'typename std::enable_if<(std::is_same<typename Kokkos::View<D, P ...>::array_layout, Kokkos::LayoutLeft>::value || std::is_same<typename Kokkos::View<D, P ...>::array_layout, Kokkos::LayoutRight>::value)>::type Kokkos::resize(Kokkos::View<D, P ...>&, size_t, size_t, size_t, size_t, size_t, size_t, size_t, size_t) [with T = int; P = {Kokkos::LayoutRight, Kokkos::OpenMP}; typename std::enable_if<(std::is_same<typename Kokkos::View<D, P ...>::array_layout, Kokkos::LayoutLeft>::value || std::is_same<typename Kokkos::View<D, P ...>::array_layout, Kokkos::LayoutRight>::value)>::type = void; size_t = long unsigned int]':
/home/aznb/mycodes/kokkos/containers/src/Kokkos_DualView.hpp:516:24:   required from 'void Kokkos::DualView<DataType, Arg1Type, Arg2Type, Arg3Type>::resize(size_t, size_t, size_t, size_t, size_t, size_t, size_t, size_t) [with DataType = int; Arg1Type = void; Arg2Type = void; Arg3Type = void; size_t = long unsigned int]'
/home/aznb/mycodes/MC/testtuple.cpp:72:33:   required from here
/home/aznb/mycodes/kokkos/core/src/Kokkos_CopyViews.hpp:1654:17: error: invalid use of incomplete type 'struct Kokkos::Impl::ViewRemap<Kokkos::View<int, Kokkos::LayoutRight, Kokkos::OpenMP>, Kokkos::View<int, Kokkos::LayoutRight, Kokkos::OpenMP>, Kokkos::OpenMP, 0>'
   Kokkos::Impl::ViewRemap< view_type , view_type >( v_resized , v );
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/aznb/mycodes/kokkos/core/src/Kokkos_CopyViews.hpp:612:8: note: declaration of 'struct Kokkos::Impl::ViewRemap<Kokkos::View<int, Kokkos::LayoutRight, Kokkos::OpenMP>, Kokkos::View<int, Kokkos::LayoutRight, Kokkos::OpenMP>, Kokkos::OpenMP, 0>'
 struct ViewRemap;
        ^~~~~~~~~

What am I missing here?

question

All 2 comments

You're declaring Kokkos::DualView<int>, which means it only stores one int. You need to declare them as Kokkos::DualView<int*> and similarly for the double one. Also, if you turn of the deprecated code option in Kokkos, you should get much better error checking of this (the constructor should fail at runtime).

Oops, it's my bad and turning off KOKKOS_ENABLE_DEPRECATED_CODE does trigger a runtime error. You can close this now.

Was this page helpful?
0 / 5 - 0 ratings