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::
169multDiag(
const SYCLBEllPackMatrix<Real>& ma,
170 const SYCLVector<Real>& vy,
171 SYCLVector<Real>& vr)
const
173#ifdef ALIEN_USE_PERF_TIMER
174 SentryType s(m_timer,
"SYCL-MULTDIAG");
176 Internal::SYCLBEllPackMatrixMultT<Real>(ma).multDiag(vy,vr);
179void SYCLInternalLinearAlgebra::
180multDiag(
const SYCLVector<Real>& diag,
181 const SYCLVector<Real>& vy,
182 SYCLVector<Real>& vr)
const
184#ifdef ALIEN_USE_PERF_TIMER
185 SentryType s(m_timer,
"SYCL-MULTDIAG");
187 diag.pointWiseMult(vy,vr);
191void SYCLInternalLinearAlgebra::
192multInvDiag(
const SYCLBEllPackMatrix<Real>& ma,
193 SYCLVector<Real>& vr)
const
195#ifdef ALIEN_USE_PERF_TIMER
196 SentryType s(m_timer,
"SYCL-MULTINVDIAG");
198 Internal::SYCLBEllPackMatrixMultT<Real>(ma).multInvDiag(vr);
201void SYCLInternalLinearAlgebra::
202computeInvDiag(
const SYCLBEllPackMatrix<Real>& ma,
203 SYCLVector<Real>& vr)
const
205#ifdef ALIEN_USE_PERF_TIMER
206 SentryType s(m_timer,
"SYCL-INVDIAG");
208 Internal::SYCLBEllPackMatrixMultT<Real>(ma).computeInvDiag(vr);
213void SYCLInternalLinearAlgebra::axpy(Real alpha,
const SYCLVector<Real>& vx, SYCLVector<Real>& vr)
const
215#ifdef ALIEN_USE_PERF_TIMER
216 SentryType s(m_timer,
"SYCL-AXPY");
218 m_internal->axpy(alpha, vx.internal()->values(), vr.internal()->values());
223void SYCLInternalLinearAlgebra::aypx(Real alpha ALIEN_UNUSED_PARAM,
224 SYCLVector<Real>& y ALIEN_UNUSED_PARAM,
225 const SYCLVector<Real>& x ALIEN_UNUSED_PARAM)
const
227 throw NotImplementedException(
228 A_FUNCINFO,
"SYCLLinearAlgebra::aypx not implemented");
233void SYCLInternalLinearAlgebra::copy(
const SYCLVector<Real>& vx, SYCLVector<Real>& vr)
const
235#ifdef ALIEN_USE_PERF_TIMER
236 SentryType s(m_timer,
"SYCL-COPY");
238 m_internal->copy(vx.internal()->values(), vr.internal()->values());
242void SYCLInternalLinearAlgebra::axpy(Real alpha,
243 const SYCLVector<Real>& vx,
245 SYCLVector<Real>& vr,
246 Integer stride_r)
const
248#ifdef ALIEN_USE_PERF_TIMER
249 SentryType s(m_timer,
"SYCL-AXPY");
251 m_internal->axpy(alpha, vx.internal()->values(), stride_x, vr.internal()->values(), stride_r);
256void SYCLInternalLinearAlgebra::aypx(Real alpha ALIEN_UNUSED_PARAM,
257 SYCLVector<Real>& y ALIEN_UNUSED_PARAM,
258 Integer stride_y ALIEN_UNUSED_PARAM,
259 const SYCLVector<Real>& x ALIEN_UNUSED_PARAM,
260 Integer stride_x ALIEN_UNUSED_PARAM)
const
262 throw NotImplementedException(
263 A_FUNCINFO,
"SYCLLinearAlgebra::aypx not implemented");
268void SYCLInternalLinearAlgebra::copy(
const SYCLVector<Real>& vx,
270 SYCLVector<Real>& vr,
271 Integer stride_r)
const
273#ifdef ALIEN_USE_PERF_TIMER
274 SentryType s(m_timer,
"SYCL-COPY");
276 m_internal->copy(vx.internal()->values(), stride_x, vr.internal()->values(), stride_r);
281Real SYCLInternalLinearAlgebra::dot(
const SYCLVector<Real>& vx,
const SYCLVector<Real>& vy)
const
283#ifdef ALIEN_USE_PERF_TIMER
284 SentryType s(m_timer,
"SYCL-DOT");
286 auto value = m_internal->dot(vx.internal()->values(), vy.internal()->values());
287 auto& dist = vx.distribution();
288 if (dist.isParallel()) {
289 return Arccore::MessagePassing::mpAllReduce(dist.parallelMng(),
290 Arccore::MessagePassing::ReduceSum,
296void SYCLInternalLinearAlgebra::dot(
const SYCLVector<Real>& vx,
297 const SYCLVector<Real>& vy,
298 SYCLInternal::Future<Real>& res)
const
300#ifdef ALIEN_USE_PERF_TIMER
301 SentryType s(m_timer,
"SYCL-DOT-F");
303 m_internal->dot(vx.internal()->values(), vy.internal()->values(), res);
305 auto& dist = vx.distribution();
306 if (dist.isParallel()) {
308 Real local_value = res() ;
310 auto request = mpNonBlockingAllReduce(dist.parallelMng(),
311 Arccore::MessagePassing::ReduceSum,
312 Arccore::ConstArrayView<Real>(1,&local_value),
313 Arccore::ArrayView<Real>(1,x)) ;
314 res.addRequest(dist.parallelMng(), request);
320void SYCLInternalLinearAlgebra::scal(Real alpha, SYCLVector<Real>& vx)
const
322#ifdef ALIEN_USE_PERF_TIMER
323 SentryType s(m_timer,
"SYCL-SCAL");
325 return m_internal->scal(alpha, vx.internal()->values());
329void SYCLInternalLinearAlgebra::scal(SYCLVector<Real>
const& vx, SYCLBEllPackMatrix<Real>& ma)
const
331#ifdef ALIEN_USE_PERF_TIMER
332 SentryType s(m_timer,
"SYCL-SCAL");
337void SYCLInternalLinearAlgebra::pointwiseMult(
const SYCLVector<Real>& vx,
338 const SYCLVector<Real>& vy,
339 SYCLVector<Real>& vz)
const
341#ifdef ALIEN_USE_PERF_TIMER
342 SentryType s(m_timer,
"SYCL-XYZ");
344 return m_internal->pointwiseMult(vx.internal()->values(), vy.internal()->values(), vz.internal()->values());
347void SYCLInternalLinearAlgebra::assign(SYCLVector<Real>& vx, Real alpha)
const
349#ifdef ALIEN_USE_PERF_TIMER
350 SentryType s(m_timer,
"SYCL-ASSIGN");
352 return m_internal->assign(alpha, vx.internal()->values());
355void SYCLInternalLinearAlgebra::diagonal(
356const SYCLBEllPackMatrix<Real>& ma, SYCLVector<Real>& vx)
const
358#ifdef ALIEN_USE_PERF_TIMER
359 SentryType s(m_timer,
"SYCL-DIAG");
361 Internal::SYCLBEllPackMatrixMultT<Real>(ma).computeDiag(vx);
364void SYCLInternalLinearAlgebra::reciprocal(SYCLVector<Real>& x ALIEN_UNUSED_PARAM)
const
366 throw NotImplementedException(
367 A_FUNCINFO,
"SYCLLinearAlgebra::reciprocal not implemented");
371Integer SYCLInternalLinearAlgebra::computeCxr(
const Matrix& a, Matrix& cxr_a)
const
373 auto block_size = a.blockSize() ;
374 cxr_a.setBlockSize(1) ;
379Integer SYCLInternalLinearAlgebra::computeCxr(
const Matrix& a,
const Vector& diag, Matrix& cxr_a)
const
381 auto block_size = a.blockSize() ;
382 cxr_a.setBlockSize(1) ;
391SYCLInternalLinearAlgebraExpr::SYCLInternalLinearAlgebraExpr()
392: IInternalLinearAlgebraExpr<SYCLBEllPackMatrix<Real>, SYCLVector<Real>>()
394 m_internal.reset(
new SYCLInternal::KernelInternal());
399SYCLInternalLinearAlgebraExpr::~SYCLInternalLinearAlgebraExpr() {}
404Real SYCLInternalLinearAlgebraExpr::norm0(
const SYCLVector<Real>& vx ALIEN_UNUSED_PARAM)
const
407 throw NotImplementedException(
408 A_FUNCINFO,
"SYCLLinearAlgebra::norm0 not implemented");
413Real SYCLInternalLinearAlgebraExpr::norm1(
const SYCLVector<Real>& vx ALIEN_UNUSED_PARAM)
const
416 throw NotImplementedException(
417 A_FUNCINFO,
"SYCLLinearAlgebra::norm1 not implemented");
422Real SYCLInternalLinearAlgebraExpr::norm2(
const SYCLVector<Real>& vx)
const
424 return std::sqrt(m_internal->dot(vx.internal()->values(), vx.internal()->values()));
427Real SYCLInternalLinearAlgebraExpr::normInf([[maybe_unused]]
const SYCLVector<Real>& vx)
const
429#ifdef ALIEN_USE_PERF_TIMER
430 SentryType s(m_timer,
"SYCL-NORMINF");
432 throw NotImplementedException(
433 A_FUNCINFO,
"SYCLLinearAlgebra::normInf not implemented");
437void SYCLInternalLinearAlgebraExpr::mult(
438const SYCLBEllPackMatrix<Real>& ma,
const SYCLVector<Real>& vx, SYCLVector<Real>& vr)
const
440 Internal::SYCLBEllPackMatrixMultT<Real>(ma).mult(vx, vr);
443void SYCLInternalLinearAlgebraExpr::mult(
444const SYCLBEllPackMatrix<Real>& ma,
const UniqueArray<Real>& vx, UniqueArray<Real>& vr)
const
446 Internal::SYCLBEllPackMatrixMultT<Real>(ma).mult(vx, vr);
451void SYCLInternalLinearAlgebraExpr::axpy([[maybe_unused]] Real alpha,
452 [[maybe_unused]]
const UniqueArray<Real>& vx,
453 [[maybe_unused]] UniqueArray<Real>& vr)
const
455 throw NotImplementedException(
456 A_FUNCINFO,
"SYCLLinearAlgebra::axpy not implemented");
459void SYCLInternalLinearAlgebraExpr::axpy(Real alpha,
const SYCLVector<Real>& vx, SYCLVector<Real>& vy)
const
461 m_internal->axpy(alpha, vx.internal()->values(), vy.internal()->values());
466void SYCLInternalLinearAlgebraExpr::aypx([[maybe_unused]] Real alpha, [[maybe_unused]] UniqueArray<Real>& vy, [[maybe_unused]] UniqueArray<Real>
const& vx)
const
468 throw NotImplementedException(
469 A_FUNCINFO,
"SYCLLinearAlgebra::aypx not implemented");
472void SYCLInternalLinearAlgebraExpr::aypx(Real alpha ALIEN_UNUSED_PARAM,
473 SYCLVector<Real>& y ALIEN_UNUSED_PARAM,
const SYCLVector<Real>& x ALIEN_UNUSED_PARAM)
const
475 throw NotImplementedException(
476 A_FUNCINFO,
"SYCLLinearAlgebra::aypx not implemented");
481void SYCLInternalLinearAlgebraExpr::copy([[maybe_unused]]
const UniqueArray<Real>& vx,
482 [[maybe_unused]] UniqueArray<Real>& vr)
const
484 throw NotImplementedException(
485 A_FUNCINFO,
"SYCLLinearAlgebra::copy not implemented");
488void SYCLInternalLinearAlgebraExpr::copy(
const SYCLVector<Real>& vx, SYCLVector<Real>& vy)
const
490 m_internal->copy(vx.internal()->values(), vy.internal()->values());
495Real SYCLInternalLinearAlgebraExpr::dot([[maybe_unused]]
496Integer local_size, [[maybe_unused]]
const UniqueArray<Real>& vx, [[maybe_unused]]
const UniqueArray<Real>& vy)
const
498 throw NotImplementedException(
499 A_FUNCINFO,
"SYCLLinearAlgebra::dot not implemented");
502Real SYCLInternalLinearAlgebraExpr::dot(
const SYCLVector<Real>& vx,
const SYCLVector<Real>& vy)
const
504 return m_internal->dot(vx.internal()->values(), vy.internal()->values());
507Real SYCLInternalLinearAlgebraExpr::norm2([[maybe_unused]]
const SYCLBEllPackMatrix<Real>& a)
const
509 throw NotImplementedException(
510 A_FUNCINFO,
"SYCLLinearAlgebra::notm2 not implemented");
513void SYCLInternalLinearAlgebraExpr::copy([[maybe_unused]]
const SYCLBEllPackMatrix<Real>& a, [[maybe_unused]] SYCLBEllPackMatrix<Real>& r)
const
515 throw NotImplementedException(
516 A_FUNCINFO,
"SYCLLinearAlgebra::copy not implemented");
519void SYCLInternalLinearAlgebraExpr::add([[maybe_unused]]
const SYCLBEllPackMatrix<Real>& a, [[maybe_unused]] SYCLBEllPackMatrix<Real>& r)
const
521 throw NotImplementedException(
522 A_FUNCINFO,
"SYCLLinearAlgebra::add not implemented");
525void SYCLInternalLinearAlgebraExpr::scal([[maybe_unused]] Real alpha, [[maybe_unused]] SYCLBEllPackMatrix<Real>& a)
const
527 throw NotImplementedException(
528 A_FUNCINFO,
"SYCLLinearAlgebra::scal not implemented");
531void SYCLInternalLinearAlgebraExpr::scal(Real alpha ALIEN_UNUSED_PARAM, UniqueArray<Real>& x ALIEN_UNUSED_PARAM)
const
533 throw NotImplementedException(
534 A_FUNCINFO,
"SYCLLinearAlgebra::scal not implemented");
537void SYCLInternalLinearAlgebraExpr::scal(Real alpha ALIEN_UNUSED_PARAM, SYCLVector<Real>& x ALIEN_UNUSED_PARAM)
const
539 throw NotImplementedException(
540 A_FUNCINFO,
"SYCLLinearAlgebra::aypx not implemented");
543void SYCLInternalLinearAlgebraExpr::diagonal(
544const SYCLBEllPackMatrix<Real>& a ALIEN_UNUSED_PARAM, SYCLVector<Real>& x ALIEN_UNUSED_PARAM)
const
546 throw NotImplementedException(
547 A_FUNCINFO,
"SYCLLinearAlgebra::aypx not implemented");
550void SYCLInternalLinearAlgebraExpr::reciprocal(SYCLVector<Real>& x ALIEN_UNUSED_PARAM)
const
552 throw NotImplementedException(
553 A_FUNCINFO,
"SYCLLinearAlgebra::aypx not implemented");
556void SYCLInternalLinearAlgebraExpr::pointwiseMult(
const SYCLVector<Real>& x ALIEN_UNUSED_PARAM,
557 const SYCLVector<Real>& y ALIEN_UNUSED_PARAM, SYCLVector<Real>& w ALIEN_UNUSED_PARAM)
const
559 throw NotImplementedException(
560 A_FUNCINFO,
"SYCLLinearAlgebra::aypx not implemented");
563template class ALIEN_EXPORT SYCLInternal::Future<double>;
565namespace SYCLInternal
568sycl::buffer<double>& KernelInternal::getWorkBuffer(std::size_t size)
570 if (m_double_work ==
nullptr) {
571 m_double_work =
new sycl::buffer<double>(size);
572 m_double_work->set_final_data(
nullptr);
575 if (size > m_double_work->size()) {
576 delete m_double_work;
577 m_double_work =
new sycl::buffer<double>(size);
578 m_double_work->set_final_data(
nullptr);
581 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 --