Arcane  v4.1.0.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
core/Data.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2025 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-2025 */
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"
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{
37ARCCORE_DEFINE_REFERENCE_COUNTED_CLASS(Arcane::ISerializedData);
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 MemoryUtils::fill(destination_buf, 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.
Fonctions de gestion mémoire et des allocateurs.
Arguments pour la copie mémoire.
Definition Memory.h:61
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:237
bool isNull() const
Indique si la RunQueue est nulle.
Vue constante sur une zone mémoire contigue contenant des éléments de taille fixe.
constexpr Int32 datatypeSize() const
Taille du type de donnée associé (1 par défaut)
Interface d'une donnée.
Definition IData.h:33
virtual void visitMultiArray2(IMultiArray2DataVisitor *visitor)
Applique le visiteur à la donnée.
Definition core/Data.cc:56
Interface du pattern visitor pour une donnée tableau 2D à taille variable.
Interface d'une donnée tableau multi 2D.
Definition IData.h:351
Interface pour un 'IData' d'un type numérique.
virtual MutableMemoryView memoryView()=0
Vue mémoire sur la donnée.
Vue modifiable sur une zone mémoire contigue contenant des éléments de taille fixe.
constexpr Int32 datatypeSize() const
Taille du type de donnée associé (1 par défaut)
Exception lorsqu'une opération n'est pas supportée.
ARCCORE_COMMON_EXPORT void fill(MutableMemoryView destination, ConstMemoryView source, const RunQueue *run_queue=nullptr)
Remplit une zone mémoire avec une valeur.
ARCCORE_COMMON_EXPORT void copy(MutableMemoryView destination, eMemoryResource destination_mem, ConstMemoryView source, eMemoryResource source_mem, const RunQueue *queue=nullptr)
Copie de source vers destination en utilisant la file queue.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
ConstMemoryView makeConstMemoryView(const void *ptr, Int32 datatype_size, Int64 nb_element)
Créé une vue mémoire en lecture seule.
Definition MemoryView.cc:36
std::int64_t Int64
Type entier signé sur 64 bits.
MutableMemoryView makeMutableMemoryView(void *ptr, Int32 datatype_size, Int64 nb_element)
Créé une vue mémoire modifiable.
Definition MemoryView.cc:26
std::int32_t Int32
Type entier signé sur 32 bits.
Espace de nom de Arccore.