Alien  1.3.0
User documentation
Loading...
Searching...
No Matches
SYCLInternalLinearAlgebra.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7
8#pragma once
9
10#include <tuple>
11
12#include <alien/utils/Precomp.h>
13
15#include <alien/core/backend/IInternalLinearAlgebraT.h>
16#include <alien/kernels/sycl/SYCLBackEnd.h>
17
18#include <alien/utils/ExceptionUtils.h>
19
20#include <alien/utils/StdTimer.h>
21/*---------------------------------------------------------------------------*/
22
23namespace Alien
24{
25namespace SYCLInternal
26{
27
28 template <typename T>
29 class Future;
30
31 class KernelInternal;
32} // namespace SYCLInternal
33
36
37class ALIEN_EXPORT SYCLInternalLinearAlgebra
38: public IInternalLinearAlgebra<SYCLMatrixType, SYCLVectorType>
39{
40 public:
41 typedef BackEnd::tag::sycl BackEndType;
42
43 //typedef VectorDistribution ResourceType;
44 typedef std::tuple<VectorDistribution const*,Integer> ResourceType;
45
46 class NullValueException
48 {
49 public:
50 typedef Exception::NumericException BaseType;
51 NullValueException(std::string const& type)
52 : BaseType(type, __LINE__)
53 {}
54 };
55
56 // clang-format off
57 typedef SYCLInternal::Future<Real> FutureType ;
58
59 typedef Alien::StdTimer TimerType ;
60 typedef TimerType::Sentry SentryType ;
61 // clang-format on
62
63 SYCLInternalLinearAlgebra();
64 virtual ~SYCLInternalLinearAlgebra();
65
66 void setDotAlgo(int dot_algo);
67
68 public:
69 // IInternalLinearAlgebra interface.
70 Real norm0(const Vector& x) const;
71 Real norm1(const Vector& x) const;
72 Real norm2(const Vector& x) const;
73 Real normInf(const Vector& x) const;
74
75 void mult(const Matrix& a, const Vector& x, Vector& r) const;
76 void addLMult(Real alpha, const Matrix& A, const Vector& x, Vector& y) const;
77 void addUMult(Real alpha, const Matrix& A, const Vector& x, Vector& y) const;
78
79 void lowerUpperSynchronize(const Matrix& A, Vector& y) const;
80 void upperLowerSynchronize(const Matrix& A, Vector& y) const;
81
82 void multDiag(const Matrix& A, Vector const& y, Vector& z) const;
83 void multDiag(const Vector& diag, Vector const& y, Vector& z) const;
84
85 void multInvDiag(const Matrix& A, Vector& y) const;
86 void computeInvDiag(const Matrix& a, Vector& inv_diag) const;
87
88 void axpy(Real alpha, const Vector& x, Vector& r) const;
89 void aypx(Real alpha, Vector& y, const Vector& x) const;
90 void copy(const Vector& x, Vector& r) const;
91
92 void axpy(Real alpha, const Vector& x, Integer stride_x, Vector& r, Integer stride_r) const;
93 void aypx(Real alpha, Vector& y, Integer stride_y, const Vector& x, Integer stride_x) const;
94 void copy(const Vector& x, Integer stride_x, Vector& r, Integer stride_r) const;
95
96 Real dot(const Vector& x, const Vector& y) const;
97 void dot(const Vector& x, const Vector& y, SYCLInternal::Future<Real>& res) const;
98
99 void scal(Real alpha, Vector& x) const;
100 void scal(const Vector& x, Matrix& a) const;
101 void diagonal(const Matrix& a, Vector& x) const;
102 void reciprocal(Vector& x) const;
103 void pointwiseMult(const Vector& x, const Vector& y, Vector& w) const;
104
105 void assign(Vector& x, Real alpha) const;
106
107 template <typename LambdaT>
108 void assign(Vector& x, LambdaT const& lambda) const
109 {
110 x.apply(lambda);
111 //m_internal->apply(lambda,x) ;
112 }
113
114 template <typename PrecondT>
115 void exec(PrecondT& precond, Vector const& x, Vector& y)
116 {
117 return precond.solve(*this, x, y);
118 }
119
120 Integer computeCxr(const Matrix& a, Matrix& cxr_a) const ;
121 Integer computeCxr(const Matrix& a, Vector const& diag_scal, Matrix& cxr_a) const ;
122
123 static ResourceType resource(Matrix const& A);
124
125 void allocate(ResourceType resource, Vector& v);
126
127 template <typename T0, typename... T>
128 void allocate(ResourceType resource, T0& v0, T&... args)
129 {
130 allocate(resource, v0);
131 allocate(resource, args...);
132 }
133
134 void free(Vector& v);
135
136 template <typename T0, typename... T>
137 void free(T0& v0, T&... args)
138 {
139 free(v0);
140 free(args...);
141 }
142
143 private:
144 std::unique_ptr<SYCLInternal::KernelInternal> m_internal;
145#ifdef ALIEN_USE_PERF_TIMER
146 mutable TimerType m_timer;
147#endif
148};
149
150class SYCLInternalLinearAlgebraExpr
151: public IInternalLinearAlgebraExpr<SYCLMatrixType, SYCLVectorType>
152{
153 public:
154 SYCLInternalLinearAlgebraExpr();
155 virtual ~SYCLInternalLinearAlgebraExpr();
156
157 public:
158 // IInternalLinearAlgebra interface.
159 Real norm0(const Vector& x) const;
160 Real norm1(const Vector& x) const;
161 Real norm2(const Vector& x) const;
162 Real normInf(const Vector& x) const;
163 void mult(const Matrix& a, const Vector& x, Vector& r) const;
164 void axpy(Real alpha, const Vector& x, Vector& r) const;
165 void aypx(Real alpha, Vector& y, const Vector& x) const;
166 void copy(const Vector& x, Vector& r) const;
167 Real dot(const Vector& x, const Vector& y) const;
168 void scal(Real alpha, Vector& x) const;
169 void diagonal(const Matrix& a, Vector& x) const;
170 void reciprocal(Vector& x) const;
171 void pointwiseMult(const Vector& x, const Vector& y, Vector& w) const;
172
173 Real norm2(const Matrix& x) const;
174 void copy(const Matrix& a, Matrix& r) const;
175 void add(const Matrix& a, Matrix& r) const;
176 void scal(Real alpha, Matrix& a) const;
177
178 // IInternalLinearAlgebra interface.
179
180 void mult(const Matrix& a, const UniqueArray<Real>& x, UniqueArray<Real>& r) const;
181 void axpy(Real alpha, UniqueArray<Real> const& x, UniqueArray<Real>& r) const;
182 void aypx(Real alpha, UniqueArray<Real>& y, UniqueArray<Real> const& x) const;
183 void copy(const UniqueArray<Real>& x, UniqueArray<Real>& r) const;
184 Real dot(Integer local_size, const UniqueArray<Real>& x, const UniqueArray<Real>& y) const;
185
186 void scal(Real alpha, UniqueArray<Real>& x) const;
187
188
189 private:
190 std::unique_ptr<SYCLInternal::KernelInternal> m_internal;
191};
192
193} // namespace Alien
194
195/*---------------------------------------------------------------------------*/
IInternalLinearAlgebraExprT.h.
Internal linear algebra interface.
Internal linear algebra interface.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Definition BackEnd.h:17