Commit 2f1d910e authored by Kenneth Moreland's avatar Kenneth Moreland

Merge branch 'container-to-storage'

parents b2584f92 21823500
......@@ -22,9 +22,10 @@
#include <vtkm/Types.h>
#include <vtkm/cont/ArrayContainerControl.h>
#include <vtkm/cont/Assert.h>
#include <vtkm/cont/ErrorControlBadValue.h>
#include <vtkm/cont/Storage.h>
#include <vtkm/cont/internal/ArrayHandleExecutionManager.h>
#include <vtkm/cont/internal/ArrayTransfer.h>
#include <vtkm/cont/internal/DeviceAdapterTag.h>
......@@ -42,18 +43,18 @@ namespace cont {
namespace internal {
/// Checks to see if the given type and container can form a valid array handle
/// (some containers cannot support all types). This check is compatable with
/// the Boost meta-template programming library (MPL). It contains a typedef
/// named type that is either boost::mpl::true_ or boost::mpl::false_. Both of
/// these have a typedef named value with the respective boolean value.
/// Checks to see if the given type and storage can form a valid array handle
/// (some storage objects cannot support all types). This check is compatable
/// with the Boost meta-template programming library (MPL). It contains a
/// typedef named type that is either boost::mpl::true_ or boost::mpl::false_.
/// Both of these have a typedef named value with the respective boolean value.
///
template<typename T, typename ArrayContainerControlTag>
template<typename T, typename StorageTag>
struct IsValidArrayHandle {
typedef typename boost::mpl::not_<
typename boost::is_base_of<
vtkm::cont::internal::UndefinedArrayContainerControl,
vtkm::cont::internal::ArrayContainerControl<T,ArrayContainerControlTag>
vtkm::cont::internal::UndefinedStorage,
vtkm::cont::internal::Storage<T,StorageTag>
>::type
>::type type;
};
......@@ -83,22 +84,18 @@ struct IsValidArrayHandle {
///
template<
typename T,
typename ArrayContainerControlTag_ = VTKM_DEFAULT_ARRAY_CONTAINER_CONTROL_TAG>
typename StorageTag_ = VTKM_DEFAULT_STORAGE_TAG>
class ArrayHandle
{
private:
typedef vtkm::cont::internal
::ArrayContainerControl<T,ArrayContainerControlTag_>
ArrayContainerControlType;
typedef vtkm::cont::internal
::ArrayHandleExecutionManagerBase<T,ArrayContainerControlTag_>
typedef vtkm::cont::internal::Storage<T,StorageTag_> StorageType;
typedef vtkm::cont::internal::ArrayHandleExecutionManagerBase<T,StorageTag_>
ExecutionManagerType;
public:
typedef T ValueType;
typedef ArrayContainerControlTag_ ArrayContainerControlTag;
typedef typename ArrayContainerControlType::PortalType PortalControl;
typedef typename ArrayContainerControlType::PortalConstType
PortalConstControl;
typedef StorageTag_ StorageTag;
typedef typename StorageType::PortalType PortalControl;
typedef typename StorageType::PortalConstType PortalConstControl;
template <typename DeviceAdapterTag>
struct ExecutionTypes
{
......@@ -398,11 +395,11 @@ public:
/// initial state of the control array. When this constructor is used, it
/// is assumed that the control array is valid.
///
ArrayHandle(const ArrayContainerControlType &container)
ArrayHandle(const StorageType &storage)
: Internals(new InternalStruct)
{
this->Internals->UserPortalValid = false;
this->Internals->ControlArray = container;
this->Internals->ControlArray = storage;
this->Internals->ControlArrayValid = true;
this->Internals->ExecutionArrayValid = false;
}
......@@ -413,12 +410,12 @@ public:
PortalConstControl UserPortal;
bool UserPortalValid;
ArrayContainerControlType ControlArray;
StorageType ControlArray;
bool ControlArrayValid;
boost::scoped_ptr<
vtkm::cont::internal::ArrayHandleExecutionManagerBase<
ValueType,ArrayContainerControlTag> > ExecutionArray;
ValueType,StorageTag> > ExecutionArray;
bool ExecutionArrayValid;
};
......@@ -468,7 +465,7 @@ public:
= const_cast<InternalStruct*>(this->Internals.get());
internals->ExecutionArray.reset(
new vtkm::cont::internal::ArrayHandleExecutionManager<
T, ArrayContainerControlTag, DeviceAdapterTag>);
T, StorageTag, DeviceAdapterTag>);
}
/// Synchronizes the control array with the execution array. If either the
......@@ -502,55 +499,55 @@ public:
boost::shared_ptr<InternalStruct> Internals;
};
/// A convenience function for creating an ArrayHandle from a standard C
/// array. Unless properly specialized, this only works with container types
/// that use an array portal that accepts a pair of pointers to signify the
/// beginning and end of the array.
/// A convenience function for creating an ArrayHandle from a standard C array.
/// Unless properly specialized, this only works with storage types that use an
/// array portal that accepts a pair of pointers to signify the beginning and
/// end of the array.
///
template<typename T, typename ArrayContainerControlTag>
template<typename T, typename StorageTag>
VTKM_CONT_EXPORT
vtkm::cont::ArrayHandle<T, ArrayContainerControlTag>
vtkm::cont::ArrayHandle<T, StorageTag>
make_ArrayHandle(const T *array,
vtkm::Id length,
ArrayContainerControlTag)
StorageTag)
{
typedef vtkm::cont::ArrayHandle<T, ArrayContainerControlTag> ArrayHandleType;
typedef vtkm::cont::ArrayHandle<T, StorageTag> ArrayHandleType;
typedef typename ArrayHandleType::PortalConstControl PortalType;
return ArrayHandleType(PortalType(array, array+length));
}
template<typename T>
VTKM_CONT_EXPORT
vtkm::cont::ArrayHandle<T, VTKM_DEFAULT_ARRAY_CONTAINER_CONTROL_TAG>
vtkm::cont::ArrayHandle<T, VTKM_DEFAULT_STORAGE_TAG>
make_ArrayHandle(const T *array, vtkm::Id length)
{
return make_ArrayHandle(array,
length,
VTKM_DEFAULT_ARRAY_CONTAINER_CONTROL_TAG());
VTKM_DEFAULT_STORAGE_TAG());
}
/// A convenience function for creating an ArrayHandle from an std::vector.
/// Unless properly specialized, this only works with container types that use
/// an array portal that accepts a pair of pointers to signify the beginning
/// and end of the array.
/// Unless properly specialized, this only works with storage types that use an
/// array portal that accepts a pair of pointers to signify the beginning and
/// end of the array.
///
template<typename T,
typename Allocator,
typename ArrayContainerControlTag>
typename StorageTag>
VTKM_CONT_EXPORT
vtkm::cont::ArrayHandle<T, ArrayContainerControlTag>
vtkm::cont::ArrayHandle<T, StorageTag>
make_ArrayHandle(const std::vector<T,Allocator> &array,
ArrayContainerControlTag)
StorageTag)
{
typedef vtkm::cont::ArrayHandle<T, ArrayContainerControlTag> ArrayHandleType;
typedef vtkm::cont::ArrayHandle<T, StorageTag> ArrayHandleType;
typedef typename ArrayHandleType::PortalConstControl PortalType;
return ArrayHandleType(PortalType(&array.front(), &array.back() + 1));
}
template<typename T, typename Allocator>
VTKM_CONT_EXPORT
vtkm::cont::ArrayHandle<T, VTKM_DEFAULT_ARRAY_CONTAINER_CONTROL_TAG>
vtkm::cont::ArrayHandle<T, VTKM_DEFAULT_STORAGE_TAG>
make_ArrayHandle(const std::vector<T,Allocator> &array)
{
return make_ArrayHandle(array, VTKM_DEFAULT_ARRAY_CONTAINER_CONTROL_TAG());
return make_ArrayHandle(array, VTKM_DEFAULT_STORAGE_TAG());
}
}
......
This diff is collapsed.
......@@ -20,8 +20,9 @@
#ifndef vtk_m_cont_ArrayHandleCounting_h
#define vtk_m_cont_ArrayHandleCounting_h
#include <vtkm/cont/ArrayContainerControlImplicit.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/StorageImplicit.h>
#include <vtkm/cont/internal/IteratorFromArrayPortal.h>
namespace vtkm {
......@@ -92,11 +93,11 @@ private:
};
/// A convenience class that provides a typedef to the appropriate tag for
/// a counting array container.
/// a counting storage.
template<typename ConstantValueType>
struct ArrayHandleCountingTraits
{
typedef vtkm::cont::ArrayContainerControlTagImplicit<
typedef vtkm::cont::StorageTagImplicit<
vtkm::cont::internal::ArrayPortalCounting<ConstantValueType> > Tag;
};
......
......@@ -22,8 +22,8 @@
#include <vtkm/Extent.h>
#include <vtkm/cont/ArrayContainerControlImplicit.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/StorageImplicit.h>
#include <vtkm/cont/internal/IteratorFromArrayPortal.h>
......@@ -131,12 +131,12 @@ private:
class ArrayHandleUniformPointCoordinates
: public vtkm::cont::ArrayHandle<
vtkm::Vector3,
vtkm::cont::ArrayContainerControlTagImplicit<
vtkm::cont::StorageTagImplicit<
internal::ArrayPortalUniformPointCoordinates> >
{
typedef vtkm::cont::ArrayHandle<
vtkm::Vector3,
vtkm::cont::ArrayContainerControlTagImplicit<
vtkm::cont::StorageTagImplicit<
internal::ArrayPortalUniformPointCoordinates> > Superclass;
public:
......
......@@ -42,7 +42,7 @@ namespace cont {
/// An ArrayPortal differs from an ArrayHandle in that the ArrayPortal is a
/// much lighterweight object and that it does not manage things like
/// allocation and control/execution sharing. An ArrayPortal also differs from
/// an ArrayContainer in that it does not actually contain the data but rather
/// a Storage in that it does not actually contain the data but rather
/// points to it. In this way the ArrayPortal can be copied and passed and
/// still point to the same data.
///
......
......@@ -21,16 +21,12 @@
include_directories(${Boost_INCLUDE_DIRS})
set(headers
ArrayContainerControl.h
ArrayContainerControlBasic.h
ArrayContainerControlImplicit.h
ArrayHandle.h
ArrayHandleCompositeVector.h
ArrayHandleCounting.h
ArrayHandleUniformPointCoordinates.h
ArrayPortal.h
Assert.h
ContainerListTag.h
DeviceAdapter.h
DeviceAdapterSerial.h
DynamicArrayHandle.h
......@@ -45,6 +41,10 @@ set(headers
PointCoordinatesArray.h
PointCoordinatesListTag.h
PointCoordinatesUniform.h
Storage.h
StorageBasic.h
StorageImplicit.h
StorageListTag.h
Timer.h
)
......
This diff is collapsed.
This diff is collapsed.
......@@ -49,20 +49,20 @@ public:
PointCoordinatesArray(const vtkm::cont::DynamicArrayHandle &array)
: Array(array) { }
template<typename Container>
template<typename Storage>
VTKM_CONT_EXPORT
PointCoordinatesArray(
const vtkm::cont::ArrayHandle<vtkm::Vector3,Container> &array)
const vtkm::cont::ArrayHandle<vtkm::Vector3,Storage> &array)
: Array(array) { }
/// In this \c CastAndCall, \c TypeList is ignored. All point coordinates are
/// expressed as Vector3, so that must be how the array is represented.
///
template<typename Functor, typename TypeList, typename ContainerList>
template<typename Functor, typename TypeList, typename StorageList>
VTKM_CONT_EXPORT
void CastAndCall(const Functor &f, TypeList, ContainerList) const
void CastAndCall(const Functor &f, TypeList, StorageList) const
{
this->Array.CastAndCall(f, vtkm::TypeListTagVector3(), ContainerList());
this->Array.CastAndCall(f, vtkm::TypeListTagVector3(), StorageList());
}
private:
......
......@@ -49,13 +49,13 @@ public:
: Array(extent, origin, spacing)
{ }
/// In this \c CastAndCall, both \c TypeList and \c ContainerList are
/// In this \c CastAndCall, both \c TypeList and \c StorageList are
/// ignored. All point coordinates are expressed as Vector3, so that must be
/// how the array is represented.
///
template<typename Functor, typename TypeList, typename ContainerList>
template<typename Functor, typename TypeList, typename StorageList>
VTKM_CONT_EXPORT
void CastAndCall(const Functor &f, TypeList, ContainerList) const
void CastAndCall(const Functor &f, TypeList, StorageList) const
{
f(this->Array);
}
......
......@@ -17,15 +17,15 @@
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#ifndef vtk_m_cont__ArrayContainerControl_h
#define vtk_m_cont__ArrayContainerControl_h
#ifndef vtk_m_cont_Storage_h
#define vtk_m_cont_Storage_h
#define VTKM_ARRAY_CONTAINER_CONTROL_ERROR -2
#define VTKM_ARRAY_CONTAINER_CONTROL_UNDEFINED -1
#define VTKM_ARRAY_CONTAINER_CONTROL_BASIC 1
#define VTKM_STORAGE_ERROR -2
#define VTKM_STORAGE_UNDEFINED -1
#define VTKM_STORAGE_BASIC 1
#ifndef VTKM_ARRAY_CONTAINER_CONTROL
#define VTKM_ARRAY_CONTAINER_CONTROL VTKM_ARRAY_CONTAINER_CONTROL_BASIC
#ifndef VTKM_STORAGE
#define VTKM_STORAGE VTKM_STORAGE_BASIC
#endif
#include <boost/static_assert.hpp>
......@@ -36,42 +36,40 @@ namespace cont {
#ifdef VTKM_DOXYGEN_ONLY
/// \brief A tag specifying client memory allocation.
///
/// An ArrayContainerControl tag specifies how an ArrayHandle allocates and
/// frees memory. The tag ArrayContainerControlTag___ does not actually exist.
/// Rather, this documentation is provided to describe how array containers are
/// specified. Loading the vtkm/cont/ArrayContainerControl.h header will set a
/// default array container. You can specify the default array container by
/// first setting the VTKM_ARRAY_CONTAINER_CONTROL macro. Currently it can only
/// be set to VTKM_ARRAY_CONTAINER_CONTROL_BASIC.
/// A Storage tag specifies how an ArrayHandle allocates and frees memory. The
/// tag StorageTag___ does not actually exist. Rather, this documentation is
/// provided to describe how array storage objects are specified. Loading the
/// vtkm/cont/Storage.h header will set a default array storage. You can
/// specify the default storage by first setting the VTKM_STORAGE macro.
/// Currently it can only be set to VTKM_STORAGE_BASIC.
///
/// User code external to VTKm is free to make its own ArrayContainerControlTag.
/// This is a good way to get VTKm to read data directly in and out of arrays
/// from other libraries. However, care should be taken when creating an
/// ArrayContainerControl. One particular problem that is likely is a container
/// that "constructs" all the items in the array. If done incorrectly, then
/// memory of the array can be incorrectly bound to the wrong process. If you
/// do provide your own ArrayContainerControlTag, please be diligent in
/// comparing its performance to the ArrayContainerControlTagBasic.
/// User code external to VTK-m is free to make its own StorageTag. This is a
/// good way to get VTK-m to read data directly in and out of arrays from other
/// libraries. However, care should be taken when creating a Storage. One
/// particular problem that is likely is a storage that "constructs" all the
/// items in the array. If done incorrectly, then memory of the array can be
/// incorrectly bound to the wrong processor. If you do provide your own
/// StorageTag, please be diligent in comparing its performance to the
/// StorageTagBasic.
///
/// To implement your own ArrayContainerControlTag, you first must create a tag
/// class (an empty struct) defining your tag (i.e. struct
/// ArrayContainerControlTagMyAlloc { };). Then provide a partial template
/// specialization of vtkm::cont::internal::ArrayContainerControl for your new
/// tag.
/// To implement your own StorageTag, you first must create a tag class (an
/// empty struct) defining your tag (i.e. struct StorageTagMyAlloc { };). Then
/// provide a partial template specialization of vtkm::cont::internal::Storage
/// for your new tag.
///
struct ArrayContainerControlTag___ { };
struct StorageTag___ { };
#endif // VTKM_DOXYGEN_ONLY
namespace internal {
struct UndefinedArrayContainerControl { };
struct UndefinedStorage { };
namespace detail {
// This class should never be used. It is used as a placeholder for undefined
// ArrayContainerControl objects. If you get a compiler error involving this
// object, then it probably comes from trying to use an ArrayHandle with bad
// template arguments.
// Storage objects. If you get a compiler error involving this object, then it
// probably comes from trying to use an ArrayHandle with bad template
// arguments.
template<typename T>
struct UndefinedArrayPortal {
BOOST_STATIC_ASSERT(sizeof(T) == -1);
......@@ -79,14 +77,13 @@ struct UndefinedArrayPortal {
} // namespace detail
/// This templated class must be partially specialized for each
/// ArrayContainerControlTag created, which will define the implementation for
/// that tag.
/// This templated class must be partially specialized for each StorageTag
/// created, which will define the implementation for that tag.
///
template<typename T, class ArrayContainerControlTag>
class ArrayContainerControl
template<typename T, class StorageTag>
class Storage
#ifndef VTKM_DOXYGEN_ONLY
: public vtkm::cont::internal::UndefinedArrayContainerControl
: public vtkm::cont::internal::UndefinedStorage
{
public:
typedef vtkm::cont::internal::detail::UndefinedArrayPortal<T> PortalType;
......@@ -152,7 +149,7 @@ public:
///
/// After calling this method GetNumberOfValues will return 0 and
/// GetIteratorBegin and GetIteratorEnd will return the same iterator. The
/// resources should also be released when the ArrayContainerControl class is
/// resources should also be released when the Storage class is
/// destroyed.
VTKM_CONT_EXPORT
void ReleaseResources();
......@@ -164,27 +161,25 @@ public:
}
} // namespace vtkm::cont
// This is put at the bottom of the header so that the ArrayContainerControl
// template is declared before any implementations are called.
// This is put at the bottom of the header so that the Storage template is
// declared before any implementations are called.
#if VTKM_ARRAY_CONTAINER_CONTROL == VTKM_ARRAY_CONTAINER_CONTROL_BASIC
#if VTKM_STORAGE == VTKM_STORAGE_BASIC
#include <vtkm/cont/ArrayContainerControlBasic.h>
#define VTKM_DEFAULT_ARRAY_CONTAINER_CONTROL_TAG \
::vtkm::cont::ArrayContainerControlTagBasic
#include <vtkm/cont/StorageBasic.h>
#define VTKM_DEFAULT_STORAGE_TAG ::vtkm::cont::StorageTagBasic
#elif VTKM_ARRAY_CONTAINER_CONTROL == VTKM_ARRAY_CONTAINER_CONTROL_ERROR
#elif VTKM_STORAGE == VTKM_STORAGE_ERROR
#include <vtkm/cont/internal/ArrayContainerControlError.h>
#define VTKM_DEFAULT_ARRAY_CONTAINER_CONTROL_TAG \
::vtkm::cont::internal::ArrayContainerControlTagError
#include <vtkm/cont/internal/StorageError.h>
#define VTKM_DEFAULT_STORAGE_TAG ::vtkm::cont::internal::StorageTagError
#elif (VTKM_ARRAY_CONTAINER_CONTROL == VTKM_ARRAY_CONTAINER_CONTROL_UNDEFINED) || !defined(VTKM_ARRAY_CONTAINER_CONTROL)
#elif (VTKM_STORAGE == VTKM_STORAGE_UNDEFINED) || !defined(VTKM_STORAGE)
#ifndef VTKM_DEFAULT_ARRAY_CONTAINER_CONTROL_TAG
#warning If array container for control is undefined, VTKM_DEFAULT_ARRAY_CONTAINER_CONTROL_TAG must be defined.
#ifndef VTKM_DEFAULT_STORAGE_TAG
#warning If array storage is undefined, VTKM_DEFAULT_STORAGE_TAG must be defined.
#endif
#endif
#endif //vtk_m_cont__ArrayContainerControl_h
#endif //vtk_m_cont_Storage_h
......@@ -17,34 +17,35 @@
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#ifndef vtk_m_cont__ArrayContainerControlBasic_h
#define vtk_m_cont__ArrayContainerControlBasic_h
#ifndef vtk_m_cont_StorageBasic_h
#define vtk_m_cont_StorageBasic_h
#include <vtkm/Types.h>
#include <vtkm/cont/ArrayContainerControl.h>
#include <vtkm/cont/Assert.h>
#include <vtkm/cont/ErrorControlBadValue.h>
#include <vtkm/cont/ErrorControlOutOfMemory.h>
#include <vtkm/cont/Storage.h>
#include <vtkm/cont/internal/ArrayPortalFromIterators.h>
namespace vtkm {
namespace cont {
/// A tag for the basic implementation of an ArrayContainerControl object.
struct ArrayContainerControlTagBasic { };
/// A tag for the basic implementation of a Storage object.
struct StorageTagBasic { };
namespace internal {
/// A basic implementation of an ArrayContainerControl object.
/// A basic implementation of an Storage object.
///
/// \todo This container does \em not construct the values within the array.
/// \todo This storage does \em not construct the values within the array.
/// Thus, it is important to not use this class with any type that will fail if
/// not constructed. These are things like basic types (int, float, etc.) and
/// the VTKm Tuple classes. In the future it would be nice to have a compile
/// time check to enforce this.
///
template <typename ValueT>
class ArrayContainerControl<ValueT, vtkm::cont::ArrayContainerControlTagBasic>
class Storage<ValueT, vtkm::cont::StorageTagBasic>
{
public:
typedef ValueT ValueType;
......@@ -54,18 +55,18 @@ public:
private:
/// The original design of this class provided an allocator as a template
/// parameters. That messed things up, though, because other templated
/// classes assume that the \c ArrayContainerControl has one template
/// parameter. There are other ways to allow you to specify the allocator,
/// but it is uncertain whether that would ever be useful. So, instead of
/// jumping through hoops implementing them, just fix the allocator for now.
/// classes assume that the \c Storage has one template parameter. There are
/// other ways to allow you to specify the allocator, but it is uncertain
/// whether that would ever be useful. So, instead of jumping through hoops
/// implementing them, just fix the allocator for now.
///
typedef std::allocator<ValueType> AllocatorType;
public:
ArrayContainerControl() : Array(NULL), NumberOfValues(0), AllocatedSize(0) { }
Storage() : Array(NULL), NumberOfValues(0), AllocatedSize(0) { }
~ArrayContainerControl()
~Storage()
{
this->ReleaseResources();
}
......@@ -152,10 +153,10 @@ public:
///
/// This method returns the pointer to the array held by this array. It then
/// clears the internal array pointer to NULL, thereby ensuring that the
/// ArrayContainerControl will never deallocate the array. This is
/// helpful for taking a reference for an array created internally by VTKm and
/// not having to keep a VTKm object around. Obviously the caller becomes
/// responsible for destroying the memory.
/// Storage will never deallocate the array. This is helpful for taking a
/// reference for an array created internally by VTK-m and not having to keep
/// a VTK-m object around. Obviously the caller becomes responsible for
/// destroying the memory.
///
ValueType *StealArray()
{
......@@ -168,8 +169,8 @@ public:
private:
// Not implemented.
ArrayContainerControl(const ArrayContainerControl<ValueType, ArrayContainerControlTagBasic> &src);
void operator=(const ArrayContainerControl<ValueType, ArrayContainerControlTagBasic> &src);
Storage(const Storage<ValueType, StorageTagBasic> &src);
void operator=(const Storage<ValueType, StorageTagBasic> &src);
ValueType *Array;
vtkm::Id NumberOfValues;
......@@ -181,4 +182,4 @@ private:
}
} // namespace vtkm::cont
#endif //vtk_m_cont__ArrayContainerControlBasic_h
#endif //vtk_m_cont_StorageBasic_h
......@@ -17,14 +17,15 @@
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#ifndef vtk_m_cont_ArrayContainerControlImplicit
#define vtk_m_cont_ArrayContainerControlImplicit
#ifndef vtk_m_cont_StorageImplicit
#define vtk_m_cont_StorageImplicit
#include <vtkm/Types.h>
#include <vtkm/cont/ArrayContainerControl.h>
#include <vtkm/cont/Assert.h>
#include <vtkm/cont/ErrorControlBadValue.h>
#include <vtkm/cont/Storage.h>
#include <vtkm/cont/internal/ArrayTransfer.h>
namespace vtkm {
......@@ -32,19 +33,16 @@ namespace cont {
/// \brief An implementation for read-only implicit arrays.
///
/// It is sometimes the case that you want VTKm to operate on an array of
/// It is sometimes the case that you want VTK-m to operate on an array of
/// implicit values. That is, rather than store the data in an actual array, it
/// is gerenated on the fly by a function. This is handled in VTKm by creating
/// an ArrayHandle in VTKm with an ArrayContainerControlTagImplicit type of
/// ArrayContainerControl. This tag itself is templated to specify an
/// ArrayPortal that generates the desired values. An ArrayHandle created with
/// this tag will raise an error on any operation that tries to modify it.
///
/// \todo The ArrayHandle currently copies the array in cases where the control
/// and environment do not share memory. This is wasteful and should be fixed.
/// is gerenated on the fly by a function. This is handled in VTK-m by creating
/// an ArrayHandle in VTK-m with a StorageTagImplicit type of \c Storage. This
/// tag itself is templated to specify an ArrayPortal that generates the
/// desired values. An ArrayHandle created with this tag will raise an error on
/// any operation that tries to modify it.
///
template<class ArrayPortalType>
struct ArrayContainerControlTagImplicit
struct StorageTagImplicit
{
typedef ArrayPortalType PortalType;
};
......@@ -52,9 +50,9 @@ struct ArrayContainerControlTagImplicit
namespace internal {
template<class ArrayPortalType>
class ArrayContainerControl<
class Storage<
typename ArrayPortalType::ValueType,
ArrayContainerControlTagImplicit<ArrayPortalType> >
StorageTagImplicit<ArrayPortalType> >
{
public:
typedef typename ArrayPortalType::ValueType ValueType;
......@@ -76,18 +74,18 @@ public:
PortalConstType GetPortalConst() const
{
// This does not work because the ArrayHandle holds the constant
// ArrayPortal, not the container.
// ArrayPortal, not the storage.
throw vtkm::cont::ErrorControlBadValue(
"Implicit container does not store array portal. "
"Implicit storage does not store array portal. "
"Perhaps you did not set the ArrayPortal when "
"constructing the ArrayHandle.");
}
vtkm::Id GetNumberOfValues() const
{
// This does not work because the ArrayHandle holds the constant
// ArrayPortal, not the container.
// ArrayPortal, not the Storage.
throw vtkm::cont::ErrorControlBadValue(
"Implicit container does not store array portal. "
"Implicit storage does not store array portal. "
"Perhaps you did not set the ArrayPortal when "
"constructing the ArrayHandle.");
}
......@@ -105,43 +103,18 @@ public:
}
};
//// If you are using this specalization of ArrayContainerControl, it means the
//// type of an ArrayHandle does not match the type of the array portal for the
//// array portal in an implicit array. Currently this use is invalid, but there
//// could be a case for implementing casting where appropriate.
//template<typename T, typename ArrayPortalType>
//class ArrayContainerControl<T, ArrayContainerControlTagImplicit<ArrayPortalType> >
//{
//public:
// // This is meant to be invalid because this class should not actually be used.
// struct PortalType
// {
// typedef void *ValueType;
// typedef void *IteratorType;
// };
// // This is meant to be invalid because this class should not actually be used.
// struct PortalConstType
// {
// typedef void *ValueType;
// typedef void *IteratorType;
// };
//};
template<typename T, class ArrayPortalType, class DeviceAdapterTag>
class ArrayTransfer<
T, ArrayContainerControlTagImplicit<ArrayPortalType>, DeviceAdapterTag>
class ArrayTransfer<T, StorageTagImplicit<ArrayPortalType>, DeviceAdapterTag>
{
private:
typedef ArrayContainerControlTagImplicit<ArrayPortalType>
ArrayContainerControlTag;
typedef vtkm::cont::internal::ArrayContainerControl<T,ArrayContainerControlTag>
ContainerType;
typedef StorageTagImplicit<ArrayPortalType> StorageTag;
typedef vtkm::cont::internal::Storage<T,StorageTag> StorageType;
public:
typedef T ValueType;
typedef typename ContainerType::PortalType PortalControl;
typedef typename ContainerType::PortalConstType PortalConstControl;
typedef typename StorageType::PortalType PortalControl;
typedef typename StorageType::PortalConstType PortalConstControl;
typedef PortalControl PortalExecution;
typedef PortalConstControl PortalConstExecution;
......@@ -159,27 +132,27 @@ public:
this->PortalValid = true;
}
VTKM_CONT_EXPORT void LoadDataForInput(const ContainerType &controlArray)
VTKM_CONT_EXPORT void LoadDataForInput(const StorageType &controlArray)
{
this->LoadDataForInput(controlArray.GetPortalConst());
}
VTKM_CONT_EXPORT
void LoadDataForInPlace(ContainerType &vtkmNotUsed(controlArray))
void LoadDataForInPlace(StorageType &vtkmNotUsed(controlArray))
{
throw vtkm::cont::ErrorControlBadValue(
"Implicit arrays cannot be used for output or in place.");
}
VTKM_CONT_EXPORT void AllocateArrayForOutput(
ContainerType &vtkmNotUsed(controlArray),
StorageType &vtkmNotUsed(controlArray),
vtkm::Id vtkmNotUsed(numberOfValues))
{
throw vtkm::cont::ErrorControlBadValue(
"Implicit arrays cannot be used for output.");
}
VTKM_CONT_EXPORT void RetrieveOutputData(
ContainerType &vtkmNotUsed(controlArray)) const
StorageType &vtkmNotUsed(controlArray)) const
{
throw vtkm::cont::ErrorControlBadValue(
"Implicit arrays cannot be used for output.");
......@@ -213,4 +186,4 @@ private:
}
} // namespace vtkm::cont