Alien  1.3.0
User documentation
Loading...
Searching...
No Matches
HCSRtoSYCLMatrixConverter.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2024 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>
14#include <alien/kernels/sycl/data/HCSRMatrix.h>
16
17#include <alien/kernels/sycl/SYCLBackEnd.h>
18#include <alien/kernels/simple_csr/CSRStructInfo.h>
19
20#include "alien/kernels/sycl/data/SYCLBEllPackInternal.h"
21#include "alien/kernels/sycl/data/HCSRMatrixInternal.h"
22
23using namespace Alien;
24using namespace Alien::SimpleCSRInternal;
25
26/*---------------------------------------------------------------------------*/
27
28class HCSRtoSYCLMatrixConverter : public IMatrixConverter
29{
30 public:
31 HCSRtoSYCLMatrixConverter();
32 virtual ~HCSRtoSYCLMatrixConverter() {}
33
34 public:
40 void convert(const IMatrixImpl* sourceImpl, IMatrixImpl* targetImpl) const;
41 void _build(const HCSRMatrix<Real>& sourceImpl, SYCLBEllPackMatrix<Real>& targetImpl) const;
42};
43
44/*---------------------------------------------------------------------------*/
45
46HCSRtoSYCLMatrixConverter::HCSRtoSYCLMatrixConverter()
47{
48 ;
49}
50
51/*---------------------------------------------------------------------------*/
52
54const IMatrixImpl* sourceImpl, IMatrixImpl* targetImpl) const
55{
56 const HCSRMatrix<Real>& v =
59
60 alien_debug(
61 [&] { cout() << "Converting HCSRMatrix: " << &v << " to SYCLBEllPackMatrix " << &v2; });
62
63 _build(v, v2);
64}
65
66void HCSRtoSYCLMatrixConverter::_build(
67const HCSRMatrix<Real>& sourceImpl, SYCLBEllPackMatrix<Real>& targetImpl) const
68{
69 typedef HCSRMatrix<Real>::MatrixInternal HCSRMatrixType;
70
71 const MatrixDistribution& dist = targetImpl.distribution();
72 const CSRStructInfo& profile = sourceImpl.getCSRProfile();
73 const Integer globalSize = dist.globalRowSize();
74 const Integer localOffset = dist.rowOffset();
75 auto const& matrixInternal = *sourceImpl.internal();
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 throw FatalErrorException(A_FUNCINFO, "SYCL Initialisation failed");
91 }
92
93 if (not targetImpl.internal()->setMatrixValues(matrixInternal.values())) {
94 throw FatalErrorException(A_FUNCINFO, "Cannot set SYCL Matrix Values");
95 }
96 }
97}
98
99/*---------------------------------------------------------------------------*/
100
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.
void convert(const IMatrixImpl *sourceImpl, IMatrixImpl *targetImpl) const
Convert a matrix from one format to another.
BackEndId targetBackend() const
Get the target backend id.
BackEndId sourceBackend() const
Get the source backend id.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Definition BackEnd.h:17