9#include "arccore/message_passing/ITypeDispatcher.h"
10#include "arccore/message_passing/Request.h"
11#include "arccore/message_passing/IStat.h"
12#include "arccore/message_passing_mpi/MessagePassingMpiGlobal.h"
13#include "arccore/message_passing_mpi/MpiDatatype.h"
15#include <alien/utils/Precomp.h>
17#include <arccore/base/NotImplementedException.h>
18#include <arccore/base/TraceInfo.h>
23#include "alien/kernels/sycl/data/SYCLEnv.h"
24#include "alien/kernels/sycl/data/SYCLEnvInternal.h"
26#include "alien/kernels/sycl/data/SYCLVectorInternal.h"
27#include "alien/kernels/sycl/data/SYCLVector.h"
29#include <alien/kernels/sycl/data/SYCLBEllPackInternal.h>
30#include <alien/kernels/sycl/data/SYCLBEllPackMatrix.h>
32#include "alien/kernels/sycl/algebra/SYCLKernelInternal.h"
33#include "alien/kernels/sycl/algebra/SYCLInternalLinearAlgebra.h"
35#include "alien/kernels/sycl/algebra/SYCLBEllPackMatrixMult.h"
42using namespace Arccore;
48SYCLInternalLinearAlgebraFactory()
54SYCLInternalLinearAlgebraExprFactory()
61namespace Internal = SYCLInternal;
65SYCLInternalLinearAlgebra::SYCLInternalLinearAlgebra()
68 m_internal.reset(
new SYCLInternal::KernelInternal());
73SYCLInternalLinearAlgebra::~SYCLInternalLinearAlgebra()
75#ifdef ALIEN_USE_PERF_TIMER
76 m_timer.printInfo(
"SYCL-ALGEBRA");
80void SYCLInternalLinearAlgebra::setDotAlgo(
int dot_algo)
82 m_internal->setDotAlgo(dot_algo);
87SYCLInternalLinearAlgebra::ResourceType
88SYCLInternalLinearAlgebra::resource(Matrix
const& A)
90 return std::make_tuple(&A.distribution().rowDistribution(),A.blockSize());
93void SYCLInternalLinearAlgebra::allocate(ResourceType resource, Vector& v)
95 v.init(*std::get<0>(resource),std::get<1>(resource),
true);
98void SYCLInternalLinearAlgebra::free(Vector& v)
103Real SYCLInternalLinearAlgebra::norm0(
const SYCLVector<Real>& vx ALIEN_UNUSED_PARAM)
const
106 throw NotImplementedException(
107 A_FUNCINFO,
"SYCLLinearAlgebra::norm0 not implemented");
112Real SYCLInternalLinearAlgebra::norm1(
const SYCLVector<Real>& vx ALIEN_UNUSED_PARAM)
const
115 throw NotImplementedException(
116 A_FUNCINFO,
"SYCLLinearAlgebra::norm1 not implemented");
120Real SYCLInternalLinearAlgebra::norm2(
const SYCLVector<Real>& vx)
const
122#ifdef ALIEN_USE_PERF_TIMER
123 SentryType s(m_timer,
"SYCL-NORM2");
125 return std::sqrt(m_internal->dot(vx.internal()->values(), vx.internal()->values()));
128Real SYCLInternalLinearAlgebra::normInf([[maybe_unused]]
const SYCLVector<Real>& vx)
const
130#ifdef ALIEN_USE_PERF_TIMER
131 SentryType s(m_timer,
"SYCL-NORMINF");
133 throw NotImplementedException(
134 A_FUNCINFO,
"SYCLLinearAlgebra::normInf not implemented");
138void SYCLInternalLinearAlgebra::mult(
const SYCLBEllPackMatrix<Real>& ma,
139 const SYCLVector<Real>& vx,
140 SYCLVector<Real>& vr)
const
142#ifdef ALIEN_USE_PERF_TIMER
143 SentryType s(m_timer,
"SYCL-SPMV");
145 Internal::SYCLBEllPackMatrixMultT<Real>(ma).mult(vx, vr);
148void SYCLInternalLinearAlgebra::addLMult(Real alpha,
149 const SYCLBEllPackMatrix<Real>& ma,
150 const SYCLVector<Real>& vx,
151 SYCLVector<Real>& vr)
const
153#ifdef ALIEN_USE_PERF_TIMER
154 SentryType s(m_timer,
"SYCL-ADDLMULT");
156 Internal::SYCLBEllPackMatrixMultT<Real>(ma).addLMult(alpha, vx, vr);
159void SYCLInternalLinearAlgebra::addUMult(Real alpha,
160 const SYCLBEllPackMatrix<Real>& ma,
161 const SYCLVector<Real>& vx,
162 SYCLVector<Real>& vr)
const
164#ifdef ALIEN_USE_PERF_TIMER
165 SentryType s(m_timer,
"SYCL-ADDUMULT");
167 Internal::SYCLBEllPackMatrixMultT<Real>(ma).addUMult(alpha, vx, vr);
170void SYCLInternalLinearAlgebra::
171multDiag(
const SYCLBEllPackMatrix<Real>& ma,
172 const SYCLVector<Real>& vy,
173 SYCLVector<Real>& vr)
const
175#ifdef ALIEN_USE_PERF_TIMER
176 SentryType s(m_timer,
"SYCL-MULTDIAG");
178 Internal::SYCLBEllPackMatrixMultT<Real>(ma).multDiag(vy,vr);
181void SYCLInternalLinearAlgebra::
182multDiag(
const SYCLVector<Real>& diag,
183 const SYCLVector<Real>& vy,
184 SYCLVector<Real>& vr)
const
186#ifdef ALIEN_USE_PERF_TIMER
187 SentryType s(m_timer,
"SYCL-MULTDIAG");
189 diag.pointWiseMult(vy,vr);
193void SYCLInternalLinearAlgebra::
194multInvDiag(
const SYCLBEllPackMatrix<Real>& ma,
195 SYCLVector<Real>& vr)
const
197#ifdef ALIEN_USE_PERF_TIMER
198 SentryType s(m_timer,
"SYCL-MULTINVDIAG");
200 Internal::SYCLBEllPackMatrixMultT<Real>(ma).multInvDiag(vr);
203void SYCLInternalLinearAlgebra::
204computeInvDiag(
const SYCLBEllPackMatrix<Real>& ma,
205 SYCLVector<Real>& vr)
const
207#ifdef ALIEN_USE_PERF_TIMER
208 SentryType s(m_timer,
"SYCL-INVDIAG");
210 Internal::SYCLBEllPackMatrixMultT<Real>(ma).computeInvDiag(vr);
215void SYCLInternalLinearAlgebra::axpy(Real alpha,
const SYCLVector<Real>& vx, SYCLVector<Real>& vr)
const
217#ifdef ALIEN_USE_PERF_TIMER
218 SentryType s(m_timer,
"SYCL-AXPY");
220 m_internal->axpy(alpha, vx.internal()->values(), vr.internal()->values());
225void SYCLInternalLinearAlgebra::aypx(Real alpha ALIEN_UNUSED_PARAM,
226 SYCLVector<Real>& y ALIEN_UNUSED_PARAM,
227 const SYCLVector<Real>& x ALIEN_UNUSED_PARAM)
const
229 throw NotImplementedException(
230 A_FUNCINFO,
"SYCLLinearAlgebra::aypx not implemented");
235void SYCLInternalLinearAlgebra::copy(
const SYCLVector<Real>& vx, SYCLVector<Real>& vr)
const
237#ifdef ALIEN_USE_PERF_TIMER
238 SentryType s(m_timer,
"SYCL-COPY");
240 m_internal->copy(vx.internal()->values(), vr.internal()->values());
244void SYCLInternalLinearAlgebra::axpy(Real alpha,
245 const SYCLVector<Real>& vx,
247 SYCLVector<Real>& vr,
248 Integer stride_r)
const
250#ifdef ALIEN_USE_PERF_TIMER
251 SentryType s(m_timer,
"SYCL-AXPY");
253 m_internal->axpy(alpha, vx.internal()->values(), stride_x, vr.internal()->values(), stride_r);
258void SYCLInternalLinearAlgebra::aypx(Real alpha ALIEN_UNUSED_PARAM,
259 SYCLVector<Real>& y ALIEN_UNUSED_PARAM,
260 Integer stride_y ALIEN_UNUSED_PARAM,
261 const SYCLVector<Real>& x ALIEN_UNUSED_PARAM,
262 Integer stride_x ALIEN_UNUSED_PARAM)
const
264 throw NotImplementedException(
265 A_FUNCINFO,
"SYCLLinearAlgebra::aypx not implemented");
270void SYCLInternalLinearAlgebra::copy(
const SYCLVector<Real>& vx,
272 SYCLVector<Real>& vr,
273 Integer stride_r)
const
275#ifdef ALIEN_USE_PERF_TIMER
276 SentryType s(m_timer,
"SYCL-COPY");
278 m_internal->copy(vx.internal()->values(), stride_x, vr.internal()->values(), stride_r);
283Real SYCLInternalLinearAlgebra::dot(
const SYCLVector<Real>& vx,
const SYCLVector<Real>& vy)
const
285#ifdef ALIEN_USE_PERF_TIMER
286 SentryType s(m_timer,
"SYCL-DOT");
288 auto value = m_internal->dot(vx.internal()->values(), vy.internal()->values());
289 auto& dist = vx.distribution();
290 if (dist.isParallel()) {
291 return Arccore::MessagePassing::mpAllReduce(dist.parallelMng(),
292 Arccore::MessagePassing::ReduceSum,
298void SYCLInternalLinearAlgebra::dot(
const SYCLVector<Real>& vx,
299 const SYCLVector<Real>& vy,
300 SYCLInternal::Future<Real>& res)
const
302#ifdef ALIEN_USE_PERF_TIMER
303 SentryType s(m_timer,
"SYCL-DOT-F");
305 m_internal->dot(vx.internal()->values(), vy.internal()->values(), res);
307 auto& dist = vx.distribution();
308 if (dist.isParallel()) {
310 Real local_value = res() ;
312 auto request = mpNonBlockingAllReduce(dist.parallelMng(),
313 Arccore::MessagePassing::ReduceSum,
314 Arccore::ConstArrayView<Real>(1,&local_value),
315 Arccore::ArrayView<Real>(1,x)) ;
316 res.addRequest(dist.parallelMng(), request);
322void SYCLInternalLinearAlgebra::scal(Real alpha, SYCLVector<Real>& vx)
const
324#ifdef ALIEN_USE_PERF_TIMER
325 SentryType s(m_timer,
"SYCL-SCAL");
327 return m_internal->scal(alpha, vx.internal()->values());
331void SYCLInternalLinearAlgebra::scal(SYCLVector<Real>
const& vx, SYCLBEllPackMatrix<Real>& ma)
const
333#ifdef ALIEN_USE_PERF_TIMER
334 SentryType s(m_timer,
"SYCL-SCAL");
339void SYCLInternalLinearAlgebra::pointwiseMult(
const SYCLVector<Real>& vx,
340 const SYCLVector<Real>& vy,
341 SYCLVector<Real>& vz)
const
343#ifdef ALIEN_USE_PERF_TIMER
344 SentryType s(m_timer,
"SYCL-XYZ");
346 return m_internal->pointwiseMult(vx.internal()->values(), vy.internal()->values(), vz.internal()->values());
349void SYCLInternalLinearAlgebra::assign(SYCLVector<Real>& vx, Real alpha)
const
351#ifdef ALIEN_USE_PERF_TIMER
352 SentryType s(m_timer,
"SYCL-ASSIGN");
354 return m_internal->assign(alpha, vx.internal()->values());
357void SYCLInternalLinearAlgebra::diagonal(
358const SYCLBEllPackMatrix<Real>& ma, SYCLVector<Real>& vx)
const
360#ifdef ALIEN_USE_PERF_TIMER
361 SentryType s(m_timer,
"SYCL-DIAG");
363 Internal::SYCLBEllPackMatrixMultT<Real>(ma).computeDiag(vx);
366void SYCLInternalLinearAlgebra::reciprocal(SYCLVector<Real>& x ALIEN_UNUSED_PARAM)
const
368 throw NotImplementedException(
369 A_FUNCINFO,
"SYCLLinearAlgebra::reciprocal not implemented");
373Integer SYCLInternalLinearAlgebra::computeCxr(
const Matrix& a, Matrix& cxr_a)
const
375 auto block_size = a.blockSize() ;
376 cxr_a.setBlockSize(1) ;
381Integer SYCLInternalLinearAlgebra::computeCxr(
const Matrix& a,
const Vector& diag, Matrix& cxr_a)
const
383 auto block_size = a.blockSize() ;
384 cxr_a.setBlockSize(1) ;
393SYCLInternalLinearAlgebraExpr::SYCLInternalLinearAlgebraExpr()
394: IInternalLinearAlgebraExpr<SYCLBEllPackMatrix<Real>, SYCLVector<Real>>()
396 m_internal.reset(
new SYCLInternal::KernelInternal());
401SYCLInternalLinearAlgebraExpr::~SYCLInternalLinearAlgebraExpr() {}
406Real SYCLInternalLinearAlgebraExpr::norm0(
const SYCLVector<Real>& vx ALIEN_UNUSED_PARAM)
const
409 throw NotImplementedException(
410 A_FUNCINFO,
"SYCLLinearAlgebra::norm0 not implemented");
415Real SYCLInternalLinearAlgebraExpr::norm1(
const SYCLVector<Real>& vx ALIEN_UNUSED_PARAM)
const
418 throw NotImplementedException(
419 A_FUNCINFO,
"SYCLLinearAlgebra::norm1 not implemented");
424Real SYCLInternalLinearAlgebraExpr::norm2(
const SYCLVector<Real>& vx)
const
426 return std::sqrt(m_internal->dot(vx.internal()->values(), vx.internal()->values()));
429Real SYCLInternalLinearAlgebraExpr::normInf([[maybe_unused]]
const SYCLVector<Real>& vx)
const
431#ifdef ALIEN_USE_PERF_TIMER
432 SentryType s(m_timer,
"SYCL-NORMINF");
434 throw NotImplementedException(
435 A_FUNCINFO,
"SYCLLinearAlgebra::normInf not implemented");
439void SYCLInternalLinearAlgebraExpr::mult(
440const SYCLBEllPackMatrix<Real>& ma,
const SYCLVector<Real>& vx, SYCLVector<Real>& vr)
const
442 Internal::SYCLBEllPackMatrixMultT<Real>(ma).mult(vx, vr);
445void SYCLInternalLinearAlgebraExpr::mult(
446const SYCLBEllPackMatrix<Real>& ma,
const UniqueArray<Real>& vx, UniqueArray<Real>& vr)
const
448 Internal::SYCLBEllPackMatrixMultT<Real>(ma).mult(vx, vr);
453void SYCLInternalLinearAlgebraExpr::axpy([[maybe_unused]] Real alpha,
454 [[maybe_unused]]
const UniqueArray<Real>& vx,
455 [[maybe_unused]] UniqueArray<Real>& vr)
const
457 throw NotImplementedException(
458 A_FUNCINFO,
"SYCLLinearAlgebra::axpy not implemented");
461void SYCLInternalLinearAlgebraExpr::axpy(Real alpha,
const SYCLVector<Real>& vx, SYCLVector<Real>& vy)
const
463 m_internal->axpy(alpha, vx.internal()->values(), vy.internal()->values());
468void SYCLInternalLinearAlgebraExpr::aypx([[maybe_unused]] Real alpha, [[maybe_unused]] UniqueArray<Real>& vy, [[maybe_unused]] UniqueArray<Real>
const& vx)
const
470 throw NotImplementedException(
471 A_FUNCINFO,
"SYCLLinearAlgebra::aypx not implemented");
474void SYCLInternalLinearAlgebraExpr::aypx(Real alpha ALIEN_UNUSED_PARAM,
475 SYCLVector<Real>& y ALIEN_UNUSED_PARAM,
const SYCLVector<Real>& x ALIEN_UNUSED_PARAM)
const
477 throw NotImplementedException(
478 A_FUNCINFO,
"SYCLLinearAlgebra::aypx not implemented");
483void SYCLInternalLinearAlgebraExpr::copy([[maybe_unused]]
const UniqueArray<Real>& vx,
484 [[maybe_unused]] UniqueArray<Real>& vr)
const
486 throw NotImplementedException(
487 A_FUNCINFO,
"SYCLLinearAlgebra::copy not implemented");
490void SYCLInternalLinearAlgebraExpr::copy(
const SYCLVector<Real>& vx, SYCLVector<Real>& vy)
const
492 m_internal->copy(vx.internal()->values(), vy.internal()->values());
497Real SYCLInternalLinearAlgebraExpr::dot([[maybe_unused]]
498Integer local_size, [[maybe_unused]]
const UniqueArray<Real>& vx, [[maybe_unused]]
const UniqueArray<Real>& vy)
const
500 throw NotImplementedException(
501 A_FUNCINFO,
"SYCLLinearAlgebra::dot not implemented");
504Real SYCLInternalLinearAlgebraExpr::dot(
const SYCLVector<Real>& vx,
const SYCLVector<Real>& vy)
const
506 return m_internal->dot(vx.internal()->values(), vy.internal()->values());
509Real SYCLInternalLinearAlgebraExpr::norm2([[maybe_unused]]
const SYCLBEllPackMatrix<Real>& a)
const
511 throw NotImplementedException(
512 A_FUNCINFO,
"SYCLLinearAlgebra::notm2 not implemented");
515void SYCLInternalLinearAlgebraExpr::copy([[maybe_unused]]
const SYCLBEllPackMatrix<Real>& a, [[maybe_unused]] SYCLBEllPackMatrix<Real>& r)
const
517 throw NotImplementedException(
518 A_FUNCINFO,
"SYCLLinearAlgebra::copy not implemented");
521void SYCLInternalLinearAlgebraExpr::add([[maybe_unused]]
const SYCLBEllPackMatrix<Real>& a, [[maybe_unused]] SYCLBEllPackMatrix<Real>& r)
const
523 throw NotImplementedException(
524 A_FUNCINFO,
"SYCLLinearAlgebra::add not implemented");
527void SYCLInternalLinearAlgebraExpr::scal([[maybe_unused]] Real alpha, [[maybe_unused]] SYCLBEllPackMatrix<Real>& a)
const
529 throw NotImplementedException(
530 A_FUNCINFO,
"SYCLLinearAlgebra::scal not implemented");
533void SYCLInternalLinearAlgebraExpr::scal(Real alpha ALIEN_UNUSED_PARAM, UniqueArray<Real>& x ALIEN_UNUSED_PARAM)
const
535 throw NotImplementedException(
536 A_FUNCINFO,
"SYCLLinearAlgebra::scal not implemented");
539void SYCLInternalLinearAlgebraExpr::scal(Real alpha ALIEN_UNUSED_PARAM, SYCLVector<Real>& x ALIEN_UNUSED_PARAM)
const
541 throw NotImplementedException(
542 A_FUNCINFO,
"SYCLLinearAlgebra::aypx not implemented");
545void SYCLInternalLinearAlgebraExpr::diagonal(
546const SYCLBEllPackMatrix<Real>& a ALIEN_UNUSED_PARAM, SYCLVector<Real>& x ALIEN_UNUSED_PARAM)
const
548 throw NotImplementedException(
549 A_FUNCINFO,
"SYCLLinearAlgebra::aypx not implemented");
552void SYCLInternalLinearAlgebraExpr::reciprocal(SYCLVector<Real>& x ALIEN_UNUSED_PARAM)
const
554 throw NotImplementedException(
555 A_FUNCINFO,
"SYCLLinearAlgebra::aypx not implemented");
558void SYCLInternalLinearAlgebraExpr::pointwiseMult(
const SYCLVector<Real>& x ALIEN_UNUSED_PARAM,
559 const SYCLVector<Real>& y ALIEN_UNUSED_PARAM, SYCLVector<Real>& w ALIEN_UNUSED_PARAM)
const
561 throw NotImplementedException(
562 A_FUNCINFO,
"SYCLLinearAlgebra::aypx not implemented");
565template class ALIEN_EXPORT SYCLInternal::Future<double>;
567namespace SYCLInternal
570sycl::buffer<double>& KernelInternal::getWorkBuffer(std::size_t size)
572 if (m_double_work ==
nullptr) {
573 m_double_work =
new sycl::buffer<double>(size);
574 m_double_work->set_final_data(
nullptr);
577 if (size > m_double_work->size()) {
578 delete m_double_work;
579 m_double_work =
new sycl::buffer<double>(size);
580 m_double_work->set_final_data(
nullptr);
583 return *m_double_work;
Internal linear algebra interface.
Internal linear algebra interface.
Linear algebra interface.
Linear algebra interface.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --