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);
272void SYCLInternalLinearAlgebra::axpy(Real alpha,
273 const SYCLVector<Real>& vx,
274 SYCLVector<Real>& vr,
275 ConstArrayView<Integer> strides_r)
const
277#ifdef ALIEN_USE_PERF_TIMER
278 SentryType s(m_timer,
"SYCL-AXPY");
280 m_internal->axpy(alpha, vx.internal()->values(), vr.internal()->values(), strides_r);
284void SYCLInternalLinearAlgebra::aypx(Real alpha ALIEN_UNUSED_PARAM,
285 SYCLVector<Real>& y ALIEN_UNUSED_PARAM,
286 Integer stride_y ALIEN_UNUSED_PARAM,
287 const SYCLVector<Real>& x ALIEN_UNUSED_PARAM,
288 Integer stride_x ALIEN_UNUSED_PARAM)
const
290 throw NotImplementedException(
291 A_FUNCINFO,
"SYCLLinearAlgebra::aypx not implemented");
296void SYCLInternalLinearAlgebra::copy(
const SYCLVector<Real>& vx,
298 SYCLVector<Real>& vr,
299 Integer stride_r)
const
301#ifdef ALIEN_USE_PERF_TIMER
302 SentryType s(m_timer,
"SYCL-COPY");
304 m_internal->copy(vx.internal()->values(), stride_x, vr.internal()->values(), stride_r);
307void SYCLInternalLinearAlgebra::copy(
const SYCLVector<Real>& vx,
308 ConstArrayView<Integer> strides_x,
309 SYCLVector<Real>& vr)
const
311#ifdef ALIEN_USE_PERF_TIMER
312 SentryType s(m_timer,
"SYCL-COPY");
314 m_internal->copy(vx.internal()->values(), strides_x, vr.internal()->values());
318void SYCLInternalLinearAlgebra::copy(
const SYCLVector<Real>& vx,
319 SYCLVector<Real>& vr,
320 ConstArrayView<Integer> strides_r)
const
322#ifdef ALIEN_USE_PERF_TIMER
323 SentryType s(m_timer,
"SYCL-COPY");
325 m_internal->copy(vx.internal()->values(), vr.internal()->values(), strides_r);
329Real SYCLInternalLinearAlgebra::dot(
const SYCLVector<Real>& vx,
const SYCLVector<Real>& vy)
const
331#ifdef ALIEN_USE_PERF_TIMER
332 SentryType s(m_timer,
"SYCL-DOT");
334 auto value = m_internal->dot(vx.internal()->values(), vy.internal()->values());
335 auto& dist = vx.distribution();
336 if (dist.isParallel()) {
338 value = Arccore::MessagePassing::mpAllReduce(dist.parallelMng(),
339 Arccore::MessagePassing::ReduceSum,
346void SYCLInternalLinearAlgebra::dot(
const SYCLVector<Real>& vx,
347 const SYCLVector<Real>& vy,
348 SYCLInternal::Future<Real>& res)
const
350#ifdef ALIEN_USE_PERF_TIMER
351 SentryType s(m_timer,
"SYCL-DOT-F");
353 m_internal->dot(vx.internal()->values(), vy.internal()->values(), res);
355 auto& dist = vx.distribution();
357 if (dist.isParallel()) {
359 Real local_value = res() ;
369 *x = Arccore::MessagePassing::mpAllReduce(
370 dist.parallelMng(), Arccore::MessagePassing::ReduceSum, local_value);
377void SYCLInternalLinearAlgebra::scal(Real alpha, SYCLVector<Real>& vx)
const
379#ifdef ALIEN_USE_PERF_TIMER
380 SentryType s(m_timer,
"SYCL-SCAL");
382 return m_internal->scal(alpha, vx.internal()->values());
386void SYCLInternalLinearAlgebra::scal(SYCLVector<Real>
const& vx, SYCLBEllPackMatrix<Real>& ma)
const
388#ifdef ALIEN_USE_PERF_TIMER
389 SentryType s(m_timer,
"SYCL-SCAL");
394void SYCLInternalLinearAlgebra::pointwiseMult(
const SYCLVector<Real>& vx,
395 const SYCLVector<Real>& vy,
396 SYCLVector<Real>& vz)
const
398#ifdef ALIEN_USE_PERF_TIMER
399 SentryType s(m_timer,
"SYCL-XYZ");
401 return m_internal->pointwiseMult(vx.internal()->values(), vy.internal()->values(), vz.internal()->values());
404void SYCLInternalLinearAlgebra::assign(SYCLVector<Real>& vx, Real alpha)
const
406#ifdef ALIEN_USE_PERF_TIMER
407 SentryType s(m_timer,
"SYCL-ASSIGN");
409 return m_internal->assign(alpha, vx.internal()->values());
412void SYCLInternalLinearAlgebra::diagonal(
413const SYCLBEllPackMatrix<Real>& ma, SYCLVector<Real>& vx)
const
415#ifdef ALIEN_USE_PERF_TIMER
416 SentryType s(m_timer,
"SYCL-DIAG");
418 Internal::SYCLBEllPackMatrixMultT<Real>(ma).computeDiag(vx);
421void SYCLInternalLinearAlgebra::reciprocal(SYCLVector<Real>& x ALIEN_UNUSED_PARAM)
const
423 throw NotImplementedException(
424 A_FUNCINFO,
"SYCLLinearAlgebra::reciprocal not implemented");
428Integer SYCLInternalLinearAlgebra::computeCxr(
const Matrix& a, Matrix& cxr_a)
const
430 auto block_size = a.blockSize() ;
431 cxr_a.setBlockSize(1) ;
436Integer SYCLInternalLinearAlgebra::computeCxr(
const Matrix& a,
438 UniqueArray<Integer>& strides)
const
440 auto block_size = a.blockSize() ;
441 cxr_a.setBlockSize(1) ;
443 const ISpace& space = a.rowSpace();
444 const MatrixDistribution& dist = a.distribution();
446 bool elliptic_split_tag_found = false ;
448 Integer domain_offset = dist.rowOffset();
449 Integer local_size = dist.localRowSize();
451 UniqueArray<Integer> filter(local_size);
453 for (Integer i = 0; i < space.nbField(); ++i)
455 const UniqueArray<Integer>& indices = space.field(i);
456 if (space.fieldLabel(i) ==
"Elliptic" and not indices.empty())
458 elliptic_split_tag_found =
true;
459 for (Integer j = 0; j < indices.size(); ++j)
461 const Integer index = indices[j];
463 filter[index - domain_offset] = 1 ;
467 cxr_a.copy(a,filter,strides) ;
472Integer SYCLInternalLinearAlgebra::computeCxr(
const Matrix& a,
const Vector& diag, Matrix& cxr_a)
const
474 auto block_size = a.blockSize() ;
475 cxr_a.setBlockSize(1) ;
484SYCLInternalLinearAlgebraExpr::SYCLInternalLinearAlgebraExpr()
485: IInternalLinearAlgebraExpr<SYCLBEllPackMatrix<Real>, SYCLVector<Real>>()
487 m_internal.reset(
new SYCLInternal::KernelInternal());
492SYCLInternalLinearAlgebraExpr::~SYCLInternalLinearAlgebraExpr() {}
497Real SYCLInternalLinearAlgebraExpr::norm0(
const SYCLVector<Real>& vx ALIEN_UNUSED_PARAM)
const
500 throw NotImplementedException(
501 A_FUNCINFO,
"SYCLLinearAlgebra::norm0 not implemented");
506Real SYCLInternalLinearAlgebraExpr::norm1(
const SYCLVector<Real>& vx ALIEN_UNUSED_PARAM)
const
509 throw NotImplementedException(
510 A_FUNCINFO,
"SYCLLinearAlgebra::norm1 not implemented");
515Real SYCLInternalLinearAlgebraExpr::norm2(
const SYCLVector<Real>& vx)
const
517 return std::sqrt(m_internal->dot(vx.internal()->values(), vx.internal()->values()));
520Real SYCLInternalLinearAlgebraExpr::normInf([[maybe_unused]]
const SYCLVector<Real>& vx)
const
522#ifdef ALIEN_USE_PERF_TIMER
523 SentryType s(m_timer,
"SYCL-NORMINF");
525 throw NotImplementedException(
526 A_FUNCINFO,
"SYCLLinearAlgebra::normInf not implemented");
530void SYCLInternalLinearAlgebraExpr::mult(
531const SYCLBEllPackMatrix<Real>& ma,
const SYCLVector<Real>& vx, SYCLVector<Real>& vr)
const
533 Internal::SYCLBEllPackMatrixMultT<Real>(ma).mult(vx, vr);
536void SYCLInternalLinearAlgebraExpr::mult(
537const SYCLBEllPackMatrix<Real>& ma,
const UniqueArray<Real>& vx, UniqueArray<Real>& vr)
const
539 Internal::SYCLBEllPackMatrixMultT<Real>(ma).mult(vx, vr);
544void SYCLInternalLinearAlgebraExpr::axpy([[maybe_unused]] Real alpha,
545 [[maybe_unused]]
const UniqueArray<Real>& vx,
546 [[maybe_unused]] UniqueArray<Real>& vr)
const
548 throw NotImplementedException(
549 A_FUNCINFO,
"SYCLLinearAlgebra::axpy not implemented");
552void SYCLInternalLinearAlgebraExpr::axpy(Real alpha,
const SYCLVector<Real>& vx, SYCLVector<Real>& vy)
const
554 m_internal->axpy(alpha, vx.internal()->values(), vy.internal()->values());
559void SYCLInternalLinearAlgebraExpr::aypx([[maybe_unused]] Real alpha, [[maybe_unused]] UniqueArray<Real>& vy, [[maybe_unused]] UniqueArray<Real>
const& vx)
const
561 throw NotImplementedException(
562 A_FUNCINFO,
"SYCLLinearAlgebra::aypx not implemented");
565void SYCLInternalLinearAlgebraExpr::aypx(Real alpha ALIEN_UNUSED_PARAM,
566 SYCLVector<Real>& y ALIEN_UNUSED_PARAM,
const SYCLVector<Real>& x ALIEN_UNUSED_PARAM)
const
568 throw NotImplementedException(
569 A_FUNCINFO,
"SYCLLinearAlgebra::aypx not implemented");
574void SYCLInternalLinearAlgebraExpr::copy([[maybe_unused]]
const UniqueArray<Real>& vx,
575 [[maybe_unused]] UniqueArray<Real>& vr)
const
577 throw NotImplementedException(
578 A_FUNCINFO,
"SYCLLinearAlgebra::copy not implemented");
581void SYCLInternalLinearAlgebraExpr::copy(
const SYCLVector<Real>& vx, SYCLVector<Real>& vy)
const
583 m_internal->copy(vx.internal()->values(), vy.internal()->values());
588Real SYCLInternalLinearAlgebraExpr::dot([[maybe_unused]]
589Integer local_size, [[maybe_unused]]
const UniqueArray<Real>& vx, [[maybe_unused]]
const UniqueArray<Real>& vy)
const
591 throw NotImplementedException(
592 A_FUNCINFO,
"SYCLLinearAlgebra::dot not implemented");
595Real SYCLInternalLinearAlgebraExpr::dot(
const SYCLVector<Real>& vx,
const SYCLVector<Real>& vy)
const
597 return m_internal->dot(vx.internal()->values(), vy.internal()->values());
600Real SYCLInternalLinearAlgebraExpr::norm2([[maybe_unused]]
const SYCLBEllPackMatrix<Real>& a)
const
602 throw NotImplementedException(
603 A_FUNCINFO,
"SYCLLinearAlgebra::notm2 not implemented");
606void SYCLInternalLinearAlgebraExpr::copy([[maybe_unused]]
const SYCLBEllPackMatrix<Real>& a, [[maybe_unused]] SYCLBEllPackMatrix<Real>& r)
const
608 throw NotImplementedException(
609 A_FUNCINFO,
"SYCLLinearAlgebra::copy not implemented");
612void SYCLInternalLinearAlgebraExpr::add([[maybe_unused]]
const SYCLBEllPackMatrix<Real>& a, [[maybe_unused]] SYCLBEllPackMatrix<Real>& r)
const
614 throw NotImplementedException(
615 A_FUNCINFO,
"SYCLLinearAlgebra::add not implemented");
618void SYCLInternalLinearAlgebraExpr::scal([[maybe_unused]] Real alpha, [[maybe_unused]] SYCLBEllPackMatrix<Real>& a)
const
620 throw NotImplementedException(
621 A_FUNCINFO,
"SYCLLinearAlgebra::scal not implemented");
624void SYCLInternalLinearAlgebraExpr::scal(Real alpha ALIEN_UNUSED_PARAM, UniqueArray<Real>& x ALIEN_UNUSED_PARAM)
const
626 throw NotImplementedException(
627 A_FUNCINFO,
"SYCLLinearAlgebra::scal not implemented");
630void SYCLInternalLinearAlgebraExpr::scal(Real alpha ALIEN_UNUSED_PARAM, SYCLVector<Real>& x ALIEN_UNUSED_PARAM)
const
632 throw NotImplementedException(
633 A_FUNCINFO,
"SYCLLinearAlgebra::aypx not implemented");
636void SYCLInternalLinearAlgebraExpr::diagonal(
637const SYCLBEllPackMatrix<Real>& a ALIEN_UNUSED_PARAM, SYCLVector<Real>& x ALIEN_UNUSED_PARAM)
const
639 throw NotImplementedException(
640 A_FUNCINFO,
"SYCLLinearAlgebra::aypx not implemented");
643void SYCLInternalLinearAlgebraExpr::reciprocal(SYCLVector<Real>& x ALIEN_UNUSED_PARAM)
const
645 throw NotImplementedException(
646 A_FUNCINFO,
"SYCLLinearAlgebra::aypx not implemented");
649void SYCLInternalLinearAlgebraExpr::pointwiseMult(
const SYCLVector<Real>& x ALIEN_UNUSED_PARAM,
650 const SYCLVector<Real>& y ALIEN_UNUSED_PARAM, SYCLVector<Real>& w ALIEN_UNUSED_PARAM)
const
652 throw NotImplementedException(
653 A_FUNCINFO,
"SYCLLinearAlgebra::aypx not implemented");
656template class ALIEN_EXPORT SYCLInternal::Future<double>;
658namespace SYCLInternal
661sycl::buffer<double>& KernelInternal::getWorkBuffer(std::size_t size)
663 if (m_double_work ==
nullptr) {
664 m_double_work =
new sycl::buffer<double>(size);
665 m_double_work->set_final_data(
nullptr);
668 if (size > m_double_work->size()) {
669 delete m_double_work;
670 m_double_work =
new sycl::buffer<double>(size);
671 m_double_work->set_final_data(
nullptr);
674 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 --