Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reordering algorithms to sparse_blas benchmark #1354

Merged
merged 2 commits into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 121 additions & 5 deletions benchmark/sparse_blas/operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -695,11 +695,111 @@ class SymbolicCholeskyOperation : public BenchmarkOperation {
};


class ReorderRcmOperation : public BenchmarkOperation {
using reorder_type = gko::reorder::Rcm<etype, itype>;

public:
explicit ReorderRcmOperation(const Mtx* mtx)
: mtx_{mtx->clone()},
factory_{reorder_type::build().on(mtx->get_executor())}
{}

std::pair<bool, double> 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> mtx_;
std::unique_ptr<reorder_type::Factory> factory_;
std::unique_ptr<reorder_type> reorder_;
};


#if GKO_HAVE_METIS


class ReorderNestedDissectionOperation : public BenchmarkOperation {
using factory_type =
gko::experimental::reorder::NestedDissection<etype, itype>;
using reorder_type = gko::matrix::Permutation<itype>;

public:
explicit ReorderNestedDissectionOperation(const Mtx* mtx)
: mtx_{mtx->clone()},
factory_{factory_type::build().on(mtx->get_executor())}
{}

std::pair<bool, double> 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> mtx_;
std::unique_ptr<factory_type> factory_;
std::unique_ptr<reorder_type> reorder_;
};


#endif


class ReorderApproxMinDegOperation : public BenchmarkOperation {
using factory_type = gko::experimental::reorder::Amd<itype>;
using reorder_type = gko::matrix::Permutation<itype>;

public:
explicit ReorderApproxMinDegOperation(const Mtx* mtx)
: mtx_{mtx->clone()},
factory_{factory_type::build().on(mtx->get_executor())}
{}

std::pair<bool, double> 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> mtx_;
std::unique_ptr<factory_type> factory_;
std::unique_ptr<reorder_type> reorder_;
};


const std::map<std::string,
std::function<std::unique_ptr<BenchmarkOperation>(const Mtx*)>>
operation_map{
{"spgemm",
[](const Mtx* mtx) { return std::make_unique<SpgemmOperation>(mtx); }},
operation_map
{
{"spgemm",
[](const Mtx* mtx) { return std::make_unique<SpgemmOperation>(mtx); }},
{"spgeam",
[](const Mtx* mtx) { return std::make_unique<SpgeamOperation>(mtx); }},
{"transpose",
Expand All @@ -726,9 +826,25 @@ const std::map<std::string,
[](const Mtx* mtx) {
return std::make_unique<SymbolicCholeskyOperation>(mtx, false);
}},
{"symbolic_cholesky_symmetric", [](const Mtx* mtx) {
{"symbolic_cholesky_symmetric",
[](const Mtx* mtx) {
return std::make_unique<SymbolicCholeskyOperation>(mtx, true);
}}};
}},
{"reorder_rcm",
[](const Mtx* mtx) {
return std::make_unique<ReorderRcmOperation>(mtx);
}},
{"reorder_amd", [](const Mtx* mtx) {
return std::make_unique<ReorderApproxMinDegOperation>(mtx);
}},
#if GKO_HAVE_METIS
{
"reorder_nd", [](const Mtx* mtx) {
return std::make_unique<ReorderNestedDissectionOperation>(mtx);
}
}
#endif
};


std::unique_ptr<BenchmarkOperation> get_operation(std::string name,
Expand Down
12 changes: 9 additions & 3 deletions benchmark/sparse_blas/sparse_blas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,17 @@ const auto benchmark_name = "sparse_blas";

using mat_data = gko::matrix_data<etype, itype>;

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 "
Expand Down