mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-08 13:23:51 +00:00
Support pointers in vtkm::exec::Fetch classes
This commit is contained in:
parent
65b019d443
commit
20d02fdec2
@ -75,10 +75,55 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
const IndexVecType* Indices;
|
||||
const IndexVecType* const Indices;
|
||||
PortalType Portal;
|
||||
};
|
||||
|
||||
template <typename IndexVecType, typename PortalType>
|
||||
class VecFromPortalPermute<IndexVecType, const PortalType*>
|
||||
{
|
||||
public:
|
||||
using ComponentType = typename std::remove_const<typename PortalType::ValueType>::type;
|
||||
|
||||
VTKM_SUPPRESS_EXEC_WARNINGS
|
||||
VTKM_EXEC_CONT
|
||||
VecFromPortalPermute() {}
|
||||
|
||||
VTKM_SUPPRESS_EXEC_WARNINGS
|
||||
VTKM_EXEC_CONT
|
||||
VecFromPortalPermute(const IndexVecType* indices, const PortalType* const portal)
|
||||
: Indices(indices)
|
||||
, Portal(portal)
|
||||
{
|
||||
}
|
||||
|
||||
VTKM_SUPPRESS_EXEC_WARNINGS
|
||||
VTKM_EXEC_CONT
|
||||
vtkm::IdComponent GetNumberOfComponents() const { return this->Indices->GetNumberOfComponents(); }
|
||||
|
||||
VTKM_SUPPRESS_EXEC_WARNINGS
|
||||
template <vtkm::IdComponent DestSize>
|
||||
VTKM_EXEC_CONT void CopyInto(vtkm::Vec<ComponentType, DestSize>& dest) const
|
||||
{
|
||||
vtkm::IdComponent numComponents = vtkm::Min(DestSize, this->GetNumberOfComponents());
|
||||
for (vtkm::IdComponent index = 0; index < numComponents; index++)
|
||||
{
|
||||
dest[index] = (*this)[index];
|
||||
}
|
||||
}
|
||||
|
||||
VTKM_SUPPRESS_EXEC_WARNINGS
|
||||
VTKM_EXEC_CONT
|
||||
ComponentType operator[](vtkm::IdComponent index) const
|
||||
{
|
||||
return this->Portal->Get((*this->Indices)[index]);
|
||||
}
|
||||
|
||||
private:
|
||||
const IndexVecType* const Indices;
|
||||
const PortalType* const Portal;
|
||||
};
|
||||
|
||||
template <typename IndexVecType, typename PortalType>
|
||||
struct TypeTraits<vtkm::VecFromPortalPermute<IndexVecType, PortalType>>
|
||||
{
|
||||
@ -134,6 +179,14 @@ inline VTKM_EXEC VecFromPortalPermute<IndexVecType, PortalType> make_VecFromPort
|
||||
return VecFromPortalPermute<IndexVecType, PortalType>(index, portal);
|
||||
}
|
||||
|
||||
template <typename IndexVecType, typename PortalType>
|
||||
inline VTKM_EXEC VecFromPortalPermute<IndexVecType, const PortalType*> make_VecFromPortalPermute(
|
||||
const IndexVecType* index,
|
||||
const PortalType* const portal)
|
||||
{
|
||||
return VecFromPortalPermute<IndexVecType, const PortalType*>(index, portal);
|
||||
}
|
||||
|
||||
} // namespace vtkm
|
||||
|
||||
#endif //vtk_m_VecFromPortalPermute_h
|
||||
|
@ -40,23 +40,43 @@ struct FetchTagArrayDirectIn
|
||||
{
|
||||
};
|
||||
|
||||
|
||||
VTKM_SUPPRESS_EXEC_WARNINGS
|
||||
template <typename T, typename U>
|
||||
inline VTKM_EXEC T load(const U& u, vtkm::Id v)
|
||||
{
|
||||
return u.Get(v);
|
||||
}
|
||||
|
||||
VTKM_SUPPRESS_EXEC_WARNINGS
|
||||
template <typename T, typename U>
|
||||
inline VTKM_EXEC T load(const U* u, vtkm::Id v)
|
||||
{
|
||||
return u->Get(v);
|
||||
}
|
||||
|
||||
template <typename ThreadIndicesType, typename ExecObjectType>
|
||||
struct Fetch<vtkm::exec::arg::FetchTagArrayDirectIn,
|
||||
vtkm::exec::arg::AspectTagDefault,
|
||||
ThreadIndicesType,
|
||||
ExecObjectType>
|
||||
{
|
||||
using ValueType = typename ExecObjectType::ValueType;
|
||||
//need to remove pointer type from ThreadIdicesType
|
||||
using ET = typename std::remove_const<typename std::remove_pointer<ExecObjectType>::type>::type;
|
||||
using PortalType =
|
||||
typename std::conditional<std::is_pointer<ExecObjectType>::value, const ET*, const ET&>::type;
|
||||
|
||||
using ValueType = typename ET::ValueType;
|
||||
|
||||
VTKM_SUPPRESS_EXEC_WARNINGS
|
||||
VTKM_EXEC
|
||||
ValueType Load(const ThreadIndicesType& indices, const ExecObjectType& arrayPortal) const
|
||||
ValueType Load(const ThreadIndicesType& indices, PortalType arrayPortal) const
|
||||
{
|
||||
return arrayPortal.Get(indices.GetInputIndex());
|
||||
return load<ValueType>(arrayPortal, indices.GetInputIndex());
|
||||
}
|
||||
|
||||
VTKM_EXEC
|
||||
void Store(const ThreadIndicesType&, const ExecObjectType&, const ValueType&) const
|
||||
void Store(const ThreadIndicesType&, PortalType, const ValueType&) const
|
||||
{
|
||||
// Store is a no-op for this fetch.
|
||||
}
|
||||
|
@ -85,6 +85,17 @@ struct FetchArrayTopologyMapInImplementation
|
||||
// least as far as the returned VecFromPortalPermute is used.
|
||||
return ValueType(indices.GetIndicesFromPointer(), field);
|
||||
}
|
||||
|
||||
VTKM_SUPPRESS_EXEC_WARNINGS
|
||||
VTKM_EXEC
|
||||
static ValueType Load(const ThreadIndicesType& indices, const FieldExecObjectType* const 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);
|
||||
}
|
||||
};
|
||||
|
||||
static inline VTKM_EXEC vtkm::VecAxisAlignedPointCoordinates<1> make_VecAxisAlignedPointCoordinates(
|
||||
|
Loading…
Reference in New Issue
Block a user