Alien  1.3.0
Developer documentation
Loading...
Searching...
No Matches
SimpleCSRtoSYCLMatrixConverter.cc
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#include <iostream>
9
10#include <alien/core/backend/IMatrixConverter.h>
12
13#include <alien/kernels/sycl/data/SYCLBEllPackMatrix.h>
15
16#include <alien/kernels/sycl/SYCLBackEnd.h>
17#include <alien/kernels/simple_csr/CSRStructInfo.h>
18#include <alien/kernels/simple_csr/SimpleCSRMatrix.h>
19#include <alien/kernels/simple_csr/SimpleCSRBackEnd.h>
20
21using namespace Alien;
22using namespace Alien::SimpleCSRInternal;
23
24/*---------------------------------------------------------------------------*/
25
26class SimpleCSRtoSYCLMatrixConverter : public IMatrixConverter
27{
28 public:
29 SimpleCSRtoSYCLMatrixConverter();
30 virtual ~SimpleCSRtoSYCLMatrixConverter() {}
31
32 public:
38 void convert(const IMatrixImpl* sourceImpl, IMatrixImpl* targetImpl) const;
39 void _build(const SimpleCSRMatrix<Real>& sourceImpl, SYCLBEllPackMatrix<Real>& targetImpl) const;
40};
41
42/*---------------------------------------------------------------------------*/
43
44SimpleCSRtoSYCLMatrixConverter::SimpleCSRtoSYCLMatrixConverter()
45{
46 ;
47}
48
49/*---------------------------------------------------------------------------*/
50
52const IMatrixImpl* sourceImpl, IMatrixImpl* targetImpl) const
53{
54 const SimpleCSRMatrix<Real>& v =
57
58 alien_debug(
59 [&] { cout() << "Converting SimpleCSRMatrix: " << &v << " to SYCLBEllPackMatrix " << &v2; });
60
61 _build(v, v2);
62}
63
64void SimpleCSRtoSYCLMatrixConverter::_build(
65const SimpleCSRMatrix<Real>& sourceImpl, SYCLBEllPackMatrix<Real>& targetImpl) const
66{
67 typedef SimpleCSRMatrix<Real>::MatrixInternal CSRMatrixType;
68
69 const MatrixDistribution& dist = targetImpl.distribution();
70 const CSRStructInfo& profile = sourceImpl.getCSRProfile();
71 const Integer globalSize = dist.globalRowSize();
72 const Integer localOffset = dist.rowOffset();
73 auto const& matrixInternal = *sourceImpl.internal();
74
75 auto block_size = sourceImpl.blockSize() ;
76
77 {
78 auto const& matrix_profile = sourceImpl.internal()->getCSRProfile();
79 int nrows = matrix_profile.getNRow();
80 int const* kcol = matrix_profile.getRowOffset().unguardedBasePointer();
81 int const* cols = matrix_profile.getCols().unguardedBasePointer();
82
83 if (not targetImpl.initMatrix(dist.parallelMng(),
84 localOffset,
85 globalSize,
86 nrows,
87 kcol,
88 cols,
89 sourceImpl.getDistStructInfo(),
90 block_size)) {
91 throw FatalErrorException(A_FUNCINFO, "SYCL Initialisation failed");
92 }
93
94 if (not targetImpl.setMatrixValues(matrixInternal.getDataPtr(), false)) {
95 throw FatalErrorException(A_FUNCINFO, "Cannot set SYCL Matrix Values");
96 }
97 }
98}
99
100/*---------------------------------------------------------------------------*/
101
ComputeBlockOffsets.h.
MatrixConverterRegisterer.h.
#define REGISTER_MATRIX_CONVERTER(converter)
Macro to register a matrix converter.
Matrices converter.
Alien::BackEndId BackEndId
Type of matrix backend.
Alien::IMatrixImpl IMatrixImpl
Type of matrix implementation.
static T & cast(IMatrixImpl *impl, BackEndId backend)
Cast a matrix implementation in its actual type.
Interface to handle abstract matrices implementation.
Definition IMatrixImpl.h:47
virtual const MatrixDistribution & distribution() const
Get the distribution of the matrix.
Computes a matrix distribution.
Arccore::Integer globalRowSize() const
Get the global row size.
Arccore::Integer rowOffset() const
Get the row offset.
Arccore::MessagePassing::IMessagePassingMng * parallelMng() const
Get the parallel manager.
BackEndId sourceBackend() const
Get the source backend id.
BackEndId targetBackend() const
Get the target backend id.
void convert(const IMatrixImpl *sourceImpl, IMatrixImpl *targetImpl) const
Convert a matrix from one format to another.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Definition BackEnd.h:17