Skip to content

Commit

Permalink
Merge (#1371): Add a batch::MultiVector class, kernels and tests
Browse files Browse the repository at this point in the history
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
pratikvn authored Aug 3, 2023
2 parents 1b71986 + 86e9312 commit 1882753
Show file tree
Hide file tree
Showing 42 changed files with 5,179 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/intel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
spack find --loaded
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=install_ginkgo -DCMAKE_CXX_COMPILER=dpcpp -DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} -DGINKGO_MIXED_PRECISION=${{ matrix.config.mixed }} -DGINKGO_DPCPP_SINGLE_MODE=ON
cmake .. -DCMAKE_INSTALL_PREFIX=install_ginkgo -DGINKGO_COMPILER_FLAGS="-ffp-model=precise" -DCMAKE_CXX_COMPILER=dpcpp -DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} -DGINKGO_MIXED_PRECISION=${{ matrix.config.mixed }} -DGINKGO_DPCPP_SINGLE_MODE=ON
make -j8
ONEAPI_DEVICE_SELECTOR=level_zero:gpu ctest -j10 --output-on-failure
Expand Down
6 changes: 6 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ build/dpcpp/2022-1/cpu/release/static:
C_COMPILER: "gcc"
CXX_COMPILER: "dpcpp"
BUILD_DPCPP: "ON"
GKO_COMPILER_FLAGS: "-ffp-model=precise"
BUILD_TYPE: "Release"
BUILD_SHARED_LIBS: "ON"
SYCL_DEVICE_FILTER: "*:cpu"
Expand All @@ -631,6 +632,7 @@ build/dpcpp/igpu/release/shared:
C_COMPILER: "gcc"
CXX_COMPILER: "dpcpp"
BUILD_DPCPP: "ON"
GKO_COMPILER_FLAGS: "-ffp-model=precise"
BUILD_TYPE: "Release"
BUILD_SHARED_LIBS: "ON"
DPCPP_SINGLE_MODE: "ON"
Expand All @@ -647,6 +649,7 @@ build/dpcpp/igpu/release/shared:
# C_COMPILER: "gcc"
# CXX_COMPILER: "dpcpp"
# BUILD_DPCPP: "ON"
# GKO_COMPILER_FLAGS: "-ffp-model=precise"
# BUILD_TYPE: "Debug"
# BUILD_SHARED_LIBS: "ON"
# DPCPP_SINGLE_MODE: "ON"
Expand All @@ -663,6 +666,7 @@ build/dpcpp/dgpu/release/static:
C_COMPILER: "gcc"
CXX_COMPILER: "dpcpp"
BUILD_DPCPP: "ON"
GKO_COMPILER_FLAGS: "-ffp-model=precise"
BUILD_TYPE: "Release"
BUILD_SHARED_LIBS: "OF"
DPCPP_SINGLE_MODE: "ON"
Expand All @@ -678,6 +682,7 @@ build/dpcpp/level_zero_dgpu/release/shared:
C_COMPILER: "gcc"
CXX_COMPILER: "dpcpp"
BUILD_DPCPP: "ON"
GKO_COMPILER_FLAGS: "-ffp-model=precise"
BUILD_TYPE: "Release"
DPCPP_SINGLE_MODE: "ON"
ONEAPI_DEVICE_SELECTOR: "level_zero:gpu"
Expand All @@ -695,6 +700,7 @@ warnings:
BUILD_CUDA: "ON"
BUILD_HIP: "ON"
CXX_FLAGS: "-Werror=pedantic -pedantic-errors"
GKO_COMPILER_FLAGS: "-Wpedantic"
allow_failure: yes

# Ensure kernel modules do not depend on core
Expand Down
2 changes: 2 additions & 0 deletions .gitlab/scripts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
-DCMAKE_CUDA_COMPILER=${CUDA_COMPILER} -DCMAKE_BUILD_TYPE=${BUILD_TYPE}
-DCMAKE_CXX_FLAGS="${CXX_FLAGS}" -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
${EXTRA_CMAKE_FLAGS} ${CUDA_ARCH_STR} ${CUDA_HOST_STR}
-DGINKGO_COMPILER_FLAGS=${GKO_COMPILER_FLAGS}
-DGINKGO_DEVEL_TOOLS=OFF -DGINKGO_BUILD_REFERENCE=${BUILD_REFERENCE}
-DGINKGO_BUILD_OMP=${BUILD_OMP} -DGINKGO_BUILD_CUDA=${BUILD_CUDA}
-DGINKGO_BUILD_HIP=${BUILD_HIP}
Expand Down Expand Up @@ -82,6 +83,7 @@
-DCMAKE_CUDA_COMPILER=${CUDA_COMPILER} -DCMAKE_BUILD_TYPE=${BUILD_TYPE}
-DCMAKE_CXX_FLAGS="${CXX_FLAGS}" -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}
${EXTRA_CMAKE_FLAGS} ${CUDA_ARCH_STR} ${CUDA_HOST_STR}
-DGINKGO_COMPILER_FLAGS=${GKO_COMPILER_FLAGS}
-DGINKGO_DEVEL_TOOLS=OFF -DGINKGO_BUILD_REFERENCE=${BUILD_REFERENCE}
-DGINKGO_BUILD_OMP=${BUILD_OMP} -DGINKGO_BUILD_CUDA=${BUILD_CUDA}
-DGINKGO_BUILD_HIP=${BUILD_HIP}
Expand Down
1 change: 1 addition & 0 deletions .gitlab/variables.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
BUILD_HIP: "OFF"
BUILD_HWLOC: "ON"
BUILD_MPI: "OFF"
GKO_COMPILER_FLAGS: ""
MPI_AS_ROOT: "OFF"
FAST_TESTS: "OFF"
NONDEFAULT_STREAM: "OFF"
Expand Down
150 changes: 150 additions & 0 deletions common/cuda_hip/base/batch_multi_vector_kernel_launcher.hpp.inc
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);
Loading

0 comments on commit 1882753

Please sign in to comment.