Alien  1.3.0
Developer 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 multDiag(const Matrix& A, Vector const& y, Vector& z) const;
80 void multDiag(const Vector& diag, Vector const& y, Vector& z) const;
81
82 void multInvDiag(const Matrix& A, Vector& y) const;
83 void computeInvDiag(const Matrix& a, Vector& inv_diag) const;
84
85 void axpy(Real alpha, const Vector& x, Vector& r) const;
86 void aypx(Real alpha, Vector& y, const Vector& x) const;
87 void copy(const Vector& x, Vector& r) const;
88
89 void axpy(Real alpha, const Vector& x, Integer stride_x, Vector& r, Integer stride_r) const;
90 void aypx(Real alpha, Vector& y, Integer stride_y, const Vector& x, Integer stride_x) const;
91 void copy(const Vector& x, Integer stride_x, Vector& r, Integer stride_r) const;
92
93 Real dot(const Vector& x, const Vector& y) const;
94 void dot(const Vector& x, const Vector& y, SYCLInternal::Future<Real>& res) const;
95
96 void scal(Real alpha, Vector& x) const;
97 void scal(const Vector& x, Matrix& a) const;
98 void diagonal(const Matrix& a, Vector& x) const;
99 void reciprocal(Vector& x) const;
100 void pointwiseMult(const Vector& x, const Vector& y, Vector& w) const;
101
102 void assign(Vector& x, Real alpha) const;
103
104 template <typename LambdaT>
105 void assign(Vector& x, LambdaT const& lambda) const
106 {
107 x.apply(lambda);
108 //m_internal->apply(lambda,x) ;
109 }
110
111 template <typename PrecondT>
112 void exec(PrecondT& precond, Vector const& x, Vector& y)
113 {
114 return precond.solve(*this, x, y);
115 }
116
117 Integer computeCxr(const Matrix& a, Matrix& cxr_a) const ;
118 Integer computeCxr(const Matrix& a, Vector const& diag_scal, Matrix& cxr_a) const ;
119
120 static ResourceType resource(Matrix const& A);
121
122 void allocate(ResourceType resource, Vector& v);
123
124 template <typename T0, typename... T>
125 void allocate(ResourceType resource, T0& v0, T&... args)
126 {
127 allocate(resource, v0);
128 allocate(resource, args...);
129 }
130
131 void free(Vector& v);
132
133 template <typename T0, typename... T>
134 void free(T0& v0, T&... args)
135 {
136 free(v0);
137 free(args...);
138 }
139
140 private:
141 std::unique_ptr<SYCLInternal::KernelInternal> m_internal;
142#ifdef ALIEN_USE_PERF_TIMER
143 mutable TimerType m_timer;
144#endif
145};
146
147class SYCLInternalLinearAlgebraExpr
148: public IInternalLinearAlgebraExpr<SYCLMatrixType, SYCLVectorType>
149{
150 public:
151 SYCLInternalLinearAlgebraExpr();
152 virtual ~SYCLInternalLinearAlgebraExpr();
153
154 public:
155 // IInternalLinearAlgebra interface.
156 Real norm0(const Vector& x) const;
157 Real norm1(const Vector& x) const;
158 Real norm2(const Vector& x) const;
159 Real normInf(const Vector& x) const;
160 void mult(const Matrix& a, const Vector& x, Vector& r) const;
161 void axpy(Real alpha, const Vector& x, Vector& r) const;
162 void aypx(Real alpha, Vector& y, const Vector& x) const;
163 void copy(const Vector& x, Vector& r) const;
164 Real dot(const Vector& x, const Vector& y) const;
165 void scal(Real alpha, Vector& x) const;
166 void diagonal(const Matrix& a, Vector& x) const;
167 void reciprocal(Vector& x) const;
168 void pointwiseMult(const Vector& x, const Vector& y, Vector& w) const;
169
170 Real norm2(const Matrix& x) const;
171 void copy(const Matrix& a, Matrix& r) const;
172 void add(const Matrix& a, Matrix& r) const;
173 void scal(Real alpha, Matrix& a) const;
174
175 // IInternalLinearAlgebra interface.
176
177 void mult(const Matrix& a, const UniqueArray<Real>& x, UniqueArray<Real>& r) const;
178 void axpy(Real alpha, UniqueArray<Real> const& x, UniqueArray<Real>& r) const;
179 void aypx(Real alpha, UniqueArray<Real>& y, UniqueArray<Real> const& x) const;
180 void copy(const UniqueArray<Real>& x, UniqueArray<Real>& r) const;
181 Real dot(Integer local_size, const UniqueArray<Real>& x, const UniqueArray<Real>& y) const;
182
183 void scal(Real alpha, UniqueArray<Real>& x) const;
184
185
186 private:
187 std::unique_ptr<SYCLInternal::KernelInternal> m_internal;
188};
189
190} // namespace Alien
191
192/*---------------------------------------------------------------------------*/
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