Skip to content

Commit

Permalink
Merge consistent matrix index type in benchmark
Browse files Browse the repository at this point in the history
This sets the index type in all benchmark operators explicitly to enable later extension to 64 bit indices.

Related PR: #828
  • Loading branch information
upsj committed Jul 13, 2021
2 parents 1cf7da6 + 0f301d1 commit 417df77
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 140 deletions.
6 changes: 3 additions & 3 deletions benchmark/conversions/conversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void convert_matrix(const gko::LinOp *matrix_from, const char *format_to,
add_or_set_member(conversion_case, conversion_name,
rapidjson::Value(rapidjson::kObjectType), allocator);

gko::matrix_data<etype> data{gko::dim<2>{1, 1}, 1};
gko::matrix_data<etype, itype> data{gko::dim<2>{1, 1}, 1};
auto matrix_to =
share(formats::matrix_factory.at(format_to)(exec, data));

Expand Down Expand Up @@ -148,9 +148,9 @@ int main(int argc, char *argv[])

std::clog << "Running test case: " << test_case << std::endl;
std::ifstream mtx_fd(test_case["filename"].GetString());
gko::matrix_data<etype> data;
gko::matrix_data<etype, itype> data;
try {
data = gko::read_raw<etype>(mtx_fd);
data = gko::read_raw<etype, itype>(mtx_fd);
} catch (std::exception &e) {
std::cerr << "Error setting up matrix data, what(): " << e.what()
<< std::endl;
Expand Down
12 changes: 6 additions & 6 deletions benchmark/matrix_generator/matrix_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,24 +96,24 @@ void validate_option_object(const rapidjson::Value &value)
}


using generator_function =
std::function<gko::matrix_data<etype>(rapidjson::Value &, std::ranlux24 &)>;
using generator_function = std::function<gko::matrix_data<etype, itype>(
rapidjson::Value &, std::ranlux24 &)>;


// matrix generators
gko::matrix_data<etype> generate_block_diagonal(rapidjson::Value &config,
std::ranlux24 &engine)
gko::matrix_data<etype, itype> generate_block_diagonal(rapidjson::Value &config,
std::ranlux24 &engine)
{
if (!config.HasMember("num_blocks") || !config["num_blocks"].IsUint() ||
!config.HasMember("block_size") || !config["block_size"].IsUint()) {
print_config_error_and_exit(2);
}
auto num_blocks = config["num_blocks"].GetUint();
auto block_size = config["block_size"].GetUint();
auto block = gko::matrix_data<etype>(
auto block = gko::matrix_data<etype, itype>(
gko::dim<2>(block_size),
std::uniform_real_distribution<rc_etype>(-1.0, 1.0), engine);
return gko::matrix_data<etype>::diag(num_blocks, block);
return gko::matrix_data<etype, itype>::diag(num_blocks, block);
}


Expand Down
2 changes: 1 addition & 1 deletion benchmark/preconditioner/preconditioner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ int main(int argc, char *argv[])
std::clog << "Running test case: " << test_case << std::endl;

std::ifstream mtx_fd(test_case["filename"].GetString());
auto data = gko::read_raw<etype>(mtx_fd);
auto data = gko::read_raw<etype, itype>(mtx_fd);

auto system_matrix =
share(formats::matrix_factory.at(FLAGS_formats)(exec, data));
Expand Down
2 changes: 1 addition & 1 deletion benchmark/solver/solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ int main(int argc, char *argv[])
{std::numeric_limits<rc_etype>::quiet_NaN()}, exec);
x = gko::initialize<Vec>({0.0}, exec);
} else {
auto data = gko::read_raw<etype>(mtx_fd);
auto data = gko::read_raw<etype, itype>(mtx_fd);
system_matrix = share(formats::matrix_factory.at(
test_case["optimal"]["spmv"].GetString())(exec, data));
if (test_case.HasMember("rhs")) {
Expand Down
4 changes: 2 additions & 2 deletions benchmark/spmv/spmv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ DEFINE_uint32(nrhs, 1, "The number of right hand sides");
// This function supposes that management of `FLAGS_overwrite` is done before
// calling it
void apply_spmv(const char *format_name, std::shared_ptr<gko::Executor> exec,
const gko::matrix_data<etype> &data, const vec<etype> *b,
const gko::matrix_data<etype, itype> &data, const vec<etype> *b,
const vec<etype> *x, const vec<etype> *answer,
rapidjson::Value &test_case,
rapidjson::MemoryPoolAllocator<> &allocator)
Expand Down Expand Up @@ -212,7 +212,7 @@ int main(int argc, char *argv[])
}
std::clog << "Running test case: " << test_case << std::endl;
std::ifstream mtx_fd(test_case["filename"].GetString());
auto data = gko::read_raw<etype>(mtx_fd);
auto data = gko::read_raw<etype, itype>(mtx_fd);

auto nrhs = FLAGS_nrhs;
auto b = create_matrix<etype>(exec, gko::dim<2>{data.size[1], nrhs},
Expand Down
21 changes: 10 additions & 11 deletions benchmark/utils/cuda_linops.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -685,11 +685,11 @@ class CuspGenericCoo


// Some shortcuts
using cusp_csrex = detail::CuspCsrEx<etype>;
using cusp_csrex = detail::CuspCsrEx<etype, itype>;
#if defined(CUDA_VERSION) && (CUDA_VERSION < 11000)
using cusp_csr = detail::CuspCsr<etype>;
using cusp_csrmp = detail::CuspCsrmp<etype>;
using cusp_csrmm = detail::CuspCsrmm<etype>;
using cusp_csr = detail::CuspCsr<etype, itype>;
using cusp_csrmp = detail::CuspCsrmp<etype, itype>;
using cusp_csrmm = detail::CuspCsrmm<etype, itype>;
#endif // defined(CUDA_VERSION) && (CUDA_VERSION < 11000)


Expand All @@ -698,10 +698,9 @@ using cusp_csrmm = detail::CuspCsrmm<etype>;
((CUDA_VERSION >= 10020) && !(defined(_WIN32) || defined(__CYGWIN__))))


using cusp_gcsr = detail::CuspGenericCsr<etype>;
using cusp_gcsr2 =
detail::CuspGenericCsr<etype, gko::int32, CUSPARSE_CSRMV_ALG2>;
using cusp_gcoo = detail::CuspGenericCoo<etype>;
using cusp_gcsr = detail::CuspGenericCsr<etype, itype>;
using cusp_gcsr2 = detail::CuspGenericCsr<etype, itype, CUSPARSE_CSRMV_ALG2>;
using cusp_gcoo = detail::CuspGenericCoo<etype, itype>;


#endif // defined(CUDA_VERSION) && (CUDA_VERSION >= 11000 || ((CUDA_VERSION >=
Expand All @@ -710,10 +709,10 @@ using cusp_gcoo = detail::CuspGenericCoo<etype>;

#if defined(CUDA_VERSION) && (CUDA_VERSION < 11000)
using cusp_coo =
detail::CuspHybrid<etype, gko::int32, CUSPARSE_HYB_PARTITION_USER, 0>;
detail::CuspHybrid<etype, itype, CUSPARSE_HYB_PARTITION_USER, 0>;
using cusp_ell =
detail::CuspHybrid<etype, gko::int32, CUSPARSE_HYB_PARTITION_MAX, 0>;
using cusp_hybrid = detail::CuspHybrid<etype>;
detail::CuspHybrid<etype, itype, CUSPARSE_HYB_PARTITION_MAX, 0>;
using cusp_hybrid = detail::CuspHybrid<etype, itype>;
#endif // defined(CUDA_VERSION) && (CUDA_VERSION < 11000)


Expand Down
41 changes: 21 additions & 20 deletions benchmark/utils/formats.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ namespace formats {


// some shortcuts
using hybrid = gko::matrix::Hybrid<etype>;
using csr = gko::matrix::Csr<etype>;
using hybrid = gko::matrix::Hybrid<etype, itype>;
using csr = gko::matrix::Csr<etype, itype>;

/**
* Creates a Ginkgo matrix from the intermediate data representation format
Expand All @@ -179,7 +179,7 @@ using csr = gko::matrix::Csr<etype>;
template <typename MatrixType>
std::unique_ptr<MatrixType> read_matrix_from_data(
std::shared_ptr<const gko::Executor> exec,
const gko::matrix_data<etype> &data)
const gko::matrix_data<etype, itype> &data)
{
auto mat = MatrixType::create(std::move(exec));
mat->read(data);
Expand Down Expand Up @@ -213,7 +213,7 @@ std::shared_ptr<csr::strategy_type> create_gpu_strategy(
*
* @throws gko::Error if the imbalance limit is exceeded
*/
void check_ell_admissibility(const gko::matrix_data<etype> &data)
void check_ell_admissibility(const gko::matrix_data<etype, itype> &data)
{
if (data.size[0] == 0 || FLAGS_ell_imbalance_limit < 0) {
return;
Expand All @@ -237,51 +237,52 @@ void check_ell_admissibility(const gko::matrix_data<etype> &data)
*
* @param MATRIX_TYPE the Ginkgo matrix type (such as `gko::matrix::Csr<>`)
*/
#define READ_MATRIX(MATRIX_TYPE, ...) \
[](std::shared_ptr<const gko::Executor> exec, \
const gko::matrix_data<etype> &data) -> std::unique_ptr<MATRIX_TYPE> { \
auto mat = MATRIX_TYPE::create(std::move(exec), __VA_ARGS__); \
mat->read(data); \
return mat; \
#define READ_MATRIX(MATRIX_TYPE, ...) \
[](std::shared_ptr<const gko::Executor> exec, \
const gko::matrix_data<etype, itype> &data) \
-> std::unique_ptr<MATRIX_TYPE> { \
auto mat = MATRIX_TYPE::create(std::move(exec), __VA_ARGS__); \
mat->read(data); \
return mat; \
}


// clang-format off
const std::map<std::string, std::function<std::unique_ptr<gko::LinOp>(
std::shared_ptr<const gko::Executor>,
const gko::matrix_data<etype> &)>>
const gko::matrix_data<etype, itype> &)>>
matrix_factory{
{"csr",
[](std::shared_ptr<const gko::Executor> exec,
const gko::matrix_data<etype> &data) -> std::unique_ptr<csr> {
const gko::matrix_data<etype, itype> &data) -> std::unique_ptr<csr> {
auto mat =
csr::create(exec, create_gpu_strategy<csr::automatical>(exec));
mat->read(data);
return mat;
}},
{"csri",
[](std::shared_ptr<const gko::Executor> exec,
const gko::matrix_data<etype> &data) -> std::unique_ptr<csr> {
const gko::matrix_data<etype, itype> &data) -> std::unique_ptr<csr> {
auto mat = csr::create(
exec, create_gpu_strategy<csr::load_balance>(exec));
mat->read(data);
return mat;
}},
{"csrm", READ_MATRIX(csr, std::make_shared<csr::merge_path>())},
{"csrc", READ_MATRIX(csr, std::make_shared<csr::classical>())},
{"coo", read_matrix_from_data<gko::matrix::Coo<etype>>},
{"coo", read_matrix_from_data<gko::matrix::Coo<etype, itype>>},
{"ell", [](std::shared_ptr<const gko::Executor> exec,
const gko::matrix_data<etype> &data) {
const gko::matrix_data<etype, itype> &data) {
check_ell_admissibility(data);
auto mat = gko::matrix::Ell<etype>::create(exec);
auto mat = gko::matrix::Ell<etype, itype>::create(exec);
mat->read(data);
return mat;
}},
{"ell-mixed",
[](std::shared_ptr<const gko::Executor> exec,
const gko::matrix_data<etype> &data) {
const gko::matrix_data<etype, itype> &data) {
check_ell_admissibility(data);
gko::matrix_data<gko::next_precision<etype>> conv_data;
gko::matrix_data<gko::next_precision<etype>, itype> conv_data;
conv_data.size = data.size;
conv_data.nonzeros.resize(data.nonzeros.size());
auto it = conv_data.nonzeros.begin();
Expand All @@ -291,7 +292,7 @@ const std::map<std::string, std::function<std::unique_ptr<gko::LinOp>(
it->value = el.value;
++it;
}
auto mat = gko::matrix::Ell<gko::next_precision<etype>>::create(
auto mat = gko::matrix::Ell<gko::next_precision<etype>, itype>::create(
std::move(exec));
mat->read(conv_data);
return mat;
Expand Down Expand Up @@ -352,7 +353,7 @@ const std::map<std::string, std::function<std::unique_ptr<gko::LinOp>(
{"hybridminstorage",
READ_MATRIX(hybrid,
std::make_shared<hybrid::minimal_storage_limit>())},
{"sellp", read_matrix_from_data<gko::matrix::Sellp<etype>>}
{"sellp", read_matrix_from_data<gko::matrix::Sellp<etype, itype>>}
};
// clang-format on

Expand Down
7 changes: 4 additions & 3 deletions benchmark/utils/general.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


#include "benchmark/utils/timer.hpp"
#include "benchmark/utils/types.hpp"


// Global command-line arguments
Expand Down Expand Up @@ -366,7 +367,7 @@ std::unique_ptr<vec<ValueType>> create_matrix(
ValueType value)
{
auto res = vec<ValueType>::create(exec);
res->read(gko::matrix_data<ValueType>(size, value));
res->read(gko::matrix_data<ValueType, itype>(size, value));
return res;
}

Expand All @@ -378,7 +379,7 @@ std::unique_ptr<vec<ValueType>> create_matrix(
RandomEngine &engine)
{
auto res = vec<ValueType>::create(exec);
res->read(gko::matrix_data<ValueType>(
res->read(gko::matrix_data<ValueType, itype>(
size,
std::uniform_real_distribution<gko::remove_complex<ValueType>>(-1.0,
1.0),
Expand All @@ -393,7 +394,7 @@ std::unique_ptr<vec<ValueType>> create_vector(
std::shared_ptr<const gko::Executor> exec, gko::size_type size)
{
auto res = vec<ValueType>::create(exec);
res->read(gko::matrix_data<ValueType>(gko::dim<2>{size, 1}));
res->read(gko::matrix_data<ValueType, itype>(gko::dim<2>{size, 1}));
return res;
}

Expand Down
10 changes: 5 additions & 5 deletions benchmark/utils/hip_linops.hip.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,14 @@ class HipspHybrid


// Some shortcuts
using hipsp_csr = detail::HipspCsr<etype>;
using hipsp_csrmm = detail::HipspCsrmm<etype>;
using hipsp_csr = detail::HipspCsr<etype, itype>;
using hipsp_csrmm = detail::HipspCsrmm<etype, itype>;


using hipsp_coo =
detail::HipspHybrid<etype, gko::int32, HIPSPARSE_HYB_PARTITION_USER, 0>;
detail::HipspHybrid<etype, itype, HIPSPARSE_HYB_PARTITION_USER, 0>;
using hipsp_ell =
detail::HipspHybrid<etype, gko::int32, HIPSPARSE_HYB_PARTITION_MAX, 0>;
using hipsp_hybrid = detail::HipspHybrid<etype>;
detail::HipspHybrid<etype, itype, HIPSPARSE_HYB_PARTITION_MAX, 0>;
using hipsp_hybrid = detail::HipspHybrid<etype, itype>;

#endif // GKO_BENCHMARK_UTILS_HIP_LINOPS_HIP_HPP_
Loading

0 comments on commit 417df77

Please sign in to comment.