Arcane  v3.14.10.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
Data.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/* Data.cc (C) 2000-2024 */
9/* */
10/* Types liés aux 'IData'. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/core/IData.h"
15
16#include "arcane/utils/NotSupportedException.h"
17#include "arcane/utils/FatalErrorException.h"
18#include "arcane/utils/ArrayShape.h"
19#include "arcane/utils/MemoryUtils.h"
20
21#include "arcane/core/IDataFactory.h"
22#include "arcane/core/IDataVisitor.h"
23#include "arcane/core/ISerializedData.h"
24#include "arcane/core/internal/IDataInternal.h"
25
27
28#include "arcane/accelerator/core/RunQueue.h"
29#include "arcane/accelerator/core/Memory.h"
30
31/*---------------------------------------------------------------------------*/
32/*---------------------------------------------------------------------------*/
33
34namespace Arccore
35{
38} // namespace Arccore
39
40namespace Arcane
41{
42
43/*---------------------------------------------------------------------------*/
44/*---------------------------------------------------------------------------*/
45
46void IDataVisitor::
47applyDataVisitor(IMultiArray2Data*)
48{
49 ARCANE_THROW(NotSupportedException, "using applyDataVisitor with IMultiArray2Data is no longer supported");
50}
51
52/*---------------------------------------------------------------------------*/
53/*---------------------------------------------------------------------------*/
54
57{
58 ARCANE_THROW(NotSupportedException, "Visiting IMultiArray2Data is no longer supported");
59}
60
61/*---------------------------------------------------------------------------*/
62/*---------------------------------------------------------------------------*/
63
64void impl::
65copyContiguousData(INumericDataInternal* num_destination, ConstMemoryView source_buf,
66 RunQueue& queue)
67{
68 ARCANE_CHECK_POINTER(num_destination);
69
70 MutableMemoryView destination_buf = num_destination->memoryView();
71 if (source_buf.datatypeSize() != destination_buf.datatypeSize())
72 ARCANE_FATAL("Source and destination do not have the same datatype s={0} d={1}",
73 source_buf.datatypeSize(), destination_buf.datatypeSize());
74 if (queue.isNull())
75 MemoryUtils::copy(destination_buf, source_buf);
76 else
77 queue.copyMemory(Accelerator::MemoryCopyArgs(destination_buf, source_buf));
78}
79
80/*---------------------------------------------------------------------------*/
81/*---------------------------------------------------------------------------*/
82
83void impl::
84copyContiguousData(IData* destination, IData* source, RunQueue& queue)
85{
87 ARCANE_CHECK_POINTER(destination);
88
89 INumericDataInternal* num_destination = destination->_commonInternal()->numericData();
90 if (!num_destination)
91 ARCANE_FATAL("Destination is not a numerical data");
92 INumericDataInternal* num_source = source->_commonInternal()->numericData();
93 if (!num_source)
94 ARCANE_FATAL("Source is not a numerical data");
95 copyContiguousData(num_destination, num_source->memoryView(), queue);
96}
97
98/*---------------------------------------------------------------------------*/
99/*---------------------------------------------------------------------------*/
100
101void impl::
102fillContiguousDataGeneric(IData* data, const void* fill_address,
103 Int32 datatype_size, RunQueue& queue)
104{
105 INumericDataInternal* num_data = data->_commonInternal()->numericData();
106 if (!num_data)
107 ARCANE_FATAL("Destination is not a numerical data");
108
109 ConstMemoryView fill_value_view(makeConstMemoryView(fill_address, datatype_size, 1));
110 MutableMemoryView destination_buf = num_data->memoryView();
111
112 // Si \a data est un tableau 2D ou plus il faut le transformer en un tableau 1D
113 // du nombre total d'éléments sinon 'destination_buf.datatypeSize() n'est pas
114 // cohérent avec 'datatype_size'
115 if (data->dimension() > 1) {
116 Int64 total_dim = data->shape().totalNbElement();
117 Int64 nb_element = destination_buf.nbElement();
118 destination_buf = makeMutableMemoryView(destination_buf.data(), datatype_size, nb_element * total_dim);
119 }
120
121 destination_buf.fill(fill_value_view, &queue);
122}
123
124/*---------------------------------------------------------------------------*/
125/*---------------------------------------------------------------------------*/
126
127} // namespace Arcane
128
129/*---------------------------------------------------------------------------*/
130/*---------------------------------------------------------------------------*/
#define ARCANE_CHECK_POINTER(ptr)
Macro retournant le pointeur ptr s'il est non nul ou lancant une exception s'il est nul.
#define ARCANE_THROW(exception_class,...)
Macro pour envoyer une exception avec formattage.
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
#define ARCCORE_DEFINE_REFERENCE_COUNTED_CLASS(class_name)
Macro pour définir les méthodes et types une classe qui utilise un compteur de référence.
Arguments pour la copie mémoire.
Definition Memory.h:63
File d'exécution pour un accélérateur.
void copyMemory(const MemoryCopyArgs &args) const
Copie des informations entre deux zones mémoires.
Definition RunQueue.cc:230
bool isNull() const
Indique si la RunQueue est nulle.
Interface d'une donnée.
Definition IData.h:33
virtual void visitMultiArray2(IMultiArray2DataVisitor *visitor)
Applique le visiteur à la donnée.
Definition Data.cc:56
Interface du pattern visitor pour une donnée tableau 2D à taille variable.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
Espace de nom de Arccore.
Definition ArcaneTypes.h:24