Share from indices vector.

Previously, each VecFromPortalPermute (the type that held the from field
values) held its own copy of the indices. For point to cell on
structured grids, this was a lot of repeated data values, which has the
potential to fill up cache and registers. Instead, just use pointer
references.
This commit is contained in:
Kenneth Moreland 2015-10-19 15:37:36 -06:00
parent f7789f0ed7
commit 45abbb5c75
4 changed files with 43 additions and 9 deletions

@ -76,7 +76,11 @@ struct FetchArrayTopologyMapInImplementation
static ValueType Load(const ThreadIndicesType &indices,
const FieldExecObjectType &field)
{
return ValueType(indices.GetIndicesFrom(), field);
// It is important that we give the VecFromPortalPermute (ValueType) a
// pointer that will stay around during the time the Vec is valid. Thus, we
// should make sure that indices is a reference that goes up the stack at
// least as far as the returned VecFromPortalPermute is used.
return ValueType(indices.GetIndicesFromPointer(), field);
}
};

@ -97,7 +97,22 @@ public:
/// containing the indices to the "from" elements.
///
VTKM_EXEC_EXPORT
IndicesFromType GetIndicesFrom() const { return this->IndicesFrom; }
const IndicesFromType &GetIndicesFrom() const { return this->IndicesFrom; }
/// \brief The input indices of the "from" elements in pointer form.
///
/// Returns the same object as GetIndicesFrom except that it returns a
/// pointer to the internally held object rather than a reference or copy.
/// Since the from indices can be a sizeable Vec (8 entries is common), it is
/// best not to have a bunch a copies. Thus, you can pass around a pointer
/// instead. However, care should be taken to make sure that this object does
/// not go out of scope, at which time the returned pointer becomes invalid.
///
VTKM_EXEC_EXPORT
const IndicesFromType *GetIndicesFromPointer() const
{
return &this->IndicesFrom;
}
/// \brief The shape of the input cell.
///
@ -276,7 +291,22 @@ public:
/// containing the indices to the "from" elements.
///
VTKM_EXEC_EXPORT
IndicesFromType GetIndicesFrom() const { return this->IndicesFrom; }
const IndicesFromType &GetIndicesFrom() const { return this->IndicesFrom; }
/// \brief The input indices of the "from" elements in pointer form.
///
/// Returns the same object as GetIndicesFrom except that it returns a
/// pointer to the internally held object rather than a reference or copy.
/// Since the from indices can be a sizeable Vec (8 entries is common), it is
/// best not to have a bunch a copies. Thus, you can pass around a pointer
/// instead. However, care should be taken to make sure that this object does
/// not go out of scope, at which time the returned pointer becomes invalid.
///
VTKM_EXEC_EXPORT
const IndicesFromType *GetIndicesFromPointer() const
{
return &this->IndicesFrom;
}
/// \brief The shape of the input cell.
///

@ -45,12 +45,12 @@ public:
VecFromPortalPermute() { }
VTKM_EXEC_EXPORT
VecFromPortalPermute(const IndexVecType &indices, const PortalType &portal)
VecFromPortalPermute(const IndexVecType *indices, const PortalType &portal)
: Indices(indices), Portal(portal) { }
VTKM_EXEC_EXPORT
vtkm::IdComponent GetNumberOfComponents() const {
return this->Indices.GetNumberOfComponents();
return this->Indices->GetNumberOfComponents();
}
template<vtkm::IdComponent DestSize>
@ -61,18 +61,18 @@ public:
vtkm::Min(DestSize, this->GetNumberOfComponents());
for (vtkm::IdComponent index = 0; index < numComponents; index++)
{
dest[index] = this->Portal.Get(this->Indices[index]);
dest[index] = (*this)[index];
}
}
VTKM_EXEC_EXPORT
ComponentType operator[](vtkm::IdComponent index) const
{
return this->Portal.Get(this->Indices[index]);
return this->Portal.Get((*this->Indices)[index]);
}
private:
IndexVecType Indices;
const IndexVecType *Indices;
PortalType Portal;
};

@ -87,7 +87,7 @@ struct VecFromPortalPermuteTestFunctor
indices.Append(offset + 2*index);
}
VecType vec(indices, portal);
VecType vec(&indices, portal);
VTKM_TEST_ASSERT(vec.GetNumberOfComponents() == length,
"Wrong length.");