vtk-m/vtkm/cont/StorageImplicit.h
Kenneth Moreland 21823500c3 Change ArrayContainerControl to Storage.
After a talk with Robert Maynard, we decided to change the name
ArrayContainerControl to Storage. There are several reasons for this
change.

1. The name ArrayContainerControl is unwieldy. It is long, hard for
humans to parse, and makes for long lines and wraparound. It is also
hard to distinguish from other names like ArrayHandleFoo and
ArrayExecutionManager.

2. The word container is getting overloaded. For example, there is a
SimplePolymorphicContainer. Container is being used for an object that
literally acts like a container for data. This class really manages
data.

3. The data does not necessarily have to be on the control side.
Implicit containers store the data nowhere. Derivative containers might
have all the real data on the execution side. It is possible in the
future to have storage on the execution environment instead of the
control (think interfacing with a simulator on the GPU).

Storage is not a perfect word (what does implicit storage really mean?),
but its the best English word we came up with.
2014-06-24 09:58:32 -06:00

190 lines
5.8 KiB
C++

//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//
// Copyright 2014 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014. Los Alamos National Security
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#ifndef vtk_m_cont_StorageImplicit
#define vtk_m_cont_StorageImplicit
#include <vtkm/Types.h>
#include <vtkm/cont/Assert.h>
#include <vtkm/cont/ErrorControlBadValue.h>
#include <vtkm/cont/Storage.h>
#include <vtkm/cont/internal/ArrayTransfer.h>
namespace vtkm {
namespace cont {
/// \brief An implementation for read-only implicit arrays.
///
/// 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 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 StorageTagImplicit
{
typedef ArrayPortalType PortalType;
};
namespace internal {
template<class ArrayPortalType>
class Storage<
typename ArrayPortalType::ValueType,
StorageTagImplicit<ArrayPortalType> >
{
public:
typedef typename ArrayPortalType::ValueType ValueType;
typedef ArrayPortalType PortalConstType;
// This is meant to be invalid. Because implicit arrays are read only, you
// should only be able to use the const version.
struct PortalType
{
typedef void *ValueType;
typedef void *IteratorType;
};
// All these methods do nothing but raise errors.
PortalType GetPortal()
{
throw vtkm::cont::ErrorControlBadValue("Implicit arrays are read-only.");
}
PortalConstType GetPortalConst() const
{
// This does not work because the ArrayHandle holds the constant
// ArrayPortal, not the storage.
throw vtkm::cont::ErrorControlBadValue(
"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 Storage.
throw vtkm::cont::ErrorControlBadValue(
"Implicit storage does not store array portal. "
"Perhaps you did not set the ArrayPortal when "
"constructing the ArrayHandle.");
}
void Allocate(vtkm::Id vtkmNotUsed(numberOfValues))
{
throw vtkm::cont::ErrorControlBadValue("Implicit arrays are read-only.");
}
void Shrink(vtkm::Id vtkmNotUsed(numberOfValues))
{
throw vtkm::cont::ErrorControlBadValue("Implicit arrays are read-only.");
}
void ReleaseResources()
{
throw vtkm::cont::ErrorControlBadValue("Implicit arrays are read-only.");
}
};
template<typename T, class ArrayPortalType, class DeviceAdapterTag>
class ArrayTransfer<T, StorageTagImplicit<ArrayPortalType>, DeviceAdapterTag>
{
private:
typedef StorageTagImplicit<ArrayPortalType> StorageTag;
typedef vtkm::cont::internal::Storage<T,StorageTag> StorageType;
public:
typedef T ValueType;
typedef typename StorageType::PortalType PortalControl;
typedef typename StorageType::PortalConstType PortalConstControl;
typedef PortalControl PortalExecution;
typedef PortalConstControl PortalConstExecution;
ArrayTransfer() : PortalValid(false) { }
VTKM_CONT_EXPORT vtkm::Id GetNumberOfValues() const
{
VTKM_ASSERT_CONT(this->PortalValid);
return this->Portal.GetNumberOfValues();
}
VTKM_CONT_EXPORT void LoadDataForInput(const PortalConstControl& portal)
{
this->Portal = portal;
this->PortalValid = true;
}
VTKM_CONT_EXPORT void LoadDataForInput(const StorageType &controlArray)
{
this->LoadDataForInput(controlArray.GetPortalConst());
}
VTKM_CONT_EXPORT
void LoadDataForInPlace(StorageType &vtkmNotUsed(controlArray))
{
throw vtkm::cont::ErrorControlBadValue(
"Implicit arrays cannot be used for output or in place.");
}
VTKM_CONT_EXPORT void AllocateArrayForOutput(
StorageType &vtkmNotUsed(controlArray),
vtkm::Id vtkmNotUsed(numberOfValues))
{
throw vtkm::cont::ErrorControlBadValue(
"Implicit arrays cannot be used for output.");
}
VTKM_CONT_EXPORT void RetrieveOutputData(
StorageType &vtkmNotUsed(controlArray)) const
{
throw vtkm::cont::ErrorControlBadValue(
"Implicit arrays cannot be used for output.");
}
VTKM_CONT_EXPORT void Shrink(vtkm::Id vtkmNotUsed(numberOfValues))
{
throw vtkm::cont::ErrorControlBadValue("Implicit arrays cannot be resized.");
}
VTKM_CONT_EXPORT PortalExecution GetPortalExecution()
{
throw vtkm::cont::ErrorControlBadValue(
"Implicit arrays are read-only. (Get the const portal.)");
}
VTKM_CONT_EXPORT PortalConstExecution GetPortalConstExecution() const
{
VTKM_ASSERT_CONT(this->PortalValid);
return this->Portal;
}
VTKM_CONT_EXPORT void ReleaseResources() { }
private:
PortalConstExecution Portal;
bool PortalValid;
};
} // namespace internal
}
} // namespace vtkm::cont
#endif //vtk_m_cont_StorageImplicit