Alien  1.3.0
User documentation
Loading...
Searching...
No Matches
SYCLBEllPackMatrix.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 * Copyright 2020 IFPEN-CEA
9 *
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 *
22 * SPDX-License-Identifier: Apache-2.0
23 */
24/*
25 * BEllPackMatrix.h
26 *
27 * Created on: Nov 20, 2021
28 * Author: gratienj
29 */
30
31#pragma once
32
35
36#include <alien/data/ISpace.h>
37
38#include <alien/kernels/sycl/SYCLPrecomp.h>
39
40#include <alien/handlers/accelerator/HCSRViewT.h>
41
42#include <alien/kernels/sycl/data/BEllPackStructInfo.h>
43#include <alien/kernels/sycl/data/SYCLDistStructInfo.h>
44
45#include <alien/kernels/sycl/SYCLBackEnd.h>
46
47#include <alien/utils/StdTimer.h>
48
49namespace Alien::SYCLInternal
50{
51template <typename ValueT>
53
54template <typename ValueT, int BlockSize>
55class MatrixInternal;
56} // namespace Alien::SYCLInternal
57
58/*---------------------------------------------------------------------------*/
59
60namespace Alien
61{
62
63/*---------------------------------------------------------------------------*/
64
65template <int BlockSize, typename IndexT>
67
68template <typename ValueT>
69class SYCLVector;
70
71template <typename ValueT>
72class ALIEN_EXPORT SYCLBEllPackMatrix : public IMatrixImpl
73{
74 public:
75 // clang-format off
76 static constexpr bool on_host_only = false ;
77 //static constexpr int PKSIZE = 256 ;
78 typedef BackEnd::tag::sycl TagType ;
79 typedef ValueT ValueType;
80 typedef ValueT value_type ;
81
82 typedef SYCLInternal::SYCLDistStructInfo DistStructInfo;
83 typedef SYCLInternal::MatrixInternal<ValueType,PKSIZE> MatrixInternalType;
84
85
86 typedef BEllPackStructInfo<PKSIZE,int> ProfileInternalType;
87 typedef BEllPackStructInfo<PKSIZE,int> ProfileType;
88 typedef typename ProfileType::IndexType IndexType ;
89
90 typedef Alien::StdTimer TimerType ;
91 typedef TimerType::Sentry SentryType ;
92
93
95 // clang-format on
96
97 public:
98 /** Constructeur de la classe */
100
101 /** Constructeur de la classe */
103
104 /** Destructeur de la classe */
106
107 void setTraceMng(ITraceMng* trace_mng) { m_trace = trace_mng; }
108
109 ProfileType const& getProfile() const
110 {
111 return *m_profilePKSIZE;
112 }
113
114 HCSRView hcsrView(BackEnd::Memory::eType memory, int nrows, int nnz) const;
115
116 ValueType* getAddressData();
117 ValueType* data();
118
119 ValueType const* getAddressData() const;
120 ValueType const* data() const;
121
122 IMessagePassingMng* getParallelMng()
123 {
124 return m_parallel_mng;
125 }
126
127 public:
128 bool initMatrix(Arccore::MessagePassing::IMessagePassingMng* parallel_mng,
129 Integer local_offset,
130 Integer global_size,
131 std::size_t nrows,
132 int const* kcol,
133 int const* cols,
134 SimpleCSRInternal::DistStructInfo const& matrix_dist_info,
135 int block_size=1);
136
137 SYCLBEllPackMatrix* cloneTo(const MultiMatrixImpl* multi) const;
138
139 bool isParallel() const { return m_is_parallel; }
140
141 Integer getLocalSize() const { return m_local_size; }
142
143 Integer getLocalOffset() const { return m_local_offset; }
144
145 Integer getGlobalSize() const { return m_global_size; }
146
147 Integer getGhostSize() const { return m_ghost_size; }
148
149 Integer getAllocSize() const { return m_local_size + m_ghost_size; }
150
151 Integer blockSize() const
152 {
153 if (block())
154 {
155 return block()->size();
156 }
157 else if (vblock()) {
158 return 1 ;
159 }
160 else {
161 return m_own_block_size ;
162 }
163 }
164
165 void setBlockSize(Integer block_size)
166 {
167 if(this->m_multi_impl)
168 const_cast<MultiMatrixImpl*>(this->m_multi_impl)->setBlockInfos(block_size) ;
169 else
170 m_own_block_size = block_size;
171 }
172
173 bool setMatrixValues(Arccore::Real const* values, bool only_host);
174
175 void copy(SYCLBEllPackMatrix const& matrix) ;
176
177 void notifyChanges();
178 void endUpdate();
179
180 void mult(SYCLVector<ValueType> const& x, SYCLVector<ValueType>& y) const;
181 void endDistMult(SYCLVector<ValueType> const& x, SYCLVector<ValueType>& y) const;
182
183 void addLMult(ValueType alpha, SYCLVector<ValueType> const& x, SYCLVector<ValueType>& y) const;
184 void addUMult(ValueType alpha, SYCLVector<ValueType> const& x, SYCLVector<ValueType>& y) const;
185
186 void multDiag(SYCLVector<ValueType> const& x, SYCLVector<ValueType>& y) const;
187
188 void multDiag(SYCLVector<ValueType>& y) const ;
189 void computeDiag(SYCLVector<ValueType>& y) const;
190
191 void multInvDiag(SYCLVector<ValueType>& y) const;
192 void computeInvDiag(SYCLVector<ValueType>& y) const;
193
194 void scal(SYCLVector<ValueType> const& diag) ;
195
196 const DistStructInfo& getDistStructInfo() const { return m_matrix_dist_info; }
197
198 Alien::SimpleCSRInternal::CommProperty::ePolicyType getSendPolicy() const
199 {
200 return m_send_policy;
201 }
202
203 Alien::SimpleCSRInternal::CommProperty::ePolicyType getRecvPolicy() const
204 {
205 return m_recv_policy;
206 }
207
208 MatrixInternalType* internal() { return m_matrixPKSIZE.get(); }
209
210 MatrixInternalType const* internal() const { return m_matrixPKSIZE.get(); }
211
212 void allocateDevicePointers(std::size_t nrows,
213 std::size_t nnz,
214 IndexType** rows,
215 IndexType** ncols,
216 IndexType** cols,
217 ValueType** values) const ;
218
219 void freeDevicePointers(IndexType* rows,
220 IndexType* ncols,
221 IndexType* cols,
222 ValueType* values) const ;
223
224 void copyDevicePointers(std::size_t nrows,
225 std::size_t nnz,
226 IndexType* rows,
227 IndexType* ncols,
228 IndexType* cols,
229 ValueType* values) const ;
230
231
232 private:
233 class IsLocal
234 {
235 public:
236 IsLocal(const ConstArrayView<Integer> offset, const Integer myrank)
237 : m_offset(offset)
238 , m_myrank(myrank)
239 {}
240 bool operator()(Arccore::Integer col) const
241 {
242 return (col >= m_offset[m_myrank]) && (col < m_offset[m_myrank + 1]);
243 }
244
245 private:
246 const ConstArrayView<Integer> m_offset;
247 const Integer m_myrank;
248 };
249
250 // clang-format off
251 std::unique_ptr<ProfileInternalType> m_profilePKSIZE;
252 std::unique_ptr<MatrixInternalType> m_matrixPKSIZE;
253
254 std::unique_ptr<ProfileInternalType> m_ext_profilePKSIZE;
255
256 int m_ellpack_size = PKSIZE ;
257 std::vector<int> m_block_row_offset ;
258 std::vector<int> m_ext_block_row_offset ;
259
260 Integer m_own_block_size = 1 ;
261
262 bool m_is_parallel = false;
263 IMessagePassingMng* m_parallel_mng = nullptr;
264 Integer m_nproc = 1;
265 Integer m_myrank = 0;
266
267 Integer m_local_size = 0;
268 Integer m_local_offset = 0;
269 Integer m_global_size = 0;
270 Integer m_ghost_size = 0;
271
272
273 //SimpleCSRInternal::DistStructInfo m_matrix_dist_info;
274 DistStructInfo m_matrix_dist_info;
275 SimpleCSRInternal::CommProperty::ePolicyType m_send_policy;
276 SimpleCSRInternal::CommProperty::ePolicyType m_recv_policy;
277 ITraceMng* m_trace = nullptr;
278 // clang-format on
279
280 // From unsuccessful try to implement multiplication.
281 friend class SYCLInternal::SYCLBEllPackMatrixMultT<ValueType>;
282
283#ifdef ALIEN_USE_PERF_TIMER
284 private:
285 mutable TimerType m_timer;
286
287 public:
288 TimerType& timer() const
289 {
290 return m_timer;
291 }
292#endif
293};
294
295//extern template class SYCLBEllPackMatrix<double>;
296} // namespace Alien
IMatrixImpl.h.
ISpace.h.
MultiMatrixImpl.h.
IMatrixImpl(const MultiMatrixImpl *multi_impl, BackEndId backend="")
Constructor.
Multi matrices representation container.
SYCLBEllPackMatrix(const MultiMatrixImpl *multi_impl)
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Definition BackEnd.h:17