Skip to content

Commit

Permalink
Add BatchIdentity preconditioner
Browse files Browse the repository at this point in the history
Co-authored-by: Aditya Kashi <[email protected]>
  • Loading branch information
pratikvn and Slaedr committed Oct 21, 2023
1 parent 0ef96d7 commit ca38a9f
Show file tree
Hide file tree
Showing 6 changed files with 443 additions and 0 deletions.
89 changes: 89 additions & 0 deletions common/cuda_hip/preconditioner/batch_identity.hpp.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*******************************<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>*******************************/

/**
* Identity preconditioner for batch solvers. ( To be able to have
* unpreconditioned solves )
*/
template <typename ValueType>
class BatchIdentity final {
public:
using value_type = ValueType;

/**
* The size of the work vector required in case of static allocation.
*/
static constexpr int work_size = 0;

/**
* The size of the work vector required in case of dynamic allocation.
*
* For the Identity preconditioner, this is unnecessary, but this function
* is part of a 'batch preconditioner interface' because other
* preconditioners may need it.
*/
__host__ __device__ static constexpr int dynamic_work_size(int, int)
{
return 0;
}


/**
* Sets the input and generates the identity preconditioner.(Nothing needs
* to be actually generated.)
*
* @param mat Matrix for which to build an Ideniity preconditioner.
* @param work A 'work-vector', which is unneecessary here as no
* preconditioner values are to be stored.
*/
__device__ __forceinline__ void generate(
size_type,
const gko::batch::matrix::ell::batch_item<const ValueType, gko::int32>&
mat,
ValueType*)
{}

__device__ __forceinline__ void generate(
size_type,
const gko::batch::matrix::dense::batch_item<const ValueType>& mat,
ValueType*)
{}

__device__ __forceinline__ void apply(const int num_rows,
const ValueType* const r,
ValueType* const z) const
{
for (int li = threadIdx.x; li < num_rows; li += blockDim.x) {
z[li] = r[li];
}
}
};
58 changes: 58 additions & 0 deletions cuda/preconditioner/batch_preconditioners.cuh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*******************************<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>*******************************/

#ifndef GKO_CUDA_PRECONDITIONER_BATCH_PRECONDITIONERS_CUH_
#define GKO_CUDA_PRECONDITIONER_BATCH_PRECONDITIONERS_CUH_


#include <ginkgo/core/matrix/batch_identity.hpp>


#include "core/matrix/batch_struct.hpp"
#include "cuda/components/cooperative_groups.cuh"
#include "cuda/components/load_store.cuh"
#include "cuda/components/reduction.cuh"


namespace gko {
namespace kernels {
namespace cuda {


#include "common/cuda_hip/preconditioner/batch_identity.hpp.inc"


} // namespace cuda
} // namespace kernels
} // namespace gko

#endif // GKO_CUDA_PRECONDITIONER_BATCH_PRECONDITIONERS_CUH_
81 changes: 81 additions & 0 deletions dpcpp/preconditioner/batch_identity.hpp.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*******************************<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>*******************************/


/**
* Identity preconditioner for batch solvers. ( To be able to have
* unpreconditioned solves )
*/
template <typename ValueType>
class BatchIdentity final {
public:
using value_type = ValueType;

/**
* The size of the work vector required in case of static allocation.
*/
static constexpr int work_size = 0;

/**
* The size of the work vector required in case of dynamic allocation.
*/
static int dynamic_work_size(int, int) { return 0; }


/**
* Sets the input and generates the identity preconditioner.(Nothing needs
* to be actually generated.)
*
* @param mat Matrix for which to build an Ideniity preconditioner.
* @param work A 'work-vector', which is unneecessary here as no
* preconditioner values are to be stored.
*/
void generate(size_type batch_id,
const gko::batch::matrix::ell::batch_item<const ValueType>&,
ValueType* const, sycl::nd_item<3> item_ct1)
{}

void generate(size_type batch_id,
const gko::batch::matrix::dense::batch_item<const ValueType>&,
ValueType* const, sycl::nd_item<3> item_ct1)
{}

__dpct_inline__ void apply(const int num_rows, const ValueType* const r,
ValueType* const z,
sycl::nd_item<3> item_ct1) const
{
for (int li = item_ct1.get_local_linear_id(); li < num_rows;
li += item_ct1.get_local_range().size()) {
z[li] = r[li];
}
}
};
55 changes: 55 additions & 0 deletions dpcpp/preconditioner/batch_preconditioners.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*******************************<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>*******************************/

#ifndef GKO_DPCPP_PRECONDITIONER_BATCH_PRECONDITIONERS_HPP_
#define GKO_DPCPP_PRECONDITIONER_BATCH_PRECONDITIONERS_HPP_


#include <ginkgo/core/matrix/batch_identity.hpp>


#include "core/matrix/batch_struct.hpp"


namespace gko {
namespace kernels {
namespace dpcpp {


#include "dpcpp/preconditioner/batch_identity.hpp.inc"


} // namespace dpcpp
} // namespace kernels
} // namespace gko

#endif // GKO_DPCPP_PRECONDITIONER_BATCH_PRECONDITIONERS_HPP_
59 changes: 59 additions & 0 deletions hip/preconditioner/batch_preconditioners.hip.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*******************************<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>*******************************/

#ifndef GKO_HIP_PRECONDITIONER_BATCH_PRECONDITIONERS_HIP_HPP_
#define GKO_HIP_PRECONDITIONER_BATCH_PRECONDITIONERS_HIP_HPP_


#include <ginkgo/core/matrix/batch_identity.hpp>


#include "core/matrix/batch_struct.hpp"
#include "hip/components/cooperative_groups.hip.hpp"
#include "hip/components/load_store.hip.hpp"
#include "hip/components/reduction.hip.hpp"


namespace gko {
namespace kernels {
namespace hip {


#include "common/cuda_hip/preconditioner/batch_identity.hpp.inc"


} // namespace hip
} // namespace kernels
} // namespace gko


#endif // GKO_HIP_PRECONDITIONER_BATCH_PRECONDITIONERS_HIP_HPP_
Loading

0 comments on commit ca38a9f

Please sign in to comment.