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 a Dense batched class and kernels #1413

Merged
merged 28 commits into from
Oct 12, 2023
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5f2379f
Add batch dense base class, core and kernels
pratikvn Oct 1, 2023
e9f2aa1
add reference kernels WIP
pratikvn Oct 2, 2023
2f6bd77
Generalize batch utilities
pratikvn Oct 3, 2023
c9d5b44
MultiVector to BatchDense conversion
pratikvn Oct 3, 2023
4053a95
Add tests for BatchDense core
pratikvn Oct 3, 2023
e4928b2
Add reference kernel tests
pratikvn Oct 3, 2023
ecc7e51
Add OMP tests and fix kernel
pratikvn Oct 3, 2023
ccbbb40
Format files
ginkgo-bot Oct 4, 2023
691201a
circ dep and typo fixes
pratikvn Oct 4, 2023
a4b82ea
Add CUDA, HIP kernels and tests
pratikvn Oct 4, 2023
b23dbfa
Add SYCL kernels and tests WIP
pratikvn Oct 4, 2023
07578dd
HIP and CUDA thrust fixes
pratikvn Oct 5, 2023
81bcf74
SYCL kernel fixes
pratikvn Oct 5, 2023
2483667
BatchDense -> batch::Dense
pratikvn Oct 5, 2023
b402b94
Doc updates and multivector view
pratikvn Oct 5, 2023
3ca9fb4
Format files
ginkgo-bot Oct 6, 2023
e5b8813
Use CommonTestFixture value_type
pratikvn Oct 6, 2023
c00b6d9
Review updates
pratikvn Oct 9, 2023
fe21d65
Review updates
pratikvn Oct 9, 2023
f210ea9
dpcpp Jacobi needs ranlux
pratikvn Oct 9, 2023
fb74b71
Remove create_multivector_view
pratikvn Oct 9, 2023
660ec7c
Format files
ginkgo-bot Oct 9, 2023
76726e9
const_array_view needs to be in gko::
pratikvn Oct 9, 2023
09b7574
Review updates
pratikvn Oct 10, 2023
94452e9
Move apply validation to BatchLinOp
pratikvn Oct 10, 2023
4a18c40
Add to test_install
pratikvn Oct 10, 2023
927e8c8
Format files
ginkgo-bot Oct 10, 2023
190a010
Review updates
pratikvn Oct 10, 2023
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
Prev Previous commit
Next Next commit
Review updates
Co-authored-by: Marcel Koch <[email protected]>
pratikvn and MarcelKoch committed Oct 11, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit c00b6d9b748491de5dc28e174d1cb9ce2de8bfa4
16 changes: 12 additions & 4 deletions core/base/batch_multi_vector.cpp
Original file line number Diff line number Diff line change
@@ -294,11 +294,12 @@ void MultiVector<ValueType>::move_to(
template <typename ValueType>
void MultiVector<ValueType>::convert_to(matrix::Dense<ValueType>* result) const
{
auto exec = result->get_executor() != nullptr ? result->get_executor()
: this->get_executor();
auto exec = result->get_executor() == nullptr ? this->get_executor()
: result->get_executor();
auto tmp = gko::batch::matrix::Dense<ValueType>::create_const(
exec, this->get_size(),
make_const_array_view(exec, this->get_num_stored_elements(),
make_const_array_view(this->get_executor(),
this->get_num_stored_elements(),
this->get_const_values()));
result->copy_from(tmp);
}
@@ -307,7 +308,14 @@ void MultiVector<ValueType>::convert_to(matrix::Dense<ValueType>* result) const
template <typename ValueType>
void MultiVector<ValueType>::move_to(matrix::Dense<ValueType>* result)
{
this->convert_to(result);
auto exec = result->get_executor() == nullptr ? this->get_executor()
: result->get_executor();
auto tmp = gko::batch::matrix::Dense<ValueType>::create_const(
exec, this->get_size(),
make_const_array_view(this->get_executor(),
this->get_num_stored_elements(),
this->get_const_values()));
tmp->move_to(result);
}


7 changes: 3 additions & 4 deletions core/base/batch_utilities.hpp
Original file line number Diff line number Diff line change
@@ -109,14 +109,13 @@ std::unique_ptr<OutputType> create_from_item(


template <typename InputType>
auto unbatch(const InputType* batch_multivec)
auto unbatch(const InputType* batch_object)
{
auto exec = batch_multivec->get_executor();
auto unbatched_mats =
std::vector<std::unique_ptr<typename InputType::unbatch_type>>{};
for (size_type b = 0; b < batch_multivec->get_num_batch_items(); ++b) {
for (size_type b = 0; b < batch_object->get_num_batch_items(); ++b) {
unbatched_mats.emplace_back(
batch_multivec->create_const_view_for_item(b)->clone());
batch_object->create_const_view_for_item(b)->clone());
}
return unbatched_mats;
}
25 changes: 0 additions & 25 deletions core/matrix/batch_dense.cpp
Original file line number Diff line number Diff line change
@@ -64,24 +64,6 @@ GKO_REGISTER_OPERATION(advanced_apply, batch_dense::advanced_apply);
} // namespace dense


namespace detail {


template <typename ValueType>
batch_dim<2> compute_batch_size(
const std::vector<gko::matrix::Dense<ValueType>*>& matrices)
{
auto common_size = matrices[0]->get_size();
for (size_type i = 1; i < matrices.size(); ++i) {
GKO_ASSERT_EQUAL_DIMENSIONS(common_size, matrices[i]->get_size());
}
return batch_dim<2>{matrices.size(), common_size};
}


} // namespace detail


template <typename ValueType>
std::unique_ptr<gko::batch::MultiVector<ValueType>>
Dense<ValueType>::create_multi_vector_view()
@@ -178,13 +160,6 @@ std::unique_ptr<const Dense<ValueType>> Dense<ValueType>::create_const(
}


inline const batch_dim<2> get_col_sizes(const batch_dim<2>& sizes)
{
return batch_dim<2>(sizes.get_num_batch_items(),
dim<2>(1, sizes.get_common_size()[1]));
}


template <typename ValueType>
Dense<ValueType>::Dense(std::shared_ptr<const Executor> exec,
const batch_dim<2>& size)
2 changes: 1 addition & 1 deletion dpcpp/test/preconditioner/jacobi_kernels.dp.cpp
Original file line number Diff line number Diff line change
@@ -90,7 +90,7 @@ class Jacobi : public ::testing::Test {
gko::uint32 max_block_size, int min_nnz, int max_nnz, int num_rhs = 1,
value_type accuracy = 0.1, bool skip_sorting = true)
{
std::ranlux48 engine(42);
std::default_random_engine engine(42);
const auto dim = *(end(block_pointers) - 1);
if (condition_numbers.size() == 0) {
mtx = gko::test::generate_random_matrix<Mtx>(
2 changes: 1 addition & 1 deletion include/ginkgo/core/matrix/batch_dense.hpp
Original file line number Diff line number Diff line change
@@ -62,7 +62,7 @@ namespace matrix {
* belonging to the same row appear consecutive in the memory and the values of
* each batch item are also stored consecutively in memory).
*
* @note Though the storage layout is similar to the multi-vector object, the
* @note Though the storage layout is the same as the multi-vector object, the
* class semantics and the operations it aims to provide is different. Hence it
pratikvn marked this conversation as resolved.
Show resolved Hide resolved
* is recommended to create multi-vector objects if the user means to view the
* data as a set of vectors.
2 changes: 1 addition & 1 deletion reference/matrix/batch_dense_kernels.hpp.inc
Original file line number Diff line number Diff line change
@@ -71,7 +71,7 @@ inline void advanced_apply_kernel(
} else {
for (int row = 0; row < c.num_rows; ++row) {
for (int col = 0; col < c.num_rhs; ++col) {
c.values[row * c.stride + col] *= gko::zero<ValueType>();
c.values[row * c.stride + col] = gko::zero<ValueType>();
}
}
}
2 changes: 1 addition & 1 deletion reference/test/matrix/batch_dense_kernels.cpp
Original file line number Diff line number Diff line change
@@ -107,7 +107,7 @@ class Dense : public ::testing::Test {
std::unique_ptr<DenseMtx> x_00;
std::unique_ptr<DenseMtx> x_01;

std::ranlux48 rand_engine;
std::default_random_engine rand_engine;
};


2 changes: 1 addition & 1 deletion test/matrix/batch_dense_kernels.cpp
Original file line number Diff line number Diff line change
@@ -90,7 +90,7 @@ class Dense : public CommonTestFixture {
dresult = gko::clone(exec, expected);
}

std::ranlux48 rand_engine;
std::default_random_engine rand_engine;

const size_t batch_size = 11;
std::unique_ptr<Mtx> x;