Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion common/cuda_hip/matrix/csr_kernels.template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <ginkgo/core/matrix/coo.hpp>
#include <ginkgo/core/matrix/dense.hpp>
#include <ginkgo/core/matrix/ell.hpp>
#include <ginkgo/core/matrix/hybrid.hpp>
#include <ginkgo/core/matrix/sellp.hpp>

#include "accessor/cuda_hip_helper.hpp"
Expand Down
22 changes: 10 additions & 12 deletions common/cuda_hip/matrix/dense_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
#include <ginkgo/core/matrix/coo.hpp>
#include <ginkgo/core/matrix/csr.hpp>
#include <ginkgo/core/matrix/diagonal.hpp>
#include <ginkgo/core/matrix/ell.hpp>
#include <ginkgo/core/matrix/fbcsr.hpp>
#include <ginkgo/core/matrix/hybrid.hpp>
#include <ginkgo/core/matrix/sellp.hpp>
#include <ginkgo/core/matrix/sparsity_csr.hpp>

Expand Down Expand Up @@ -571,19 +569,19 @@ template <typename ValueType, typename IndexType>
void convert_to_hybrid(std::shared_ptr<const DefaultExecutor> exec,
matrix::view::dense<const ValueType> source,
const int64* coo_row_ptrs,
matrix::Hybrid<ValueType, IndexType>* result)
matrix::view::hybrid<ValueType, IndexType> result)
{
const auto num_rows = result->get_size()[0];
const auto num_cols = result->get_size()[1];
const auto num_rows = result.size[0];
const auto num_cols = result.size[1];
const auto ell_max_nnz_per_row =
result->get_ell_num_stored_elements_per_row();
result.ell_part.num_stored_elements_per_row;
const auto source_stride = source.stride;
const auto ell_stride = result->get_ell_stride();
auto ell_col_idxs = result->get_ell_col_idxs();
auto ell_values = result->get_ell_values();
auto coo_row_idxs = result->get_coo_row_idxs();
auto coo_col_idxs = result->get_coo_col_idxs();
auto coo_values = result->get_coo_values();
const auto ell_stride = result.ell_part.stride;
auto ell_col_idxs = result.ell_part.col_idxs;
auto ell_values = result.ell_part.values;
auto coo_row_idxs = result.coo_part.row_idxs;
auto coo_col_idxs = result.coo_part.col_idxs;
auto coo_values = result.coo_part.values;

auto grid_dim = ceildiv(num_rows, default_block_size / config::warp_size);
if (grid_dim > 0) {
Expand Down
10 changes: 5 additions & 5 deletions common/unified/matrix/csr_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ template <typename ValueType, typename IndexType>
void convert_to_hybrid(std::shared_ptr<const DefaultExecutor> exec,
const matrix::Csr<ValueType, IndexType>* source,
const int64* coo_row_ptrs,
matrix::Hybrid<ValueType, IndexType>* result)
matrix::view::hybrid<ValueType, IndexType> result)
{
run_kernel(
exec,
Expand Down Expand Up @@ -218,10 +218,10 @@ void convert_to_hybrid(std::shared_ptr<const DefaultExecutor> exec,
},
source->get_size()[0], source->get_const_row_ptrs(),
source->get_const_col_idxs(), source->get_const_values(),
result->get_ell_stride(), result->get_ell_num_stored_elements_per_row(),
result->get_ell_col_idxs(), result->get_ell_values(), coo_row_ptrs,
result->get_coo_row_idxs(), result->get_coo_col_idxs(),
result->get_coo_values());
result.ell_part.stride, result.ell_part.num_stored_elements_per_row,
result.ell_part.col_idxs, result.ell_part.values, coo_row_ptrs,
result.coo_part.row_idxs, result.coo_part.col_idxs,
result.coo_part.values);
}

GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
Expand Down
42 changes: 20 additions & 22 deletions common/unified/matrix/hybrid_kernels.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
// SPDX-FileCopyrightText: 2017 - 2026 The Ginkgo authors
//
// SPDX-License-Identifier: BSD-3-Clause

Expand Down Expand Up @@ -51,7 +51,7 @@ template <typename ValueType, typename IndexType>
void fill_in_matrix_data(std::shared_ptr<const DefaultExecutor> exec,
const device_matrix_data<ValueType, IndexType>& data,
const int64* row_ptrs, const int64* coo_row_ptrs,
matrix::Hybrid<ValueType, IndexType>* result)
matrix::view::hybrid<ValueType, IndexType> result)
{
using device_value_type = device_type<ValueType>;
run_kernel(
Expand Down Expand Up @@ -83,25 +83,25 @@ void fill_in_matrix_data(std::shared_ptr<const DefaultExecutor> exec,
},
data.get_size()[0], row_ptrs, data.get_const_values(),
data.get_const_row_idxs(), data.get_const_col_idxs(),
result->get_ell_stride(), result->get_ell_num_stored_elements_per_row(),
result->get_ell_col_idxs(), result->get_ell_values(), coo_row_ptrs,
result->get_coo_row_idxs(), result->get_coo_col_idxs(),
result->get_coo_values());
result.ell_part.stride, result.ell_part.num_stored_elements_per_row,
result.ell_part.col_idxs, result.ell_part.values, coo_row_ptrs,
result.coo_part.row_idxs, result.coo_part.col_idxs,
result.coo_part.values);
}

GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
GKO_DECLARE_HYBRID_FILL_IN_MATRIX_DATA_KERNEL);


template <typename ValueType, typename IndexType>
void convert_to_csr(std::shared_ptr<const DefaultExecutor> exec,
const matrix::Hybrid<ValueType, IndexType>* source,
const IndexType* ell_row_ptrs,
const IndexType* coo_row_ptrs,
matrix::Csr<ValueType, IndexType>* result)
void convert_to_csr(
std::shared_ptr<const DefaultExecutor> exec,
matrix::view::hybrid<const ValueType, const IndexType> source,
const IndexType* ell_row_ptrs, const IndexType* coo_row_ptrs,
matrix::Csr<ValueType, IndexType>* result)
{
const auto ell = source->get_ell();
const auto coo = source->get_coo();
const auto ell = source.ell_part;
const auto coo = source.coo_part;
// ELL is stored in column-major, so we swap row and column parameters
run_kernel(
exec,
Expand All @@ -117,18 +117,16 @@ void convert_to_csr(std::shared_ptr<const DefaultExecutor> exec,
out_vals[out_idx] = in_vals[ell_idx];
}
},
dim<2>{ell->get_num_stored_elements_per_row(), ell->get_size()[0]},
static_cast<int64>(ell->get_stride()), ell->get_const_col_idxs(),
ell->get_const_values(), ell_row_ptrs, coo_row_ptrs,
result->get_col_idxs(), result->get_values());
dim<2>{ell.num_stored_elements_per_row, ell.size[0]},
static_cast<int64>(ell.stride), ell.col_idxs, ell.values, ell_row_ptrs,
coo_row_ptrs, result->get_col_idxs(), result->get_values());
run_kernel(
exec,
[] GKO_KERNEL(auto idx, auto ell_row_ptrs, auto coo_row_ptrs,
auto out_row_ptrs) {
out_row_ptrs[idx] = ell_row_ptrs[idx] + coo_row_ptrs[idx];
},
source->get_size()[0] + 1, ell_row_ptrs, coo_row_ptrs,
result->get_row_ptrs());
source.size[0] + 1, ell_row_ptrs, coo_row_ptrs, result->get_row_ptrs());
run_kernel(
exec,
[] GKO_KERNEL(auto idx, auto in_rows, auto in_cols, auto in_vals,
Expand All @@ -145,9 +143,9 @@ void convert_to_csr(std::shared_ptr<const DefaultExecutor> exec,
out_cols[out_idx] = col;
out_vals[out_idx] = val;
},
coo->get_num_stored_elements(), coo->get_const_row_idxs(),
coo->get_const_col_idxs(), coo->get_const_values(), ell_row_ptrs,
coo_row_ptrs, result->get_col_idxs(), result->get_values());
coo.num_stored_elements, coo.row_idxs, coo.col_idxs, coo.values,
ell_row_ptrs, coo_row_ptrs, result->get_col_idxs(),
result->get_values());
}

GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(
Expand Down
3 changes: 2 additions & 1 deletion core/matrix/csr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <ginkgo/core/matrix/dense.hpp>
#include <ginkgo/core/matrix/ell.hpp>
#include <ginkgo/core/matrix/fbcsr.hpp>
#include <ginkgo/core/matrix/hybrid.hpp>
#include <ginkgo/core/matrix/identity.hpp>
#include <ginkgo/core/matrix/permutation.hpp>
#include <ginkgo/core/matrix/scaled_permutation.hpp>
Expand Down Expand Up @@ -442,7 +443,7 @@ void Csr<ValueType, IndexType>::convert_to(
auto tmp = make_temporary_clone(exec, result);
tmp->resize(this->get_size(), ell_lim, coo_nnz);
exec->run(csr::make_convert_to_hybrid(this, coo_row_ptrs.get_const_data(),
tmp.get()));
tmp->get_device_view()));
}


Expand Down
6 changes: 1 addition & 5 deletions core/matrix/csr_kernels.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@
#include <ginkgo/core/base/array.hpp>
#include <ginkgo/core/base/index_set.hpp>
#include <ginkgo/core/base/types.hpp>
#include <ginkgo/core/matrix/coo.hpp>
#include <ginkgo/core/matrix/csr.hpp>
#include <ginkgo/core/matrix/dense.hpp>
#include <ginkgo/core/matrix/device_views.hpp>
#include <ginkgo/core/matrix/diagonal.hpp>
#include <ginkgo/core/matrix/ell.hpp>
#include <ginkgo/core/matrix/hybrid.hpp>
#include <ginkgo/core/matrix/sellp.hpp>
#include <ginkgo/core/matrix/sparsity_csr.hpp>

Expand Down Expand Up @@ -113,7 +109,7 @@ namespace kernels {
void convert_to_hybrid(std::shared_ptr<const DefaultExecutor> exec, \
const matrix::Csr<ValueType, IndexType>* source, \
const int64* coo_row_ptrs, \
matrix::Hybrid<ValueType, IndexType>* result)
matrix::view::hybrid<ValueType, IndexType> result)

#define GKO_DECLARE_CSR_CONVERT_TO_SELLP_KERNEL(ValueType, IndexType) \
void convert_to_sellp(std::shared_ptr<const DefaultExecutor> exec, \
Expand Down
2 changes: 1 addition & 1 deletion core/matrix/dense.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ void Dense<ValueType>::convert_impl(Hybrid<ValueType, IndexType>* result) const
tmp->resize(this->get_size(), ell_lim, coo_nnz);
exec->run(dense::make_convert_to_hybrid(this->get_const_device_view(),
coo_row_ptrs.get_const_data(),
tmp.get()));
tmp->get_device_view()));
}


Expand Down
2 changes: 1 addition & 1 deletion core/matrix/dense_kernels.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ namespace kernels {
void convert_to_hybrid(std::shared_ptr<const DefaultExecutor> exec, \
matrix::view::dense<const ValueType> source, \
const int64* coo_row_ptrs, \
matrix::Hybrid<ValueType, IndexType>* other)
matrix::view::hybrid<ValueType, IndexType> other)

#define GKO_DECLARE_DENSE_CONVERT_TO_SELLP_KERNEL(ValueType, IndexType) \
void convert_to_sellp(std::shared_ptr<const DefaultExecutor> exec, \
Expand Down
27 changes: 22 additions & 5 deletions core/matrix/hybrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,23 @@ Hybrid<ValueType, IndexType>::Hybrid(std::shared_ptr<const Executor> exec,
{}


template <typename ValueType, typename IndexType>
typename Hybrid<ValueType, IndexType>::device_view
Hybrid<ValueType, IndexType>::get_device_view()
{
return device_view{ell_->get_device_view(), coo_->get_device_view()};
}


template <typename ValueType, typename IndexType>
typename Hybrid<ValueType, IndexType>::const_device_view
Hybrid<ValueType, IndexType>::get_const_device_view() const
{
return const_device_view{ell_->get_const_device_view(),
coo_->get_const_device_view()};
}


template <typename ValueType, typename IndexType>
std::unique_ptr<Hybrid<ValueType, IndexType>>
Hybrid<ValueType, IndexType>::create(std::shared_ptr<const Executor> exec,
Expand Down Expand Up @@ -316,8 +333,8 @@ void Hybrid<ValueType, IndexType>::convert_to(
tmp->values_.resize_and_reset(nnz);
tmp->set_size(this->get_size());
exec->run(hybrid::make_convert_to_csr(
this, ell_row_ptrs.get_const_data(), coo_row_ptrs.get_const_data(),
tmp.get()));
this->get_const_device_view(), ell_row_ptrs.get_const_data(),
coo_row_ptrs.get_const_data(), tmp.get()));
}
result->make_srow();
}
Expand Down Expand Up @@ -367,9 +384,9 @@ void Hybrid<ValueType, IndexType>::read(const device_mat_data& data)
coo_row_ptrs.get_data()));
coo_nnz = get_element(coo_row_ptrs, num_rows);
this->resize(data.get_size(), ell_max_nnz, coo_nnz);
exec->run(
hybrid::make_fill_in_matrix_data(*local_data, row_ptrs.get_const_data(),
coo_row_ptrs.get_const_data(), this));
exec->run(hybrid::make_fill_in_matrix_data(
*local_data, row_ptrs.get_const_data(), coo_row_ptrs.get_const_data(),
this->get_device_view()));
}


Expand Down
20 changes: 10 additions & 10 deletions core/matrix/hybrid_kernels.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
// SPDX-FileCopyrightText: 2017 - 2026 The Ginkgo authors
//
// SPDX-License-Identifier: BSD-3-Clause

#ifndef GKO_CORE_MATRIX_HYBRID_KERNELS_HPP_
#define GKO_CORE_MATRIX_HYBRID_KERNELS_HPP_


#include <ginkgo/core/matrix/csr.hpp>
#include <ginkgo/core/matrix/dense.hpp>
#include <ginkgo/core/matrix/hybrid.hpp>

#include "core/base/kernel_declaration.hpp"

Expand All @@ -30,14 +30,14 @@ namespace kernels {
std::shared_ptr<const DefaultExecutor> exec, \
const device_matrix_data<ValueType, IndexType>& data, \
const int64* row_ptrs, const int64* coo_row_ptrs, \
matrix::Hybrid<ValueType, IndexType>* result)

#define GKO_DECLARE_HYBRID_CONVERT_TO_CSR_KERNEL(ValueType, IndexType) \
void convert_to_csr(std::shared_ptr<const DefaultExecutor> exec, \
const matrix::Hybrid<ValueType, IndexType>* source, \
const IndexType* ell_row_ptrs, \
const IndexType* coo_row_ptrs, \
matrix::Csr<ValueType, IndexType>* result)
matrix::view::hybrid<ValueType, IndexType> result)

#define GKO_DECLARE_HYBRID_CONVERT_TO_CSR_KERNEL(ValueType, IndexType) \
void convert_to_csr( \
std::shared_ptr<const DefaultExecutor> exec, \
matrix::view::hybrid<const ValueType, const IndexType> source, \
const IndexType* ell_row_ptrs, const IndexType* coo_row_ptrs, \
matrix::Csr<ValueType, IndexType>* result)


#define GKO_DECLARE_ALL_AS_TEMPLATES \
Expand Down
3 changes: 2 additions & 1 deletion core/reorder/rcm.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
// SPDX-FileCopyrightText: 2017 - 2026 The Ginkgo authors
//
// SPDX-License-Identifier: BSD-3-Clause

Expand All @@ -13,6 +13,7 @@
#include <ginkgo/core/base/types.hpp>
#include <ginkgo/core/base/utils.hpp>
#include <ginkgo/core/matrix/csr.hpp>
#include <ginkgo/core/matrix/dense.hpp>
#include <ginkgo/core/matrix/permutation.hpp>
#include <ginkgo/core/matrix/sparsity_csr.hpp>

Expand Down
58 changes: 57 additions & 1 deletion core/test/matrix/hybrid.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
// SPDX-FileCopyrightText: 2017 - 2026 The Ginkgo authors
//
// SPDX-License-Identifier: BSD-3-Clause

Expand Down Expand Up @@ -457,3 +457,59 @@ TYPED_TEST(Hybrid, GetCorrectAutomatic)

ASSERT_NO_THROW(gko::as<strategy2>(mtx->template get_strategy<Mtx2>()));
}


TYPED_TEST(Hybrid, CanCreateDeviceView)
{
auto view = this->mtx->get_device_view();

EXPECT_EQ(view.size, this->mtx->get_size());
EXPECT_EQ(view.ell_part.num_stored_elements_per_row,
this->mtx->get_ell_num_stored_elements_per_row());
EXPECT_EQ(view.ell_part.stride, this->mtx->get_ell_stride());
EXPECT_EQ(view.ell_part.values, this->mtx->get_ell_values());
EXPECT_EQ(view.ell_part.col_idxs, this->mtx->get_ell_col_idxs());
EXPECT_EQ(view.coo_part.num_stored_elements,
this->mtx->get_coo_num_stored_elements());
EXPECT_EQ(view.coo_part.row_idxs, this->mtx->get_coo_row_idxs());
EXPECT_EQ(view.coo_part.col_idxs, this->mtx->get_coo_col_idxs());
EXPECT_EQ(view.coo_part.values, this->mtx->get_coo_values());
}


TYPED_TEST(Hybrid, CanCreateConstDeviceView)
{
auto view = this->mtx->get_const_device_view();

EXPECT_EQ(view.size, this->mtx->get_size());
EXPECT_EQ(view.ell_part.num_stored_elements_per_row,
this->mtx->get_ell_num_stored_elements_per_row());
EXPECT_EQ(view.ell_part.stride, this->mtx->get_ell_stride());
EXPECT_EQ(view.ell_part.values, this->mtx->get_ell_values());
EXPECT_EQ(view.ell_part.col_idxs, this->mtx->get_ell_col_idxs());
EXPECT_EQ(view.coo_part.num_stored_elements,
this->mtx->get_coo_num_stored_elements());
EXPECT_EQ(view.coo_part.row_idxs, this->mtx->get_coo_row_idxs());
EXPECT_EQ(view.coo_part.col_idxs, this->mtx->get_coo_col_idxs());
EXPECT_EQ(view.coo_part.values, this->mtx->get_coo_values());
}
Comment thread
MarcelKoch marked this conversation as resolved.


TEST(HybridView, CreateFailsWithNonMatchingSizes)
{
#ifdef NDEBUG
GTEST_SKIP() << "Assertion is only enabled in debug mode";
#endif

using value_type = double;
using index_type = int;
auto exec = gko::ReferenceExecutor::create();
auto coo = gko::matrix::Coo<value_type, index_type>::create(
exec, gko::dim<2>(1, 2));
auto ell = gko::matrix::Ell<value_type, index_type>::create(
exec, gko::dim<2>(2, 1));

using view_t = gko::matrix::view::hybrid<value_type, index_type>;
EXPECT_EXIT(view_t(ell->get_device_view(), coo->get_device_view()),
check_assertion_exit_code, "");
}
4 changes: 0 additions & 4 deletions dpcpp/matrix/csr_kernels.dp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
#include <ginkgo/core/base/exception_helpers.hpp>
#include <ginkgo/core/base/math.hpp>
#include <ginkgo/core/base/std_extensions.hpp>
#include <ginkgo/core/matrix/coo.hpp>
#include <ginkgo/core/matrix/dense.hpp>
#include <ginkgo/core/matrix/ell.hpp>
#include <ginkgo/core/matrix/hybrid.hpp>
#include <ginkgo/core/matrix/sellp.hpp>

#include "accessor/sycl_helper.hpp"
Expand Down
Loading
Loading