From f57c961f58265831fe8a2608594f918dae858233 Mon Sep 17 00:00:00 2001 From: Mark Hoemmen Date: Thu, 18 Feb 2016 12:38:13 -0700 Subject: [PATCH] Kokkos,Tpetra: Change default graph/matrix offset type to LO The default Kokkos::StaticCrsGraph<...>::size_type (type of row offsets) is now the same as the type of column indices. Ditto for KokkosSparse::CrsMatrix and Tpetra::CrsGraph and Tpetra::CrsMatrix. Had to do some awful metatype stuff to fix the FENL example, which weirdly wants to create a Kokkos::StaticCrsGraph whose column indices are unsigned[2] (???). --- .../containers/src/Kokkos_StaticCrsGraph.hpp | 28 ++++++++++++++++++---- packages/tpetra/core/src/Tpetra_CrsGraph_decl.hpp | 4 ++-- .../tpetra/kernels/src/Kokkos_Sparse_CrsMatrix.hpp | 9 +++---- .../tpetra/kernels/unit_test/TestCrsMatrix.cpp | 18 +++++++------- 4 files changed, 40 insertions(+), 19 deletions(-) diff --git a/packages/kokkos/containers/src/Kokkos_StaticCrsGraph.hpp b/packages/kokkos/containers/src/Kokkos_StaticCrsGraph.hpp index 1ce3863..3467485 100644 --- a/packages/kokkos/containers/src/Kokkos_StaticCrsGraph.hpp +++ b/packages/kokkos/containers/src/Kokkos_StaticCrsGraph.hpp @@ -1,13 +1,13 @@ /* //@HEADER // ************************************************************************ -// +// // Kokkos v. 2.0 // Copyright (2014) Sandia Corporation -// +// // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, // the U.S. Government retains certain rights in this software. -// +// // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: @@ -36,7 +36,7 @@ // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // // Questions? Contact H. Carter Edwards (hcedwar@sandia.gov) -// +// // ************************************************************************ //@HEADER */ @@ -51,6 +51,21 @@ namespace Kokkos { +namespace { // (anonymous) + template + struct GetDefaultSizeType { + typedef ViewTraits traits_type; + typedef typename traits_type::device_type::memory_space::size_type size_type; + + static const bool canUse = std::is_integral >::value; + + typedef typename Kokkos::Impl::if_c::type, + size_type>::type type; + }; + +} // namespace (anonymous) + /// \class StaticCrsGraph /// \brief Compressed row storage array. /// @@ -84,8 +99,11 @@ namespace Kokkos { template< class DataType, class Arg1Type, class Arg2Type = void, - typename SizeType = typename ViewTraits::size_type> + typename SizeType = typename GetDefaultSizeType::type> class StaticCrsGraph { + static_assert (std::is_integral::value, "SizeType must be an integer."); + static_assert (! std::is_pointer::value, "SizeType must not be a pointer."); + private: typedef ViewTraits traits; diff --git a/packages/tpetra/core/src/Tpetra_CrsGraph_decl.hpp b/packages/tpetra/core/src/Tpetra_CrsGraph_decl.hpp index 8efe0fa..d8c8876 100644 --- a/packages/tpetra/core/src/Tpetra_CrsGraph_decl.hpp +++ b/packages/tpetra/core/src/Tpetra_CrsGraph_decl.hpp @@ -299,8 +299,8 @@ namespace Tpetra { //! The type of the part of the sparse graph on each MPI process. typedef Kokkos::StaticCrsGraph local_graph_type; + execution_space> local_graph_type; + //! DEPRECATED; use local_graph_type (above) instead. typedef local_graph_type LocalStaticCrsGraphType TPETRA_DEPRECATED; diff --git a/packages/tpetra/kernels/src/Kokkos_Sparse_CrsMatrix.hpp b/packages/tpetra/kernels/src/Kokkos_Sparse_CrsMatrix.hpp index 6809f5a..2e62cfc 100644 --- a/packages/tpetra/kernels/src/Kokkos_Sparse_CrsMatrix.hpp +++ b/packages/tpetra/kernels/src/Kokkos_Sparse_CrsMatrix.hpp @@ -51,8 +51,9 @@ #ifndef KOKKOS_SPARSE_CRSMATRIX_HPP_ #define KOKKOS_SPARSE_CRSMATRIX_HPP_ -#include -#include +#include "TpetraKernels_config.h" +#include "Kokkos_Core.hpp" +#include "Kokkos_StaticCrsGraph.hpp" #include #include @@ -363,7 +364,7 @@ template::size_type> + class SizeType = typename Kokkos::StaticCrsGraph::size_type> class CrsMatrix { private: typedef typename Kokkos::ViewTraits::host_mirror_space host_mirror_space ; @@ -387,7 +388,7 @@ public: typedef SizeType size_type; //! Type of a host-memory mirror of the sparse matrix. - typedef CrsMatrix HostMirror; + typedef CrsMatrix HostMirror; //! Type of the graph structure of the sparse matrix. typedef Kokkos::StaticCrsGraph StaticCrsGraphType; //! Type of column indices in the sparse matrix. diff --git a/packages/tpetra/kernels/unit_test/TestCrsMatrix.cpp b/packages/tpetra/kernels/unit_test/TestCrsMatrix.cpp index 4fde6dd..23c4582 100644 --- a/packages/tpetra/kernels/unit_test/TestCrsMatrix.cpp +++ b/packages/tpetra/kernels/unit_test/TestCrsMatrix.cpp @@ -65,7 +65,7 @@ namespace { // anonymous // \param whichMatrix [in] The index of the matrix to create. template void - makeSparseMatrix (Kokkos::View& ptr, + makeSparseMatrix (Kokkos::View::size_type*, MemorySpace>& ptr, Kokkos::View& ind, Kokkos::View& val, int& numRows, @@ -76,7 +76,7 @@ namespace { // anonymous using Kokkos::HostSpace; using Kokkos::MemoryUnmanaged; using Kokkos::View; - typedef typename MemorySpace::size_type size_type; + typedef typename KokkosSparse::CrsMatrix::size_type size_type; if (whichMatrix == 0) { numRows = 10; @@ -130,12 +130,14 @@ namespace { // anonymous } } - // Return the Kokkos::CrsMatrix corresponding to makeSparseMatrix(). + // Return the KokkosSparse::CrsMatrix corresponding to makeSparseMatrix(). template - Kokkos::CrsMatrix + KokkosSparse::CrsMatrix makeCrsMatrix () { - Kokkos::View ptr; + typedef KokkosSparse::CrsMatrix crs_matrix_type; + + Kokkos::View ptr; Kokkos::View ind; Kokkos::View val; int numRows; @@ -144,11 +146,11 @@ namespace { // anonymous const int whichMatrix = 0; makeSparseMatrix (ptr, ind, val, numRows, numCols, nnz, whichMatrix); - typedef Kokkos::CrsMatrix crs_matrix_type; + return crs_matrix_type ("A", numRows, numCols, nnz, val, ptr, ind); } - // Create a Kokkos::CrsMatrix. This mainly tests that the class + // Create a KokkosSparse::CrsMatrix. This mainly tests that the class // compiles. However, it does need to initialize the MemorySpace's // default execution space, because it allocates Views and calls // deep_copy a few times. @@ -158,7 +160,7 @@ namespace { // anonymous { Kokkos::initialize(); - typedef Kokkos::CrsMatrix crs_matrix_type; + typedef KokkosSparse::CrsMatrix crs_matrix_type; crs_matrix_type A = makeCrsMatrix (); // mfh 28 Sep 2013: Use A in some way, so the compiler can't // optimize it away completely. This forces the compiler to -- 2.1.3