Skip to content

Commit

Permalink
output fill-in in symbolic factorization benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
upsj committed Mar 21, 2023
1 parent 5c4f6fe commit b492d04
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 54 deletions.
15 changes: 15 additions & 0 deletions benchmark/sparse_blas/operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


#include "benchmark/sparse_blas/operations.hpp"
#include "benchmark/utils/json.hpp"
#include "core/factorization/elimination_forest.hpp"
#include "core/factorization/symbolic.hpp"
#include "core/matrix/csr_kernels.hpp"
Expand Down Expand Up @@ -631,6 +632,13 @@ class SymbolicLuOperation : public BenchmarkOperation {

void run() override { gko::factorization::symbolic_lu(mtx_, result_); }

void write_stats(rapidjson::Value& object,
rapidjson::MemoryPoolAllocator<>& allocator) override
{
add_or_set_member(object, "factor_nonzeros",
result_->get_num_stored_elements(), allocator);
}

private:
const Mtx* mtx_;
std::unique_ptr<Mtx> result_;
Expand All @@ -656,6 +664,13 @@ class SymbolicCholeskyOperation : public BenchmarkOperation {
gko::factorization::symbolic_cholesky(mtx_, result_, forest_);
}

void write_stats(rapidjson::Value& object,
rapidjson::MemoryPoolAllocator<>& allocator) override
{
add_or_set_member(object, "factor_nonzeros",
result_->get_num_stored_elements(), allocator);
}

private:
const Mtx* mtx_;
std::unique_ptr<Mtx> result_;
Expand Down
13 changes: 12 additions & 1 deletion benchmark/sparse_blas/operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <tuple>


#include <rapidjson/document.h>


#include "benchmark/utils/types.hpp"


Expand All @@ -58,7 +61,7 @@ class BenchmarkOperation {
* Sets up all necessary data for a following call to
* BenchmarkOperation::run.
*/
virtual void prepare(){};
virtual void prepare() {}

/**
* Computes the error between a reference solution and the solution provided
Expand All @@ -71,6 +74,14 @@ class BenchmarkOperation {
* Executes the operation to be benchmarked.
*/
virtual void run() = 0;


/**
* Allows the operation to write arbitrary information to the JSON output.
*/
virtual void write_stats(rapidjson::Value& object,
rapidjson::MemoryPoolAllocator<>& allocator)
{}
};


Expand Down
1 change: 1 addition & 0 deletions benchmark/sparse_blas/sparse_blas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ void apply_sparse_blas(const char* operation_name,
op->run();
exec->remove_logger(gen_logger);
}
op->write_stats(test_case[operation_name], allocator);

add_or_set_member(test_case[operation_name], "completed", true,
allocator);
Expand Down
54 changes: 1 addition & 53 deletions benchmark/utils/general.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <rapidjson/prettywriter.h>


#include "benchmark/utils/json.hpp"
#include "benchmark/utils/timer.hpp"
#include "benchmark/utils/types.hpp"
#include "core/distributed/helpers.hpp"
Expand Down Expand Up @@ -188,59 +189,6 @@ std::default_random_engine& get_engine()
}


// helper for writing out rapidjson Values
std::ostream& operator<<(std::ostream& os, const rapidjson::Value& value)
{
rapidjson::OStreamWrapper jos(os);
rapidjson::PrettyWriter<rapidjson::OStreamWrapper, rapidjson::UTF8<>,
rapidjson::UTF8<>, rapidjson::CrtAllocator,
rapidjson::kWriteNanAndInfFlag>
writer(jos);
value.Accept(writer);
return os;
}


// helper for setting rapidjson object members
template <typename T, typename NameType, typename Allocator>
std::enable_if_t<
!std::is_same<typename std::decay<T>::type, gko::size_type>::value, void>
add_or_set_member(rapidjson::Value& object, NameType&& name, T&& value,
Allocator&& allocator)
{
if (object.HasMember(name)) {
object[name] = std::forward<T>(value);
} else {
auto n = rapidjson::Value(name, allocator);
object.AddMember(n, std::forward<T>(value), allocator);
}
}


/**
@internal This is required to fix some MacOS problems (and possibly other
compilers). There is no explicit RapidJSON constructor for `std::size_t` so a
conversion to a known constructor is required to solve any ambiguity. See the
last comments of https://github.com/ginkgo-project/ginkgo/issues/270.
*/
template <typename T, typename NameType, typename Allocator>
std::enable_if_t<
std::is_same<typename std::decay<T>::type, gko::size_type>::value, void>
add_or_set_member(rapidjson::Value& object, NameType&& name, T&& value,
Allocator&& allocator)
{
if (object.HasMember(name)) {
object[name] =
std::forward<std::uint64_t>(static_cast<std::uint64_t>(value));
} else {
auto n = rapidjson::Value(name, allocator);
object.AddMember(
n, std::forward<std::uint64_t>(static_cast<std::uint64_t>(value)),
allocator);
}
}


// helper for splitting a delimiter-separated list into vector of strings
std::vector<std::string> split(const std::string& s, char delimiter = ',')
{
Expand Down
102 changes: 102 additions & 0 deletions benchmark/utils/json.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*******************************<GINKGO LICENSE>******************************
Copyright (c) 2017-2023, the Ginkgo authors
All rights reserved.
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 copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT
HOLDER OR 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.
******************************<GINKGO LICENSE>*******************************/

#ifndef GKO_BENCHMARK_UTILS_JSON_HPP_
#define GKO_BENCHMARK_UTILS_JSON_HPP_


#include <ginkgo/ginkgo.hpp>


#include <type_traits>


#include <rapidjson/document.h>
#include <rapidjson/istreamwrapper.h>
#include <rapidjson/ostreamwrapper.h>
#include <rapidjson/prettywriter.h>


// helper for setting rapidjson object members
template <typename T, typename NameType, typename Allocator>
std::enable_if_t<
!std::is_same<typename std::decay<T>::type, gko::size_type>::value, void>
add_or_set_member(rapidjson::Value& object, NameType&& name, T&& value,
Allocator&& allocator)
{
if (object.HasMember(name)) {
object[name] = std::forward<T>(value);
} else {
auto n = rapidjson::Value(name, allocator);
object.AddMember(n, std::forward<T>(value), allocator);
}
}


/**
@internal This is required to fix some MacOS problems (and possibly other
compilers). There is no explicit RapidJSON constructor for `std::size_t` so a
conversion to a known constructor is required to solve any ambiguity. See the
last comments of https://github.com/ginkgo-project/ginkgo/issues/270.
*/
template <typename T, typename NameType, typename Allocator>
std::enable_if_t<
std::is_same<typename std::decay<T>::type, gko::size_type>::value, void>
add_or_set_member(rapidjson::Value& object, NameType&& name, T&& value,
Allocator&& allocator)
{
if (object.HasMember(name)) {
object[name] =
std::forward<std::uint64_t>(static_cast<std::uint64_t>(value));
} else {
auto n = rapidjson::Value(name, allocator);
object.AddMember(
n, std::forward<std::uint64_t>(static_cast<std::uint64_t>(value)),
allocator);
}
}


// helper for writing out rapidjson Values
inline std::ostream& operator<<(std::ostream& os, const rapidjson::Value& value)
{
rapidjson::OStreamWrapper jos(os);
rapidjson::PrettyWriter<rapidjson::OStreamWrapper, rapidjson::UTF8<>,
rapidjson::UTF8<>, rapidjson::CrtAllocator,
rapidjson::kWriteNanAndInfFlag>
writer(jos);
value.Accept(writer);
return os;
}


#endif // GKO_BENCHMARK_UTILS_JSON_HPP_

0 comments on commit b492d04

Please sign in to comment.