Skip to content

Commit

Permalink
review updates
Browse files Browse the repository at this point in the history
Co-authored-by: Marcel Koch <[email protected]>
Co-authored-by: Yu-Hsiang Tsai <[email protected]>
  • Loading branch information
3 people committed May 2, 2024
1 parent 92fd162 commit 4a6e2ef
Show file tree
Hide file tree
Showing 16 changed files with 146 additions and 132 deletions.
64 changes: 58 additions & 6 deletions core/preconditioner/batch_jacobi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,64 @@ size_type Jacobi<ValueType, IndexType>::compute_storage_space(
}


template <typename ValueType, typename IndexType>
const IndexType* Jacobi<ValueType, IndexType>::get_const_block_pointers()
const noexcept
{
return block_pointers_.get_const_data();
}


template <typename ValueType, typename IndexType>
const IndexType* Jacobi<ValueType, IndexType>::get_const_map_block_to_row()
const noexcept
{
return map_block_to_row_.get_const_data();
}


template <typename ValueType, typename IndexType>
const IndexType* Jacobi<
ValueType, IndexType>::get_const_blocks_cumulative_offsets() const noexcept
{
return blocks_cumulative_offsets_.get_const_data();
}


template <typename ValueType, typename IndexType>
uint32 Jacobi<ValueType, IndexType>::get_max_block_size() const noexcept
{
return parameters_.max_block_size;
}


template <typename ValueType, typename IndexType>
size_type Jacobi<ValueType, IndexType>::get_num_blocks() const noexcept
{
return num_blocks_;
}

template <typename ValueType, typename IndexType>
const ValueType* Jacobi<ValueType, IndexType>::get_const_blocks() const noexcept
{
return blocks_.get_const_data();
}


template <typename ValueType, typename IndexType>
size_type Jacobi<ValueType, IndexType>::get_num_stored_elements() const noexcept
{
return blocks_.get_size();
}


template <typename ValueType, typename IndexType>
Jacobi<ValueType, IndexType>::Jacobi(std::shared_ptr<const Executor> exec)
: EnableBatchLinOp<Jacobi>(exec),
num_blocks_{},
num_blocks_{0},
block_pointers_(exec),
blocks_(exec),
row_block_map_info_(exec),
map_block_to_row_(exec),
blocks_cumulative_offsets_(exec)
{}

Expand All @@ -63,8 +114,8 @@ Jacobi<ValueType, IndexType>::Jacobi(
num_blocks_{
block_pointers_.get_size() > 0 ? block_pointers_.get_size() - 1 : 0},
blocks_(factory->get_executor()),
row_block_map_info_(factory->get_executor(),
system_matrix->get_common_size()[0]),
map_block_to_row_(factory->get_executor(),
system_matrix->get_common_size()[0]),
blocks_cumulative_offsets_(factory->get_executor(), num_blocks_ + 1)
{
GKO_ASSERT_BATCH_HAS_SQUARE_DIMENSIONS(system_matrix);
Expand Down Expand Up @@ -128,6 +179,7 @@ void Jacobi<ValueType, IndexType>::generate_precond(
std::move(sys_rows_view)));

if (block_pointers_.get_data() == nullptr) {
block_pointers_.set_executor(exec);
this->detect_blocks(first_sys_csr.get());
exec->synchronize();
blocks_cumulative_offsets_.resize_and_reset(num_blocks_ + 1);
Expand All @@ -142,7 +194,7 @@ void Jacobi<ValueType, IndexType>::generate_precond(

exec->run(jacobi::make_find_row_block_map(num_blocks_,
block_pointers_.get_const_data(),
row_block_map_info_.get_data()));
map_block_to_row_.get_data()));

// Note: Row-major order offers advantage in terms of
// performance in both preconditioner generation and application for both
Expand All @@ -163,7 +215,7 @@ void Jacobi<ValueType, IndexType>::generate_precond(
exec->run(jacobi::make_extract_common_blocks_pattern(
first_sys_csr.get(), num_blocks_,
blocks_cumulative_offsets_.get_const_data(),
block_pointers_.get_const_data(), row_block_map_info_.get_const_data(),
block_pointers_.get_const_data(), map_block_to_row_.get_const_data(),
block_nnz_idxs.get_data()));

exec->run(jacobi::make_compute_block_jacobi(
Expand Down
2 changes: 1 addition & 1 deletion core/preconditioner/batch_jacobi_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ GKO_ATTRIBUTES static size_type get_block_offset(
* @param block_storage_cumulative the cumulative block storage array
*
* @return the global offset of the block which belongs to the batch entry
* with index = batch_id and has local id = "block_id" within its batch
* with index = "batch_id" and has local id = "block_id" within its batch
* entry
*/
GKO_ATTRIBUTES static size_type get_global_block_offset(
Expand Down
4 changes: 2 additions & 2 deletions core/preconditioner/batch_jacobi_kernels.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace kernels {
void find_row_block_map(std::shared_ptr<const DefaultExecutor> exec, \
const size_type num_blocks, \
const IndexType* block_pointers, \
IndexType* row_block_map_info)
IndexType* map_block_to_row)

#define GKO_DECLARE_BATCH_BLOCK_JACOBI_COMPUTE_CUMULATIVE_BLOCK_STORAGE( \
IndexType) \
Expand All @@ -42,7 +42,7 @@ namespace kernels {
std::shared_ptr<const DefaultExecutor> exec, \
const matrix::Csr<ValueType, IndexType>* first_sys_csr, \
const size_type num_blocks, const IndexType* cumulative_block_storage, \
const IndexType* block_pointers, const IndexType* row_block_map_info, \
const IndexType* block_pointers, const IndexType* map_block_to_row, \
IndexType* blocks_pattern)


Expand Down
18 changes: 7 additions & 11 deletions core/solver/batch_dispatch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,7 @@ class batch_solver_dispatch {
{
if (!precond_ ||
dynamic_cast<const matrix::Identity<value_type>*>(precond_)) {
dispatch_on_stop<
device::batch_preconditioner::Identity<device_value_type>>(
dispatch_on_stop(
logger, mat_item,
device::batch_preconditioner::Identity<device_value_type>(),
b_item, x_item);
Expand All @@ -237,25 +236,22 @@ class batch_solver_dispatch {
precond_)) {
const auto max_block_size = prec->get_max_block_size();
if (max_block_size == 1) {
dispatch_on_stop<device::batch_preconditioner::ScalarJacobi<
device_value_type>>(
logger, mat_item,
device::batch_preconditioner::ScalarJacobi<
device_value_type>(),
b_item, x_item);
dispatch_on_stop(logger, mat_item,
device::batch_preconditioner::ScalarJacobi<
device_value_type>(),
b_item, x_item);
} else {
const auto num_blocks = prec->get_num_blocks();
const auto block_ptrs_arr = prec->get_const_block_pointers();
const auto row_block_map_arr =
prec->get_const_row_block_map_info();
prec->get_const_map_block_to_row();
const auto blocks_arr =
reinterpret_cast<DeviceValueType<const ValueType*>>(
prec->get_const_blocks());
const auto blocks_cumul_storage =
prec->get_const_blocks_cumulative_offsets();

dispatch_on_stop<device::batch_preconditioner::BlockJacobi<
device_value_type>>(
dispatch_on_stop(
logger, mat_item,
device::batch_preconditioner::BlockJacobi<
device_value_type>(max_block_size, num_blocks,
Expand Down
61 changes: 30 additions & 31 deletions core/test/utils/assertions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,11 +530,10 @@ ::testing::AssertionResult array_equal_impl(


template <typename ValueType>
::testing::AssertionResult array_near_impl(const std::string& first_expression,
const std::string& second_expression,
const array<ValueType>& first,
const array<ValueType>& second,
double tolerance)
::testing::AssertionResult array_near_impl(
const std::string& first_expression, const std::string& second_expression,
const std::string& tolerance_expression, const array<ValueType>& first,
const array<ValueType>& second, double tolerance)
{
const auto num_elems1 = first.get_size();
const auto num_elems2 = second.get_size();
Expand All @@ -556,8 +555,8 @@ ::testing::AssertionResult array_near_impl(const std::string& first_expression,
auto fail = ::testing::AssertionFailure();
fail << "Array " << first_expression << " is different from "
<< second_expression << " at index " << i
<< " with relative error: " << err
<< ", tolerance: " << tolerance << "\n";
<< " with relative error: " << err << ", expected "
<< tolerance_expression << " (which is " << tolerance << ")\n";
return fail;
}
}
Expand Down Expand Up @@ -870,7 +869,7 @@ ::testing::AssertionResult array_equal(const std::string& first_expression,
* ASSERT_PRED_FORMAT2(gko::test::assertions::array_equal, array1, array2);
* ```
*
* @see GKO_ASSERT_ARRAY_EQ
* @see GKO_ASSERT_ARRAY_NEAR
*/
template <typename ValueType>
::testing::AssertionResult array_near(const std::string& first_expression,
Expand All @@ -880,8 +879,29 @@ ::testing::AssertionResult array_near(const std::string& first_expression,
const array<ValueType>& second,
double tolerance)
{
return detail::array_near_impl(first_expression, second_expression, first,
second, tolerance);
return detail::array_near_impl(first_expression, second_expression,
tolerance_expression, first, second,
tolerance);
}


/**
* array_nearoverload: where both `first` and `second` are const_array_views.
* It creates array copies of the const_array_view and then compare `first` and
* `second`
*
* @copydoc array_near
*/
template <typename ValueType>
::testing::AssertionResult array_near(
const std::string& first_expression, const std::string& second_expression,
const std::string& tolerance_expression,
const gko::detail::const_array_view<ValueType>& first,
const gko::detail::const_array_view<ValueType>& second, double tolerance)
{
return detail::array_near_impl(first_expression, second_expression,
tolerance_expression, first.copy_to_array(),
second.copy_to_array(), tolerance);
}


Expand Down Expand Up @@ -937,27 +957,6 @@ ::testing::AssertionResult array_equal(
second.copy_to_array());
}

// /**
// * array_equal overload: where both `first` and `second` are
// const_array_views.
// * It creates array copies of the const_array_view and then compare `first`
// and
// * `second`
// *
// * @copydoc array_equal
// */
// template <typename ValueType>
// ::testing::AssertionResult array_near(
// const std::string& first_expression, const std::string&
// second_expression, const std::string& tolerance_expression, const
// gko::detail::const_array_view<ValueType>& first, const
// gko::detail::const_array_view<ValueType>& second, double tolerance)
// {
// return detail::array_near_impl(first_expression, second_expression,
// tolerance_expression,
// first.copy_to_array(),
// second.copy_to_array(), tolerance);
// }

/** array_equal overloads where one side is an initializer list .*/
template <typename ValueType>
Expand Down
8 changes: 4 additions & 4 deletions cuda/preconditioner/batch_jacobi_kernels.cu
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ GKO_INSTANTIATE_FOR_INT32_TYPE(


template <typename IndexType>
void find_row_block_map(
std::shared_ptr<const DefaultExecutor> exec, const size_type num_blocks,
const IndexType* const block_pointers,
IndexType* const row_block_map_info) GKO_NOT_IMPLEMENTED;
void find_row_block_map(std::shared_ptr<const DefaultExecutor> exec,
const size_type num_blocks,
const IndexType* const block_pointers,
IndexType* const map_block_to_row) GKO_NOT_IMPLEMENTED;

GKO_INSTANTIATE_FOR_INT32_TYPE(
GKO_DECLARE_BATCH_BLOCK_JACOBI_FIND_ROW_BLOCK_MAP);
Expand Down
8 changes: 4 additions & 4 deletions dpcpp/preconditioner/batch_jacobi_kernels.dp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ GKO_INSTANTIATE_FOR_INT32_TYPE(


template <typename IndexType>
void find_row_block_map(
std::shared_ptr<const DefaultExecutor> exec, const size_type num_blocks,
const IndexType* const block_pointers,
IndexType* const row_block_map_info) GKO_NOT_IMPLEMENTED;
void find_row_block_map(std::shared_ptr<const DefaultExecutor> exec,
const size_type num_blocks,
const IndexType* const block_pointers,
IndexType* const map_block_to_row) GKO_NOT_IMPLEMENTED;

GKO_INSTANTIATE_FOR_INT32_TYPE(
GKO_DECLARE_BATCH_BLOCK_JACOBI_FIND_ROW_BLOCK_MAP);
Expand Down
8 changes: 4 additions & 4 deletions hip/preconditioner/batch_jacobi_kernels.hip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ GKO_INSTANTIATE_FOR_INT32_TYPE(


template <typename IndexType>
void find_row_block_map(
std::shared_ptr<const DefaultExecutor> exec, const size_type num_blocks,
const IndexType* const block_pointers,
IndexType* const row_block_map_info) GKO_NOT_IMPLEMENTED;
void find_row_block_map(std::shared_ptr<const DefaultExecutor> exec,
const size_type num_blocks,
const IndexType* const block_pointers,
IndexType* const map_block_to_row) GKO_NOT_IMPLEMENTED;

GKO_INSTANTIATE_FOR_INT32_TYPE(
GKO_DECLARE_BATCH_BLOCK_JACOBI_FIND_ROW_BLOCK_MAP);
Expand Down
Loading

0 comments on commit 4a6e2ef

Please sign in to comment.