Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify method 'ItemMaterialVariableBase::_initializeNewItems()' and cleanup code #1738

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions arcane/src/arcane/materials/ItemMaterialVariableBaseT.H
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,8 @@ _resizeForIndexer(ResizeVariableIndexerArgs& args)
this->_setView(index + 1);
}
if (args.isUseOneCommand()) {
auto dest = asWritableBytes(m_device_views).smallView();
auto source = asBytes(m_host_views).smallView();
auto dest = asWritableBytes(m_device_views.view());
auto source = asBytes(m_host_views.view());
args.addOneCopyData(source,dest,1);
}
else
Expand Down Expand Up @@ -467,7 +467,7 @@ _initializeNewItems(const ComponentItemListBuilder& list_builder, RunQueue& queu
{
MeshMaterialVariableIndexer* indexer = list_builder.indexer();
Integer var_index = indexer->index();
PrivatePartType* partial_var = m_vars[var_index+1];
PrivatePartType* partial_var = m_vars[var_index + 1];
if (!_isValidAndUsedAndGlobalUsed(partial_var))
return;

Expand All @@ -485,31 +485,32 @@ _initializeNewItems(const ComponentItemListBuilder& list_builder, RunQueue& queu
auto command = makeCommand(queue);
SmallSpan<ContainerViewType> views = m_device_views.smallSpan();

ContainerSpanType partial_view = m_host_views[var_index + 1];
ContainerSpanType pure_view = m_host_views[0];

ARCANE_CHECK_ACCESSIBLE_POINTER(queue, views.data());
ARCANE_CHECK_ACCESSIBLE_POINTER(queue, partial_matvar.data());

if (init_with_zero){
if (init_with_zero) {
command << RUNCOMMAND_LOOP1(iter, nb_partial)
{
auto [i] = iter();
MatVarIndex mvi = partial_matvar[i];
Traits::setValue(views[mvi.arrayIndex()][mvi.valueIndex()],zero);
Traits::setValue(partial_view[mvi.valueIndex()], zero);
};
}
else{
else {
SmallSpan<const Int32> partial_local_ids = list_builder.partialLocalIds();
ARCANE_CHECK_ACCESSIBLE_POINTER(queue, partial_local_ids.data());
command << RUNCOMMAND_LOOP1(iter, nb_partial)
{
auto [i] = iter();
const auto& v = views[0][partial_local_ids[i]];
MatVarIndex mvi = partial_matvar[i];
Traits::setValue(views[mvi.arrayIndex()][mvi.valueIndex()],v);
Traits::setValue(partial_view[mvi.valueIndex()], pure_view[partial_local_ids[i]]);
};
}
}


/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

Expand Down
142 changes: 73 additions & 69 deletions arcane/src/arcane/materials/MeshMaterialVariable.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,18 +178,19 @@ class MaterialVariableScalarTraits
{
public:

typedef DataType ValueType;

typedef DataType SubViewType;
typedef DataType SubConstViewType;
typedef DataType SubInputViewType;
typedef ArrayView<DataType> ContainerViewType;
typedef ConstArrayView<DataType> ContainerConstViewType;
typedef VariableArrayT<DataType> PrivatePartType;
typedef IArrayDataT<DataType> ValueDataType;
typedef Array<DataType> ContainerType;
typedef UniqueArray<DataType> UniqueContainerType;
typedef VariableRefArrayT<DataType> VariableRefType;
using ValueType = DataType;

using SubViewType = DataType;
using SubConstViewType = DataType;
using SubInputViewType = DataType;
using ContainerSpanType = SmallSpan<DataType>;
using ContainerViewType = ArrayView<DataType>;
using ContainerConstViewType = ConstArrayView<DataType>;
using PrivatePartType = VariableArrayT<DataType>;
using ValueDataType = IArrayDataT<DataType>;
using ContainerType = Array<DataType>;
using UniqueContainerType = UniqueArray<DataType>;
using VariableRefType = VariableRefArrayT<DataType>;

public:

Expand All @@ -211,8 +212,8 @@ class MaterialVariableScalarTraits
static Integer dimension() { return 0; }
static SmallSpan<std::byte> toBytes(ArrayView<DataType> view)
{
SmallSpan<DataType> s(view);
return asWritableBytes(s).smallView();
//SmallSpan<DataType> s(view);
return asWritableBytes(view);
}

};
Expand All @@ -225,18 +226,19 @@ class MaterialVariableArrayTraits
{
public:

typedef DataType ValueType;
using ValueType = DataType;

typedef ArrayView<DataType> SubViewType;
typedef ConstArrayView<DataType> SubConstViewType;
typedef SmallSpan<const DataType> SubInputViewType;
typedef Array2View<DataType> ContainerViewType;
typedef ConstArray2View<DataType> ContainerConstViewType;
typedef Array2VariableT<DataType> PrivatePartType;
typedef IArray2DataT<DataType> ValueDataType;
typedef Array2<DataType> ContainerType;
typedef UniqueArray2<DataType> UniqueContainerType;
typedef VariableRefArray2T<DataType> VariableRefType;
using SubViewType = ArrayView<DataType>;
using SubConstViewType = ConstArrayView<DataType>;
using SubInputViewType = SmallSpan<const DataType>;
using ContainerViewType = Array2View<DataType>;
using ContainerSpanType = SmallSpan2<DataType>;
using ContainerConstViewType = ConstArray2View<DataType>;
using PrivatePartType = Array2VariableT<DataType>;
using ValueDataType = IArray2DataT<DataType>;
using ContainerType = Array2<DataType>;
using UniqueContainerType = UniqueArray2<DataType>;
using VariableRefType = VariableRefArray2T<DataType>;

public:

Expand All @@ -263,7 +265,7 @@ class MaterialVariableArrayTraits
static SmallSpan<std::byte> toBytes(Array2View<DataType> view)
{
SmallSpan<DataType> s(view.data(), view.totalNbElement());
return asWritableBytes(s).smallView();
return asWritableBytes(s);
}

static Integer dimension() { return 0; }
Expand All @@ -282,29 +284,30 @@ class ItemMaterialVariableBase
{
public:

typedef Traits TraitsType;
typedef typename Traits::ValueType ValueType;
typedef typename Traits::ValueType DataType;
typedef ItemMaterialVariableBase<Traits> ThatClass;

typedef typename Traits::SubViewType SubViewType;
typedef typename Traits::SubConstViewType SubConstViewType;
typedef typename Traits::SubInputViewType SubInputViewType;
typedef typename Traits::ContainerViewType ContainerViewType;
typedef typename Traits::ContainerConstViewType ContainerConstViewType;
typedef typename Traits::PrivatePartType PrivatePartType;
typedef typename Traits::ValueDataType ValueDataType;
typedef typename Traits::ContainerType ContainerType;
typedef typename Traits::UniqueContainerType UniqueContainerType;
typedef typename Traits::VariableRefType VariableRefType;
using TraitsType = Traits;
using ValueType = typename Traits::ValueType;
using DataType = typename Traits::ValueType;
using ThatClass = ItemMaterialVariableBase<Traits>;

using SubViewType = typename Traits::SubViewType;
using SubConstViewType = typename Traits::SubConstViewType;
using SubInputViewType = typename Traits::SubInputViewType;
using ContainerSpanType = typename Traits::ContainerSpanType;
using ContainerViewType = typename Traits::ContainerViewType;
using ContainerConstViewType = typename Traits::ContainerConstViewType;
using PrivatePartType = typename Traits::PrivatePartType;
using ValueDataType = typename Traits::ValueDataType;
using ContainerType = typename Traits::ContainerType;
using UniqueContainerType = typename Traits::UniqueContainerType;
using VariableRefType = typename Traits::VariableRefType;

public:

ARCANE_MATERIALS_EXPORT
ItemMaterialVariableBase(const MaterialVariableBuildInfo& v,
PrivatePartType* global_var,
VariableRef* global_var_ref,MatVarSpace mvs);
ARCANE_MATERIALS_EXPORT ~ItemMaterialVariableBase();
ARCANE_MATERIALS_EXPORT ~ItemMaterialVariableBase() override;

public:

Expand Down Expand Up @@ -374,6 +377,12 @@ class ItemMaterialVariableBase

protected:

/*!
* \brief Positionne les vues à partir du conteneur
*
* La vue accélérateur n'est pas mise à jour ici mais lors de l'appel
* à _copyHostViewsToViews().
*/
void _setView(Int32 index)
{
ContainerViewType view;
Expand Down Expand Up @@ -416,16 +425,16 @@ class ItemMaterialVariableScalar
: public ItemMaterialVariableBase<MaterialVariableScalarTraits<DataType>>
{
public:

typedef ItemMaterialVariableBase<MaterialVariableScalarTraits<DataType>> BaseClass;
typedef MaterialVariableScalarTraits<DataType> Traits;
typedef ItemMaterialVariableScalar<DataType> ThatClass;

typedef typename Traits::ContainerViewType ContainerViewType;
typedef typename Traits::PrivatePartType PrivatePartType;
typedef typename Traits::ValueDataType ValueDataType;
typedef typename Traits::ContainerType ContainerType;
typedef typename Traits::VariableRefType VariableRefType;
using BaseClass = ItemMaterialVariableBase<MaterialVariableScalarTraits<DataType>>;
using Traits = MaterialVariableScalarTraits<DataType>;
using ThatClass = ItemMaterialVariableScalar<DataType>;

using ContainerViewType = typename Traits::ContainerViewType;
using PrivatePartType = typename Traits::PrivatePartType;
using ValueDataType = typename Traits::ValueDataType;
using ContainerType = typename Traits::ContainerType;
using VariableRefType = typename Traits::VariableRefType;

protected:

Expand Down Expand Up @@ -495,8 +504,6 @@ class ItemMaterialVariableScalar

void _synchronizeV1();
void _synchronizeV2();
void _synchronizeV3();
void _synchronizeV4();
void _synchronizeV5();
Int64 _synchronize2();

Expand Down Expand Up @@ -568,8 +575,8 @@ class MeshMaterialVariableScalar
IMeshMaterialVariable* toMeshMaterialVariable() final { return this; }

private:
VariableRefType* m_true_global_variable_ref;

VariableRefType* m_true_global_variable_ref = nullptr;
};

/*---------------------------------------------------------------------------*/
Expand All @@ -585,24 +592,23 @@ class ItemMaterialVariableArray
{
public:

typedef ItemMaterialVariableBase<MaterialVariableArrayTraits<DataType>> BaseClass;
typedef MaterialVariableArrayTraits<DataType> Traits;
using BaseClass = ItemMaterialVariableBase<MaterialVariableArrayTraits<DataType>>;
using Traits = MaterialVariableArrayTraits<DataType>;

typedef ItemMaterialVariableArray<DataType> ThatClass;
using ThatClass = ItemMaterialVariableArray<DataType>;

typedef typename Traits::ContainerViewType ContainerViewType;
typedef typename Traits::PrivatePartType PrivatePartType;
typedef typename Traits::ValueDataType ValueDataType;
typedef typename Traits::ContainerType ContainerType;
typedef typename Traits::VariableRefType VariableRefType;
using ContainerViewType = typename Traits::ContainerViewType;
using PrivatePartType = typename Traits::PrivatePartType;
using ValueDataType = typename Traits::ValueDataType;
using ContainerType = typename Traits::ContainerType;
using VariableRefType = typename Traits::VariableRefType;

protected:

ARCANE_MATERIALS_EXPORT
ItemMaterialVariableArray(const MaterialVariableBuildInfo& v,
PrivatePartType* global_var,
VariableRef* global_var_ref,MatVarSpace mvs);
ARCANE_MATERIALS_EXPORT ~ItemMaterialVariableArray() {}

public:

Expand Down Expand Up @@ -679,10 +685,10 @@ class MeshMaterialVariableArray
using ThatInterface = IArrayMeshMaterialVariable<ItemType,DataType>;
using BuilderType = typename ThatInterface::BuilderType;
using StaticImpl = MeshMaterialVariableCommonStaticImpl<ThatClass>;
typedef ItemType ItemTypeTemplate;
using ItemTypeTemplate = ItemType;

using BaseClass = ItemMaterialVariableArray<DataType>;
typedef MeshVariableArrayRefT<ItemType,DataType> VariableRefType;
using VariableRefType = MeshVariableArrayRefT<ItemType, DataType>;
using PrivatePartType = typename BaseClass::PrivatePartType;

friend StaticImpl;
Expand All @@ -693,8 +699,6 @@ class MeshMaterialVariableArray
MeshMaterialVariableArray(const MaterialVariableBuildInfo& v,
PrivatePartType* global_var,
VariableRefType* global_var_ref,MatVarSpace mvs);
ARCANE_MATERIALS_EXPORT
~MeshMaterialVariableArray(){}

public:

Expand All @@ -706,7 +710,7 @@ class MeshMaterialVariableArray

private:

VariableRefType* m_true_global_variable_ref;
VariableRefType* m_true_global_variable_ref = nullptr;
};


Expand Down
Loading