Skip to content

Commit

Permalink
Jgfouca/par ilut (#1506)
Browse files Browse the repository at this point in the history
* Make par_ilut files by copying spiluk
* post rebase cleanups
* Remove ILUT alg selection
* Remove fill_level for numeric phase of par_ilut
* minor cleanup
* add candidates working
* Remove unused
* CUDA building and running
* add dbg printfs
* Add full numeric checks
* Fixes for upstream merge
* Get rid of unused template arg for spadd_symbolic
* Residual done
* Some cleanup and documentation
* Replace prefix_sum with much simpler impl
* Add deterministic option to par_ilut. Be sure to sort transpose_matrix output
* Remove debug output
* Switch from typedefs to using
* Improve doxygen for par ilut
* Warning cleanup
* Run clang formatter on everything
* Make handle destructor callable by device
* Change correct handle
* Fixes for complex scalar
* Fix spadd perf tests
* Remove numeric stuff from symbolic par_ilut
* Use struct to reduce type duplication
* Remove reinterpret casts again with fix
* Fix warnings
* Fix small type bug in ExclusiveParallelPrefixSum
* Fixes for when Kokkos::Serial is not available
* Formatting
* Fix uninitialized error for L|U_new_row_map
* Fix ExclusiveParallelPrefixSum to allow for uninitialized or garbage in last view element input
  • Loading branch information
jgfouca authored Oct 28, 2022
1 parent ea7d39a commit a2fb862
Show file tree
Hide file tree
Showing 27 changed files with 3,199 additions and 51 deletions.
28 changes: 24 additions & 4 deletions common/src/KokkosKernels_SimpleUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,16 @@ class SquareRootFunctor {

template <typename view_t>
struct ExclusiveParallelPrefixSum {
typedef typename view_t::value_type idx;
typedef typename view_t::value_type value_type;
view_t array_sum;
ExclusiveParallelPrefixSum(view_t arr_) : array_sum(arr_) {}

KOKKOS_INLINE_FUNCTION
void operator()(const size_t ii, size_t &update, const bool final) const {
idx val = array_sum(ii);
void operator()(const size_t ii, value_type &update, const bool final) const {
value_type val =
(ii == array_sum.extent(0) - 1) ? value_type(0) : array_sum(ii);
if (final) {
array_sum(ii) = idx(update);
array_sum(ii) = value_type(update);
}
update += val;
}
Expand Down Expand Up @@ -118,6 +119,25 @@ inline void kk_exclusive_parallel_prefix_sum(
ExclusiveParallelPrefixSum<view_t>(arr));
}

/***
* \brief Function performs the exclusive parallel prefix sum. That is each
* entry holds the sum until itself. This version also returns the final sum
* equivalent to the sum-reduction of arr before doing the scan.
* \param num_elements: size of the array
* \param arr: the array for which the prefix sum will be performed.
* \param finalSum: will be set to arr[num_elements - 1] after computing the
* prefix sum.
*/
template <typename view_t, typename MyExecSpace>
inline void kk_exclusive_parallel_prefix_sum(
typename view_t::value_type num_elements, view_t arr,
typename view_t::non_const_value_type &finalSum) {
typedef Kokkos::RangePolicy<MyExecSpace> my_exec_space;
Kokkos::parallel_scan("KokkosKernels::Common::PrefixSum",
my_exec_space(0, num_elements),
ExclusiveParallelPrefixSum<view_t>(arr), finalSum);
}

/***
* \brief Function performs the inclusive parallel prefix sum. That is each
* entry holds the sum until itself including itself. \param num_elements: size
Expand Down
16 changes: 4 additions & 12 deletions perf_test/sparse/KokkosSparse_spadd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,6 @@ void run_experiment(const Params& params) {
lno_view_t;
typedef typename crsMat_t::StaticCrsGraphType::entries_type::non_const_type
lno_nnz_view_t;
typedef typename crsMat_t::StaticCrsGraphType::row_map_type const_lno_view_t;
typedef
typename crsMat_t::StaticCrsGraphType::entries_type const_lno_nnz_view_t;

lno_view_t row_mapC;
// entriesC, valuesC and cusparseBuffer are allocated inside
Expand All @@ -200,10 +197,8 @@ void run_experiment(const Params& params) {
double numericTime = 0;

// Do an untimed warm up symbolic, and preallocate space for C entries/values
spadd_symbolic<KernelHandle, const_lno_view_t, const_lno_nnz_view_t,
const_lno_view_t, const_lno_nnz_view_t, lno_view_t,
lno_nnz_view_t>(&kh, A.graph.row_map, A.graph.entries,
B.graph.row_map, B.graph.entries, row_mapC);
spadd_symbolic(&kh, A.graph.row_map, A.graph.entries, B.graph.row_map,
B.graph.entries, row_mapC);

bool use_kk = !params.use_cusparse && !params.use_mkl;

Expand Down Expand Up @@ -261,11 +256,8 @@ void run_experiment(const Params& params) {
for (int sumRep = 0; sumRep < params.repeat; sumRep++) {
timer.reset();
if (use_kk) {
spadd_symbolic<KernelHandle, const_lno_view_t, const_lno_nnz_view_t,
const_lno_view_t, const_lno_nnz_view_t, lno_view_t,
lno_nnz_view_t>(&kh, A.graph.row_map, A.graph.entries,
B.graph.row_map, B.graph.entries,
row_mapC);
spadd_symbolic(&kh, A.graph.row_map, A.graph.entries, B.graph.row_map,
B.graph.entries, row_mapC);
c_nnz = addHandle->get_c_nnz();
} else if (params.use_cusparse) {
#ifdef KOKKOSKERNELS_ENABLE_TPL_CUSPARSE
Expand Down
14 changes: 14 additions & 0 deletions sparse/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,20 @@ KOKKOSKERNELS_GENERATE_ETI(Sparse_spiluk_numeric spiluk_numeric
TYPE_LISTS FLOATS ORDINALS OFFSETS LAYOUTS DEVICES
)

KOKKOSKERNELS_GENERATE_ETI(Sparse_par_ilut_symbolic par_ilut_symbolic
COMPONENTS sparse
HEADER_LIST ETI_HEADERS
SOURCE_LIST SOURCES
TYPE_LISTS FLOATS ORDINALS OFFSETS LAYOUTS DEVICES
)

KOKKOSKERNELS_GENERATE_ETI(Sparse_par_ilut_numeric par_ilut_numeric
COMPONENTS sparse
HEADER_LIST ETI_HEADERS
SOURCE_LIST SOURCES
TYPE_LISTS FLOATS ORDINALS OFFSETS LAYOUTS DEVICES
)

KOKKOSKERNELS_GENERATE_ETI(Sparse_sptrsv_symbolic sptrsv_symbolic
COMPONENTS sparse
HEADER_LIST ETI_HEADERS
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
//@HEADER
// ************************************************************************
//
// KokkosKernels 0.9: Linear Algebra and Graph Kernels
// Copyright 2017 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:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact Siva Rajamanickam (srajama@sandia.gov)
//
// ************************************************************************
//@HEADER
*/


#define KOKKOSKERNELS_IMPL_COMPILE_LIBRARY true
#include "KokkosKernels_config.h"

#include "KokkosSparse_par_ilut_numeric_spec.hpp"
namespace KokkosSparse {
namespace Impl {
@SPARSE_PAR_ILUT_NUMERIC_ETI_INST_BLOCK@
} //IMPL
} //Kokkos
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
//@HEADER
// ************************************************************************
//
// KokkosKernels 0.9: Linear Algebra and Graph Kernels
// Copyright 2017 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:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact Siva Rajamanickam (srajama@sandia.gov)
//
// ************************************************************************
//@HEADER
*/


#define KOKKOSKERNELS_IMPL_COMPILE_LIBRARY true
#include "KokkosKernels_config.h"

#include "KokkosSparse_par_ilut_symbolic_spec.hpp"
namespace KokkosSparse {
namespace Impl {
@SPARSE_PAR_ILUT_SYMBOLIC_ETI_INST_BLOCK@
} //IMPL
} //Kokkos
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#ifndef KOKKOSSPARSE_PAR_ILUT_NUMERIC_ETI_SPEC_AVAIL_HPP_
#define KOKKOSSPARSE_PAR_ILUT_NUMERIC_ETI_SPEC_AVAIL_HPP_
/*
//@HEADER
// ************************************************************************
//
// KokkosKernels 0.9: Linear Algebra and Graph Kernels
// Copyright 2017 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:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact Siva Rajamanickam (srajama@sandia.gov)
//
// ************************************************************************
//@HEADER
*/

namespace KokkosSparse {
namespace Impl {

@SPARSE_PAR_ILUT_NUMERIC_ETI_AVAIL_BLOCK@

} // Impl
} // KokkosSparse
#endif // KOKKOSSPARSE_PAR_ILUT_NUMERIC_ETI_SPEC_AVAIL_HPP_
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#ifndef KOKKOSSPARSE_PAR_ILUT_NUMERIC_ETI_SPEC_DECL_HPP_
#define KOKKOSSPARSE_PAR_ILUT_NUMERIC_ETI_SPEC_DECL_HPP_
/*
//@HEADER
// ************************************************************************
//
// KokkosKernels 0.9: Linear Algebra and Graph Kernels
// Copyright 2017 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:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact Siva Rajamanickam (srajama@sandia.gov)
//
// ************************************************************************
//@HEADER
*/

namespace KokkosSparse {
namespace Impl {

@SPARSE_PAR_ILUT_NUMERIC_DECL_BLOCK@

} // Impl
} // KokkosSparse
#endif // KOKKOSSPARSE_PAR_ILUT_NUMERIC_ETI_SPEC_DECL_HPP_
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#ifndef KOKKOSSPARSE_PAR_ILUT_SYMBOLIC_ETI_SPEC_AVAIL_HPP_
#define KOKKOSSPARSE_PAR_ILUT_SYMBOLIC_ETI_SPEC_AVAIL_HPP_
/*
//@HEADER
// ************************************************************************
//
// KokkosKernels 0.9: Linear Algebra and Graph Kernels
// Copyright 2017 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:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact Siva Rajamanickam (srajama@sandia.gov)
//
// ************************************************************************
//@HEADER
*/

namespace KokkosSparse {
namespace Impl {

@SPARSE_PAR_ILUT_SYMBOLIC_ETI_AVAIL_BLOCK@

} // Impl
} // KokkosSparse
#endif // KOKKOSSPARSE_PAR_ILUT_SYMBOLIC_ETI_SPEC_AVAIL_HPP_
Loading

0 comments on commit a2fb862

Please sign in to comment.