-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge (#1371): Add a batch::MultiVector class, kernels and tests
This PR adds the batch::MultiVector class, which implements the batched multi-vector object. Following our discussion, this is now separate from the LinOp/BatchLinOp hierarchy. In addition, the following things are also added in this PR: 1. batch_dim<> functionality which is a simple wrapper over dim<> for storing uniform batched objects. 2. batch_struct, to ease the access and implementation of the backend kernels. 3. batch_initialize functions used to initialize the all matrix formats in a fashion similar to Dense<>::initialize(...). 4. Backend kernels and tests for OpenMP, CUDA, HIP and DPCPP and their tests. There are no apply kernels as this is only a Multi-vector object and hence does not lend itself to the apply functionality. To be general enough, a MultiVector is supported even though the solvers in batch_develop currently only support single vector. This PR is first in the series of the functionality that brings batched functionality to Ginkgo develop and part of the functionality has been in batch-develop. Some aspects discussed in the PR will be implemented in a later PR and has been logged in #1376 Related PR: #1371
- Loading branch information
Showing
42 changed files
with
5,179 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
common/cuda_hip/base/batch_multi_vector_kernel_launcher.hpp.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/*******************************<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>*******************************/ | ||
|
||
|
||
template <typename ValueType> | ||
void scale(std::shared_ptr<const DefaultExecutor> exec, | ||
const batch::MultiVector<ValueType>* const alpha, | ||
batch::MultiVector<ValueType>* const x) | ||
{ | ||
const auto num_blocks = x->get_num_batch_items(); | ||
const auto alpha_ub = get_batch_struct(alpha); | ||
const auto x_ub = get_batch_struct(x); | ||
if (alpha->get_common_size()[1] == 1) { | ||
scale_kernel<<<num_blocks, default_block_size, 0, exec->get_stream()>>>( | ||
alpha_ub, x_ub, [] __device__(int col) { return 0; }); | ||
} else { | ||
scale_kernel<<<num_blocks, default_block_size, 0, exec->get_stream()>>>( | ||
alpha_ub, x_ub, [] __device__(int col) { return col; }); | ||
} | ||
} | ||
|
||
GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE( | ||
GKO_DECLARE_BATCH_MULTI_VECTOR_SCALE_KERNEL); | ||
|
||
|
||
template <typename ValueType> | ||
void add_scaled(std::shared_ptr<const DefaultExecutor> exec, | ||
const batch::MultiVector<ValueType>* const alpha, | ||
const batch::MultiVector<ValueType>* const x, | ||
batch::MultiVector<ValueType>* const y) | ||
{ | ||
const auto num_blocks = x->get_num_batch_items(); | ||
const size_type nrhs = x->get_common_size()[1]; | ||
const auto alpha_ub = get_batch_struct(alpha); | ||
const auto x_ub = get_batch_struct(x); | ||
const auto y_ub = get_batch_struct(y); | ||
if (alpha->get_common_size()[1] == 1) { | ||
add_scaled_kernel<<<num_blocks, default_block_size, 0, | ||
exec->get_stream()>>>( | ||
alpha_ub, x_ub, y_ub, [] __device__(int col) { return 0; }); | ||
} else { | ||
add_scaled_kernel<<<num_blocks, default_block_size, 0, | ||
exec->get_stream()>>>( | ||
alpha_ub, x_ub, y_ub, [] __device__(int col) { return col; }); | ||
} | ||
} | ||
|
||
GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE( | ||
GKO_DECLARE_BATCH_MULTI_VECTOR_ADD_SCALED_KERNEL); | ||
|
||
|
||
template <typename ValueType> | ||
void compute_dot(std::shared_ptr<const DefaultExecutor> exec, | ||
const batch::MultiVector<ValueType>* x, | ||
const batch::MultiVector<ValueType>* y, | ||
batch::MultiVector<ValueType>* result) | ||
{ | ||
const auto num_blocks = x->get_num_batch_items(); | ||
const auto num_rhs = x->get_common_size()[1]; | ||
const auto x_ub = get_batch_struct(x); | ||
const auto y_ub = get_batch_struct(y); | ||
const auto res_ub = get_batch_struct(result); | ||
compute_gen_dot_product_kernel<<<num_blocks, default_block_size, 0, | ||
exec->get_stream()>>>( | ||
x_ub, y_ub, res_ub, [] __device__(auto val) { return val; }); | ||
} | ||
|
||
GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE( | ||
GKO_DECLARE_BATCH_MULTI_VECTOR_COMPUTE_DOT_KERNEL); | ||
|
||
|
||
template <typename ValueType> | ||
void compute_conj_dot(std::shared_ptr<const DefaultExecutor> exec, | ||
const batch::MultiVector<ValueType>* x, | ||
const batch::MultiVector<ValueType>* y, | ||
batch::MultiVector<ValueType>* result) | ||
{ | ||
const auto num_blocks = x->get_num_batch_items(); | ||
const auto num_rhs = x->get_common_size()[1]; | ||
const auto x_ub = get_batch_struct(x); | ||
const auto y_ub = get_batch_struct(y); | ||
const auto res_ub = get_batch_struct(result); | ||
compute_gen_dot_product_kernel<<<num_blocks, default_block_size, 0, | ||
exec->get_stream()>>>( | ||
x_ub, y_ub, res_ub, [] __device__(auto val) { return conj(val); }); | ||
} | ||
|
||
GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE( | ||
GKO_DECLARE_BATCH_MULTI_VECTOR_COMPUTE_CONJ_DOT_KERNEL); | ||
|
||
|
||
template <typename ValueType> | ||
void compute_norm2(std::shared_ptr<const DefaultExecutor> exec, | ||
const batch::MultiVector<ValueType>* const x, | ||
batch::MultiVector<remove_complex<ValueType>>* const result) | ||
{ | ||
const auto num_blocks = x->get_num_batch_items(); | ||
const auto num_rhs = x->get_common_size()[1]; | ||
const auto x_ub = get_batch_struct(x); | ||
const auto res_ub = get_batch_struct(result); | ||
compute_norm2_kernel<<<num_blocks, default_block_size, 0, | ||
exec->get_stream()>>>(x_ub, res_ub); | ||
} | ||
|
||
GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE( | ||
GKO_DECLARE_BATCH_MULTI_VECTOR_COMPUTE_NORM2_KERNEL); | ||
|
||
|
||
template <typename ValueType> | ||
void copy(std::shared_ptr<const DefaultExecutor> exec, | ||
const batch::MultiVector<ValueType>* x, | ||
batch::MultiVector<ValueType>* result) | ||
{ | ||
const auto num_blocks = x->get_num_batch_items(); | ||
const auto result_ub = get_batch_struct(result); | ||
const auto x_ub = get_batch_struct(x); | ||
copy_kernel<<<num_blocks, default_block_size, 0, exec->get_stream()>>>( | ||
x_ub, result_ub); | ||
} | ||
|
||
GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE(GKO_DECLARE_BATCH_MULTI_VECTOR_COPY_KERNEL); |
Oops, something went wrong.