9#include "arccore/message_passing/ITypeDispatcher.h"
10#include "arccore/message_passing/Request.h"
11#include "arccore/message_passing/IStat.h"
13#include <alien/utils/Precomp.h>
15#include <arccore/base/NotImplementedException.h>
16#include <arccore/base/TraceInfo.h>
21#include "alien/kernels/sycl/data/SYCLEnv.h"
22#include "alien/kernels/sycl/data/SYCLEnvInternal.h"
24#include "alien/kernels/sycl/data/SYCLVectorInternal.h"
25#include "alien/kernels/sycl/data/SYCLVector.h"
27#include <alien/kernels/sycl/data/SYCLBEllPackInternal.h>
28#include <alien/kernels/sycl/data/SYCLBEllPackMatrix.h>
30#include "alien/kernels/sycl/algebra/SYCLKernelInternal.h"
31#include "alien/kernels/sycl/algebra/SYCLInternalLinearAlgebra.h"
33#include "alien/kernels/sycl/algebra/SYCLBEllPackMatrixMult.h"
40using namespace Arccore;
46SYCLInternalLinearAlgebraFactory()
52SYCLInternalLinearAlgebraExprFactory()
59namespace Internal = SYCLInternal;
63SYCLInternalLinearAlgebra::SYCLInternalLinearAlgebra()
66 m_internal.reset(
new SYCLInternal::KernelInternal());
71SYCLInternalLinearAlgebra::~SYCLInternalLinearAlgebra()
73#ifdef ALIEN_USE_PERF_TIMER
74 m_timer.printInfo(
"SYCL-ALGEBRA");
78void SYCLInternalLinearAlgebra::setDotAlgo(
int dot_algo)
80 m_internal->setDotAlgo(dot_algo);
85SYCLInternalLinearAlgebra::ResourceType
86SYCLInternalLinearAlgebra::resource(Matrix
const& A)
88 return std::make_tuple(&A.distribution().rowDistribution(),A.blockSize());
91void SYCLInternalLinearAlgebra::allocate(ResourceType resource, Vector& v)
93 v.init(*std::get<0>(resource),std::get<1>(resource),
true);
96void SYCLInternalLinearAlgebra::free(Vector& v)
101Real SYCLInternalLinearAlgebra::norm0(
const SYCLVector<Real>& vx ALIEN_UNUSED_PARAM)
const
104 throw NotImplementedException(
105 A_FUNCINFO,
"SYCLLinearAlgebra::norm0 not implemented");
110Real SYCLInternalLinearAlgebra::norm1(
const SYCLVector<Real>& vx ALIEN_UNUSED_PARAM)
const
113 throw NotImplementedException(
114 A_FUNCINFO,
"SYCLLinearAlgebra::norm1 not implemented");
118Real SYCLInternalLinearAlgebra::norm2(
const SYCLVector<Real>& vx)
const
120#ifdef ALIEN_USE_PERF_TIMER
121 SentryType s(m_timer,
"SYCL-NORM2");
123 return std::sqrt(m_internal->dot(vx.internal()->values(), vx.internal()->values()));
126Real SYCLInternalLinearAlgebra::normInf([[maybe_unused]]
const SYCLVector<Real>& vx)
const
128#ifdef ALIEN_USE_PERF_TIMER
129 SentryType s(m_timer,
"SYCL-NORMINF");
131 throw NotImplementedException(
132 A_FUNCINFO,
"SYCLLinearAlgebra::normInf not implemented");
136void SYCLInternalLinearAlgebra::mult(
const SYCLBEllPackMatrix<Real>& ma,
137 const SYCLVector<Real>& vx,
138 SYCLVector<Real>& vr)
const
140#ifdef ALIEN_USE_PERF_TIMER
141 SentryType s(m_timer,
"SYCL-SPMV");
143 Internal::SYCLBEllPackMatrixMultT<Real>(ma).mult(vx, vr);
146void SYCLInternalLinearAlgebra::addLMult(Real alpha,
147 const SYCLBEllPackMatrix<Real>& ma,
148 const SYCLVector<Real>& vx,
149 SYCLVector<Real>& vr)
const
151#ifdef ALIEN_USE_PERF_TIMER
152 SentryType s(m_timer,
"SYCL-ADDLMULT");
154 Internal::SYCLBEllPackMatrixMultT<Real>(ma).addLMult(alpha, vx, vr);
157void SYCLInternalLinearAlgebra::addUMult(Real alpha,
158 const SYCLBEllPackMatrix<Real>& ma,
159 const SYCLVector<Real>& vx,
160 SYCLVector<Real>& vr)
const
162#ifdef ALIEN_USE_PERF_TIMER
163 SentryType s(m_timer,
"SYCL-ADDUMULT");
165 Internal::SYCLBEllPackMatrixMultT<Real>(ma).addUMult(alpha, vx, vr);
168void SYCLInternalLinearAlgebra::lowerUpperSynchronize(
const SYCLBEllPackMatrix<Real>& ma,
169 SYCLVector<Real>& vr)
const
171#ifdef ALIEN_USE_PERF_TIMER
172 SentryType s(m_timer,
"SYCL-luSynchronize");
174 Internal::SYCLBEllPackMatrixMultT<Real>(ma).lowerUpperSynchronize(vr, vr);
177void SYCLInternalLinearAlgebra::upperLowerSynchronize(
const SYCLBEllPackMatrix<Real>& ma,
178 SYCLVector<Real>& vr)
const
180#ifdef ALIEN_USE_PERF_TIMER
181 SentryType s(m_timer,
"SYCL-ulSynchronize");
183 Internal::SYCLBEllPackMatrixMultT<Real>(ma).upperLowerSynchronize(vr, vr);
186void SYCLInternalLinearAlgebra::
187multDiag(
const SYCLBEllPackMatrix<Real>& ma,
188 const SYCLVector<Real>& vy,
189 SYCLVector<Real>& vr)
const
191#ifdef ALIEN_USE_PERF_TIMER
192 SentryType s(m_timer,
"SYCL-MULTDIAG");
194 Internal::SYCLBEllPackMatrixMultT<Real>(ma).multDiag(vy,vr);
197void SYCLInternalLinearAlgebra::
198multDiag(
const SYCLVector<Real>& diag,
199 const SYCLVector<Real>& vy,
200 SYCLVector<Real>& vr)
const
202#ifdef ALIEN_USE_PERF_TIMER
203 SentryType s(m_timer,
"SYCL-MULTDIAG");
205 diag.pointWiseMult(vy,vr);
209void SYCLInternalLinearAlgebra::
210multInvDiag(
const SYCLBEllPackMatrix<Real>& ma,
211 SYCLVector<Real>& vr)
const
213#ifdef ALIEN_USE_PERF_TIMER
214 SentryType s(m_timer,
"SYCL-MULTINVDIAG");
216 Internal::SYCLBEllPackMatrixMultT<Real>(ma).multInvDiag(vr);
219void SYCLInternalLinearAlgebra::
220computeInvDiag(
const SYCLBEllPackMatrix<Real>& ma,
221 SYCLVector<Real>& vr)
const
223#ifdef ALIEN_USE_PERF_TIMER
224 SentryType s(m_timer,
"SYCL-INVDIAG");
226 Internal::SYCLBEllPackMatrixMultT<Real>(ma).computeInvDiag(vr);
231void SYCLInternalLinearAlgebra::axpy(Real alpha,
const SYCLVector<Real>& vx, SYCLVector<Real>& vr)
const
233#ifdef ALIEN_USE_PERF_TIMER
234 SentryType s(m_timer,
"SYCL-AXPY");
236 m_internal->axpy(alpha, vx.internal()->values(), vr.internal()->values());
241void SYCLInternalLinearAlgebra::aypx(Real alpha ALIEN_UNUSED_PARAM,
242 SYCLVector<Real>& y ALIEN_UNUSED_PARAM,
243 const SYCLVector<Real>& x ALIEN_UNUSED_PARAM)
const
245 throw NotImplementedException(
246 A_FUNCINFO,
"SYCLLinearAlgebra::aypx not implemented");
251void SYCLInternalLinearAlgebra::copy(
const SYCLVector<Real>& vx, SYCLVector<Real>& vr)
const
253#ifdef ALIEN_USE_PERF_TIMER
254 SentryType s(m_timer,
"SYCL-COPY");
256 m_internal->copy(vx.internal()->values(), vr.internal()->values());
260void SYCLInternalLinearAlgebra::axpy(Real alpha,
261 const SYCLVector<Real>& vx,
263 SYCLVector<Real>& vr,
264 Integer stride_r)
const
266#ifdef ALIEN_USE_PERF_TIMER
267 SentryType s(m_timer,
"SYCL-AXPY");
269 m_internal->axpy(alpha, vx.internal()->values(), stride_x, vr.internal()->values(), stride_r);
274void SYCLInternalLinearAlgebra::aypx(Real alpha ALIEN_UNUSED_PARAM,
275 SYCLVector<Real>& y ALIEN_UNUSED_PARAM,
276 Integer stride_y ALIEN_UNUSED_PARAM,
277 const SYCLVector<Real>& x ALIEN_UNUSED_PARAM,
278 Integer stride_x ALIEN_UNUSED_PARAM)
const
280 throw NotImplementedException(
281 A_FUNCINFO,
"SYCLLinearAlgebra::aypx not implemented");
286void SYCLInternalLinearAlgebra::copy(
const SYCLVector<Real>& vx,
288 SYCLVector<Real>& vr,
289 Integer stride_r)
const
291#ifdef ALIEN_USE_PERF_TIMER
292 SentryType s(m_timer,
"SYCL-COPY");
294 m_internal->copy(vx.internal()->values(), stride_x, vr.internal()->values(), stride_r);
299Real SYCLInternalLinearAlgebra::dot(
const SYCLVector<Real>& vx,
const SYCLVector<Real>& vy)
const
301#ifdef ALIEN_USE_PERF_TIMER
302 SentryType s(m_timer,
"SYCL-DOT");
304 auto value = m_internal->dot(vx.internal()->values(), vy.internal()->values());
305 auto& dist = vx.distribution();
306 if (dist.isParallel()) {
308 value = Arccore::MessagePassing::mpAllReduce(dist.parallelMng(),
309 Arccore::MessagePassing::ReduceSum,
316void SYCLInternalLinearAlgebra::dot(
const SYCLVector<Real>& vx,
317 const SYCLVector<Real>& vy,
318 SYCLInternal::Future<Real>& res)
const
320#ifdef ALIEN_USE_PERF_TIMER
321 SentryType s(m_timer,
"SYCL-DOT-F");
323 m_internal->dot(vx.internal()->values(), vy.internal()->values(), res);
325 auto& dist = vx.distribution();
327 if (dist.isParallel()) {
329 Real local_value = res() ;
339 *x = Arccore::MessagePassing::mpAllReduce(
340 dist.parallelMng(), Arccore::MessagePassing::ReduceSum, local_value);
347void SYCLInternalLinearAlgebra::scal(Real alpha, SYCLVector<Real>& vx)
const
349#ifdef ALIEN_USE_PERF_TIMER
350 SentryType s(m_timer,
"SYCL-SCAL");
352 return m_internal->scal(alpha, vx.internal()->values());
356void SYCLInternalLinearAlgebra::scal(SYCLVector<Real>
const& vx, SYCLBEllPackMatrix<Real>& ma)
const
358#ifdef ALIEN_USE_PERF_TIMER
359 SentryType s(m_timer,
"SYCL-SCAL");
364void SYCLInternalLinearAlgebra::pointwiseMult(
const SYCLVector<Real>& vx,
365 const SYCLVector<Real>& vy,
366 SYCLVector<Real>& vz)
const
368#ifdef ALIEN_USE_PERF_TIMER
369 SentryType s(m_timer,
"SYCL-XYZ");
371 return m_internal->pointwiseMult(vx.internal()->values(), vy.internal()->values(), vz.internal()->values());
374void SYCLInternalLinearAlgebra::assign(SYCLVector<Real>& vx, Real alpha)
const
376#ifdef ALIEN_USE_PERF_TIMER
377 SentryType s(m_timer,
"SYCL-ASSIGN");
379 return m_internal->assign(alpha, vx.internal()->values());
382void SYCLInternalLinearAlgebra::diagonal(
383const SYCLBEllPackMatrix<Real>& ma, SYCLVector<Real>& vx)
const
385#ifdef ALIEN_USE_PERF_TIMER
386 SentryType s(m_timer,
"SYCL-DIAG");
388 Internal::SYCLBEllPackMatrixMultT<Real>(ma).computeDiag(vx);
391void SYCLInternalLinearAlgebra::reciprocal(SYCLVector<Real>& x ALIEN_UNUSED_PARAM)
const
393 throw NotImplementedException(
394 A_FUNCINFO,
"SYCLLinearAlgebra::reciprocal not implemented");
398Integer SYCLInternalLinearAlgebra::computeCxr(
const Matrix& a, Matrix& cxr_a)
const
400 auto block_size = a.blockSize() ;
401 cxr_a.setBlockSize(1) ;
406Integer SYCLInternalLinearAlgebra::computeCxr(
const Matrix& a,
const Vector& diag, Matrix& cxr_a)
const
408 auto block_size = a.blockSize() ;
409 cxr_a.setBlockSize(1) ;
418SYCLInternalLinearAlgebraExpr::SYCLInternalLinearAlgebraExpr()
419: IInternalLinearAlgebraExpr<SYCLBEllPackMatrix<Real>, SYCLVector<Real>>()
421 m_internal.reset(
new SYCLInternal::KernelInternal());
426SYCLInternalLinearAlgebraExpr::~SYCLInternalLinearAlgebraExpr() {}
431Real SYCLInternalLinearAlgebraExpr::norm0(
const SYCLVector<Real>& vx ALIEN_UNUSED_PARAM)
const
434 throw NotImplementedException(
435 A_FUNCINFO,
"SYCLLinearAlgebra::norm0 not implemented");
440Real SYCLInternalLinearAlgebraExpr::norm1(
const SYCLVector<Real>& vx ALIEN_UNUSED_PARAM)
const
443 throw NotImplementedException(
444 A_FUNCINFO,
"SYCLLinearAlgebra::norm1 not implemented");
449Real SYCLInternalLinearAlgebraExpr::norm2(
const SYCLVector<Real>& vx)
const
451 return std::sqrt(m_internal->dot(vx.internal()->values(), vx.internal()->values()));
454Real SYCLInternalLinearAlgebraExpr::normInf([[maybe_unused]]
const SYCLVector<Real>& vx)
const
456#ifdef ALIEN_USE_PERF_TIMER
457 SentryType s(m_timer,
"SYCL-NORMINF");
459 throw NotImplementedException(
460 A_FUNCINFO,
"SYCLLinearAlgebra::normInf not implemented");
464void SYCLInternalLinearAlgebraExpr::mult(
465const SYCLBEllPackMatrix<Real>& ma,
const SYCLVector<Real>& vx, SYCLVector<Real>& vr)
const
467 Internal::SYCLBEllPackMatrixMultT<Real>(ma).mult(vx, vr);
470void SYCLInternalLinearAlgebraExpr::mult(
471const SYCLBEllPackMatrix<Real>& ma,
const UniqueArray<Real>& vx, UniqueArray<Real>& vr)
const
473 Internal::SYCLBEllPackMatrixMultT<Real>(ma).mult(vx, vr);
478void SYCLInternalLinearAlgebraExpr::axpy([[maybe_unused]] Real alpha,
479 [[maybe_unused]]
const UniqueArray<Real>& vx,
480 [[maybe_unused]] UniqueArray<Real>& vr)
const
482 throw NotImplementedException(
483 A_FUNCINFO,
"SYCLLinearAlgebra::axpy not implemented");
486void SYCLInternalLinearAlgebraExpr::axpy(Real alpha,
const SYCLVector<Real>& vx, SYCLVector<Real>& vy)
const
488 m_internal->axpy(alpha, vx.internal()->values(), vy.internal()->values());
493void SYCLInternalLinearAlgebraExpr::aypx([[maybe_unused]] Real alpha, [[maybe_unused]] UniqueArray<Real>& vy, [[maybe_unused]] UniqueArray<Real>
const& vx)
const
495 throw NotImplementedException(
496 A_FUNCINFO,
"SYCLLinearAlgebra::aypx not implemented");
499void SYCLInternalLinearAlgebraExpr::aypx(Real alpha ALIEN_UNUSED_PARAM,
500 SYCLVector<Real>& y ALIEN_UNUSED_PARAM,
const SYCLVector<Real>& x ALIEN_UNUSED_PARAM)
const
502 throw NotImplementedException(
503 A_FUNCINFO,
"SYCLLinearAlgebra::aypx not implemented");
508void SYCLInternalLinearAlgebraExpr::copy([[maybe_unused]]
const UniqueArray<Real>& vx,
509 [[maybe_unused]] UniqueArray<Real>& vr)
const
511 throw NotImplementedException(
512 A_FUNCINFO,
"SYCLLinearAlgebra::copy not implemented");
515void SYCLInternalLinearAlgebraExpr::copy(
const SYCLVector<Real>& vx, SYCLVector<Real>& vy)
const
517 m_internal->copy(vx.internal()->values(), vy.internal()->values());
522Real SYCLInternalLinearAlgebraExpr::dot([[maybe_unused]]
523Integer local_size, [[maybe_unused]]
const UniqueArray<Real>& vx, [[maybe_unused]]
const UniqueArray<Real>& vy)
const
525 throw NotImplementedException(
526 A_FUNCINFO,
"SYCLLinearAlgebra::dot not implemented");
529Real SYCLInternalLinearAlgebraExpr::dot(
const SYCLVector<Real>& vx,
const SYCLVector<Real>& vy)
const
531 return m_internal->dot(vx.internal()->values(), vy.internal()->values());
534Real SYCLInternalLinearAlgebraExpr::norm2([[maybe_unused]]
const SYCLBEllPackMatrix<Real>& a)
const
536 throw NotImplementedException(
537 A_FUNCINFO,
"SYCLLinearAlgebra::notm2 not implemented");
540void SYCLInternalLinearAlgebraExpr::copy([[maybe_unused]]
const SYCLBEllPackMatrix<Real>& a, [[maybe_unused]] SYCLBEllPackMatrix<Real>& r)
const
542 throw NotImplementedException(
543 A_FUNCINFO,
"SYCLLinearAlgebra::copy not implemented");
546void SYCLInternalLinearAlgebraExpr::add([[maybe_unused]]
const SYCLBEllPackMatrix<Real>& a, [[maybe_unused]] SYCLBEllPackMatrix<Real>& r)
const
548 throw NotImplementedException(
549 A_FUNCINFO,
"SYCLLinearAlgebra::add not implemented");
552void SYCLInternalLinearAlgebraExpr::scal([[maybe_unused]] Real alpha, [[maybe_unused]] SYCLBEllPackMatrix<Real>& a)
const
554 throw NotImplementedException(
555 A_FUNCINFO,
"SYCLLinearAlgebra::scal not implemented");
558void SYCLInternalLinearAlgebraExpr::scal(Real alpha ALIEN_UNUSED_PARAM, UniqueArray<Real>& x ALIEN_UNUSED_PARAM)
const
560 throw NotImplementedException(
561 A_FUNCINFO,
"SYCLLinearAlgebra::scal not implemented");
564void SYCLInternalLinearAlgebraExpr::scal(Real alpha ALIEN_UNUSED_PARAM, SYCLVector<Real>& x ALIEN_UNUSED_PARAM)
const
566 throw NotImplementedException(
567 A_FUNCINFO,
"SYCLLinearAlgebra::aypx not implemented");
570void SYCLInternalLinearAlgebraExpr::diagonal(
571const SYCLBEllPackMatrix<Real>& a ALIEN_UNUSED_PARAM, SYCLVector<Real>& x ALIEN_UNUSED_PARAM)
const
573 throw NotImplementedException(
574 A_FUNCINFO,
"SYCLLinearAlgebra::aypx not implemented");
577void SYCLInternalLinearAlgebraExpr::reciprocal(SYCLVector<Real>& x ALIEN_UNUSED_PARAM)
const
579 throw NotImplementedException(
580 A_FUNCINFO,
"SYCLLinearAlgebra::aypx not implemented");
583void SYCLInternalLinearAlgebraExpr::pointwiseMult(
const SYCLVector<Real>& x ALIEN_UNUSED_PARAM,
584 const SYCLVector<Real>& y ALIEN_UNUSED_PARAM, SYCLVector<Real>& w ALIEN_UNUSED_PARAM)
const
586 throw NotImplementedException(
587 A_FUNCINFO,
"SYCLLinearAlgebra::aypx not implemented");
590template class ALIEN_EXPORT SYCLInternal::Future<double>;
592namespace SYCLInternal
595sycl::buffer<double>& KernelInternal::getWorkBuffer(std::size_t size)
597 if (m_double_work ==
nullptr) {
598 m_double_work =
new sycl::buffer<double>(size);
599 m_double_work->set_final_data(
nullptr);
602 if (size > m_double_work->size()) {
603 delete m_double_work;
604 m_double_work =
new sycl::buffer<double>(size);
605 m_double_work->set_final_data(
nullptr);
608 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 --