From 97a58078dba71c41fb24892e77c32d7caabef42e Mon Sep 17 00:00:00 2001 From: Tobias Ribizel Date: Fri, 23 Jun 2023 09:53:00 +0200 Subject: [PATCH 1/2] add reorderings to sparse_blas benchmark --- benchmark/sparse_blas/operations.cpp | 126 +++++++++++++++++++++++++- benchmark/sparse_blas/sparse_blas.cpp | 12 ++- 2 files changed, 130 insertions(+), 8 deletions(-) diff --git a/benchmark/sparse_blas/operations.cpp b/benchmark/sparse_blas/operations.cpp index 6a817a67c0d..dc96143ed6d 100644 --- a/benchmark/sparse_blas/operations.cpp +++ b/benchmark/sparse_blas/operations.cpp @@ -695,11 +695,111 @@ class SymbolicCholeskyOperation : public BenchmarkOperation { }; +class ReorderRcmOperation : public BenchmarkOperation { + using reorder_type = gko::reorder::Rcm; + +public: + explicit ReorderRcmOperation(const Mtx* mtx) + : mtx_{mtx->clone()}, + factory_{reorder_type::build().on(mtx->get_executor())} + {} + + std::pair validate() const override + { + // validating RCM correctness is hard, let's leave it out for now + return {true, 0.0}; + } + + gko::size_type get_flops() const override { return 0; } + + gko::size_type get_memory() const override { return 0; } + + void prepare() override {} + + void run() override { reorder_ = factory_->generate(mtx_); } + +private: + std::shared_ptr mtx_; + std::unique_ptr factory_; + std::unique_ptr reorder_; +}; + + +#if GKO_HAVE_METIS + + +class ReorderNestedDissectionOperation : public BenchmarkOperation { + using factory_type = + gko::experimental::reorder::NestedDissection; + using reorder_type = gko::matrix::Permutation; + +public: + explicit ReorderNestedDissectionOperation(const Mtx* mtx) + : mtx_{mtx->clone()}, + factory_{factory_type::build().on(mtx->get_executor())} + {} + + std::pair validate() const override + { + // validating ND correctness is hard, let's leave it out for now + return {true, 0.0}; + } + + gko::size_type get_flops() const override { return 0; } + + gko::size_type get_memory() const override { return 0; } + + void prepare() override {} + + void run() override { reorder_ = factory_->generate(mtx_); } + +private: + std::shared_ptr mtx_; + std::unique_ptr factory_; + std::unique_ptr reorder_; +}; + + +#endif + + +class ReorderApproxMinDegOperation : public BenchmarkOperation { + using factory_type = gko::experimental::reorder::Amd; + using reorder_type = gko::matrix::Permutation; + +public: + explicit ReorderApproxMinDegOperation(const Mtx* mtx) + : mtx_{mtx->clone()}, + factory_{factory_type::build().on(mtx->get_executor())} + {} + + std::pair validate() const override + { + // validating AMD correctness is hard, let's leave it out for now + return {true, 0.0}; + } + + gko::size_type get_flops() const override { return 0; } + + gko::size_type get_memory() const override { return 0; } + + void prepare() override {} + + void run() override { reorder_ = factory_->generate(mtx_); } + +private: + std::shared_ptr mtx_; + std::unique_ptr factory_; + std::unique_ptr reorder_; +}; + + const std::map(const Mtx*)>> - operation_map{ - {"spgemm", - [](const Mtx* mtx) { return std::make_unique(mtx); }}, + operation_map +{ + {"spgemm", + [](const Mtx* mtx) { return std::make_unique(mtx); }}, {"spgeam", [](const Mtx* mtx) { return std::make_unique(mtx); }}, {"transpose", @@ -726,9 +826,25 @@ const std::map(mtx, false); }}, - {"symbolic_cholesky_symmetric", [](const Mtx* mtx) { + {"symbolic_cholesky_symmetric", + [](const Mtx* mtx) { return std::make_unique(mtx, true); - }}}; + }}, + {"reorder_rcm", + [](const Mtx* mtx) { + return std::make_unique(mtx); + }}, + {"reorder_amd", [](const Mtx* mtx) { + return std::make_unique(mtx); + }}, +#if GKO_HAVE_METIS + { + "reorder_nd", [](const Mtx* mtx) { + return std::make_unique(mtx); + } + } +#endif +}; std::unique_ptr get_operation(std::string name, diff --git a/benchmark/sparse_blas/sparse_blas.cpp b/benchmark/sparse_blas/sparse_blas.cpp index 4fb06d2a4a0..3b0ce26db5f 100644 --- a/benchmark/sparse_blas/sparse_blas.cpp +++ b/benchmark/sparse_blas/sparse_blas.cpp @@ -57,11 +57,17 @@ const auto benchmark_name = "sparse_blas"; using mat_data = gko::matrix_data; -DEFINE_string( - operations, "spgemm,spgeam,transpose", +const char* operations_string = "Comma-separated list of operations to be benchmarked. Can be " "spgemm, spgeam, transpose, sort, is_sorted, generate_lookup, " - "lookup, symbolic_lu, symbolic_cholesky, symbolic_cholesky_symmetric"); + "lookup, symbolic_lu, symbolic_cholesky, " + "symbolic_cholesky_symmetric, reorder_rcm, " +#if GKO_HAVE_METIS + "reorder_nd, " +#endif + "reorder_amd"; + +DEFINE_string(operations, "spgemm,spgeam,transpose", operations_string); DEFINE_bool(validate, false, "Check for correct sparsity pattern and compute the L2 norm " From 304a452db2e4d2b27a37d776f2b0bd152073c5e0 Mon Sep 17 00:00:00 2001 From: Tobias Ribizel Date: Fri, 23 Jun 2023 10:58:05 +0200 Subject: [PATCH 2/2] improve formatting Co-authored-by: Yuhsiang M. Tsai --- benchmark/sparse_blas/operations.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/benchmark/sparse_blas/operations.cpp b/benchmark/sparse_blas/operations.cpp index dc96143ed6d..66e5707c559 100644 --- a/benchmark/sparse_blas/operations.cpp +++ b/benchmark/sparse_blas/operations.cpp @@ -796,10 +796,9 @@ class ReorderApproxMinDegOperation : public BenchmarkOperation { const std::map(const Mtx*)>> - operation_map -{ - {"spgemm", - [](const Mtx* mtx) { return std::make_unique(mtx); }}, + operation_map{ + {"spgemm", + [](const Mtx* mtx) { return std::make_unique(mtx); }}, {"spgeam", [](const Mtx* mtx) { return std::make_unique(mtx); }}, {"transpose", @@ -834,17 +833,18 @@ const std::map(mtx); }}, - {"reorder_amd", [](const Mtx* mtx) { + {"reorder_amd", + [](const Mtx* mtx) { return std::make_unique(mtx); }}, + {"reorder_nd", + [](const Mtx* mtx) -> std::unique_ptr { #if GKO_HAVE_METIS - { - "reorder_nd", [](const Mtx* mtx) { - return std::make_unique(mtx); - } - } + return std::make_unique(mtx); +#else + GKO_NOT_COMPILED(METIS); #endif -}; + }}}; std::unique_ptr get_operation(std::string name,