2014-02-10 19:53:03 +00:00
|
|
|
//============================================================================
|
|
|
|
// 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.
|
2015-05-21 12:09:22 +00:00
|
|
|
// Copyright 2014 Los Alamos National Security.
|
2014-02-10 19:53:03 +00:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//============================================================================
|
2014-03-07 15:19:09 +00:00
|
|
|
#ifndef vtk_m_cont_exec_ArrayHandleExecutionManager_h
|
|
|
|
#define vtk_m_cont_exec_ArrayHandleExecutionManager_h
|
2014-02-10 19:53:03 +00:00
|
|
|
|
|
|
|
#include <vtkm/cont/ErrorControlInternal.h>
|
2014-06-23 23:33:04 +00:00
|
|
|
#include <vtkm/cont/Storage.h>
|
|
|
|
|
2014-02-10 19:53:03 +00:00
|
|
|
#include <vtkm/cont/internal/ArrayTransfer.h>
|
|
|
|
|
|
|
|
namespace vtkm {
|
|
|
|
namespace cont {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
/// The common base for ArrayHandleExecutionManager. This is the interface
|
|
|
|
/// used when the type of the device is not known at run time.
|
|
|
|
///
|
2014-06-23 23:33:04 +00:00
|
|
|
template<typename T, typename Storage>
|
2014-02-10 19:53:03 +00:00
|
|
|
class ArrayHandleExecutionManagerBase
|
|
|
|
{
|
|
|
|
private:
|
2014-06-23 23:33:04 +00:00
|
|
|
typedef vtkm::cont::internal::Storage<T,Storage> StorageType;
|
2014-02-10 19:53:03 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
template <typename DeviceAdapter>
|
2014-02-11 21:20:30 +00:00
|
|
|
struct ExecutionTypes
|
|
|
|
{
|
2014-02-10 19:53:03 +00:00
|
|
|
private:
|
2014-06-23 23:33:04 +00:00
|
|
|
typedef vtkm::cont::internal::ArrayTransfer<T,Storage,DeviceAdapter>
|
2014-02-10 19:53:03 +00:00
|
|
|
ArrayTransferType;
|
|
|
|
public:
|
|
|
|
typedef typename ArrayTransferType::PortalExecution Portal;
|
|
|
|
typedef typename ArrayTransferType::PortalConstExecution PortalConst;
|
|
|
|
};
|
|
|
|
|
2014-12-10 15:38:03 +00:00
|
|
|
/// The type of value held in the array (vtkm::FloatDefault, vtkm::Vec, etc.)
|
2014-02-10 19:53:03 +00:00
|
|
|
///
|
|
|
|
typedef T ValueType;
|
|
|
|
|
|
|
|
/// An array portal that can be used in the control environment.
|
|
|
|
///
|
2014-06-23 23:33:04 +00:00
|
|
|
typedef typename StorageType::PortalType PortalControl;
|
|
|
|
typedef typename StorageType::PortalConstType PortalConstControl;
|
2014-02-10 19:53:03 +00:00
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
virtual ~ArrayHandleExecutionManagerBase() { }
|
|
|
|
|
|
|
|
/// Returns the number of values stored in the array. Results are undefined
|
|
|
|
/// if data has not been loaded or allocated.
|
|
|
|
///
|
2015-05-01 02:47:30 +00:00
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
vtkm::Id GetNumberOfValues() const {
|
|
|
|
return this->GetNumberOfValuesImpl();
|
|
|
|
}
|
2014-02-10 19:53:03 +00:00
|
|
|
|
2015-05-01 02:47:30 +00:00
|
|
|
/// Prepares the data for use as input in the execution environment. If the
|
|
|
|
/// flag \c updateData is true, then data is transferred to the execution
|
|
|
|
/// environment. Otherwise, this transfer should be skipped.
|
|
|
|
///
|
|
|
|
/// Returns a constant array portal valid in the execution environment.
|
2014-02-10 19:53:03 +00:00
|
|
|
///
|
2015-05-01 02:47:30 +00:00
|
|
|
template<typename DeviceAdapter>
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
typename ExecutionTypes<DeviceAdapter>::PortalConst
|
|
|
|
PrepareForInput(bool updateData, DeviceAdapter) {
|
|
|
|
this->VerifyDeviceAdapter(DeviceAdapter());
|
2014-02-10 19:53:03 +00:00
|
|
|
|
2015-05-01 02:47:30 +00:00
|
|
|
typename ExecutionTypes<DeviceAdapter>::PortalConst portal;
|
|
|
|
this->PrepareForInputImpl(updateData, &portal);
|
|
|
|
return portal;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Prepares the data for use as both input and output in the execution
|
|
|
|
/// environment. If the flag \c updateData is true, then data is transferred
|
|
|
|
/// to the execution environment. Otherwise, this transfer should be skipped.
|
|
|
|
///
|
|
|
|
/// Returns a read-write array portal valid in the execution environment.
|
2014-02-10 19:53:03 +00:00
|
|
|
///
|
2015-05-01 02:47:30 +00:00
|
|
|
template<typename DeviceAdapter>
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
typename ExecutionTypes<DeviceAdapter>::Portal
|
|
|
|
PrepareForInPlace(bool updateData, DeviceAdapter) {
|
|
|
|
this->VerifyDeviceAdapter(DeviceAdapter());
|
|
|
|
|
|
|
|
typename ExecutionTypes<DeviceAdapter>::Portal portal;
|
|
|
|
this->PrepareForInPlaceImpl(updateData, &portal);
|
|
|
|
return portal;
|
|
|
|
}
|
2014-02-10 19:53:03 +00:00
|
|
|
|
2014-06-23 23:33:04 +00:00
|
|
|
/// Allocates an array in the execution environment of the specified size. If
|
|
|
|
/// control and execution share arrays, then this class can allocate data
|
2015-05-01 02:47:30 +00:00
|
|
|
/// using the given Storage it can be used directly in the execution
|
|
|
|
/// environment.
|
|
|
|
///
|
|
|
|
/// Returns a writable array portal valid in the execution environment.
|
2014-02-10 19:53:03 +00:00
|
|
|
///
|
2015-05-01 02:47:30 +00:00
|
|
|
template<typename DeviceAdapter>
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
typename ExecutionTypes<DeviceAdapter>::Portal
|
|
|
|
PrepareForOutput(vtkm::Id numberOfValues, DeviceAdapter) {
|
|
|
|
this->VerifyDeviceAdapter(DeviceAdapter());
|
|
|
|
|
|
|
|
typename ExecutionTypes<DeviceAdapter>::Portal portal;
|
|
|
|
this->PrepareForOutputImpl(numberOfValues, &portal);
|
|
|
|
return portal;
|
|
|
|
}
|
2014-02-10 19:53:03 +00:00
|
|
|
|
2015-05-01 02:47:30 +00:00
|
|
|
/// Allocates data in the given Storage and copies data held in the execution
|
|
|
|
/// environment (managed by this class) into the storage object. The
|
|
|
|
/// reference to the storage given is the same as that passed to the
|
|
|
|
/// constructor. If control and execution share arrays, this can be no
|
|
|
|
/// operation. This method should only be called after PrepareForOutput is
|
2014-02-10 19:53:03 +00:00
|
|
|
/// called.
|
|
|
|
///
|
2015-05-01 02:47:30 +00:00
|
|
|
VTKM_CONT_EXPORT
|
2015-05-01 03:29:58 +00:00
|
|
|
void RetrieveOutputData(StorageType *storage) const {
|
2015-05-01 02:47:30 +00:00
|
|
|
this->RetrieveOutputDataImpl(storage);
|
|
|
|
}
|
2014-02-10 19:53:03 +00:00
|
|
|
|
|
|
|
/// \brief Reduces the size of the array without changing its values.
|
|
|
|
///
|
|
|
|
/// This method allows you to resize the array without reallocating it. The
|
|
|
|
/// number of entries in the array is changed to \c numberOfValues. The data
|
|
|
|
/// in the array (from indices 0 to \c numberOfValues - 1) are the same, but
|
|
|
|
/// \c numberOfValues must be equal or less than the preexisting size
|
|
|
|
/// (returned from GetNumberOfValues). That is, this method can only be used
|
|
|
|
/// to shorten the array, not lengthen.
|
|
|
|
///
|
|
|
|
VTKM_CONT_EXPORT
|
2015-05-01 02:47:30 +00:00
|
|
|
void Shrink(vtkm::Id numberOfValues) {
|
|
|
|
this->ShrinkImpl(numberOfValues);
|
2014-02-10 19:53:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Frees any resources (i.e. memory) allocated for the exeuction
|
|
|
|
/// environment, if any.
|
|
|
|
///
|
2015-05-01 02:47:30 +00:00
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
void ReleaseResources() {
|
|
|
|
this->ReleaseResourcesImpl();
|
|
|
|
}
|
2014-02-10 19:53:03 +00:00
|
|
|
|
|
|
|
template<typename DeviceAdapter>
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
bool IsDeviceAdapter(DeviceAdapter) const
|
|
|
|
{
|
|
|
|
return this->IsDeviceAdapterImpl(
|
2015-12-01 20:39:15 +00:00
|
|
|
vtkm::cont::DeviceAdapterTraits<DeviceAdapter>::GetId());
|
2014-02-10 19:53:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-05-01 02:47:30 +00:00
|
|
|
virtual vtkm::Id GetNumberOfValuesImpl() const = 0;
|
|
|
|
|
|
|
|
virtual void PrepareForInputImpl(bool updateData,
|
|
|
|
void *portalExecutionVoid) = 0;
|
|
|
|
|
|
|
|
virtual void PrepareForInPlaceImpl(bool updateData,
|
|
|
|
void *portalExecutionVoid) = 0;
|
2014-02-10 19:53:03 +00:00
|
|
|
|
2015-05-01 02:47:30 +00:00
|
|
|
virtual void PrepareForOutputImpl(vtkm::Id numberOfValues,
|
|
|
|
void *portalExecution) = 0;
|
|
|
|
|
2015-05-01 03:29:58 +00:00
|
|
|
virtual void RetrieveOutputDataImpl(StorageType *storage) const = 0;
|
2015-05-01 02:47:30 +00:00
|
|
|
|
|
|
|
virtual void ShrinkImpl(Id numberOfValues) = 0;
|
|
|
|
|
|
|
|
virtual void ReleaseResourcesImpl() = 0;
|
2014-02-10 19:53:03 +00:00
|
|
|
|
|
|
|
virtual bool IsDeviceAdapterImpl(
|
2015-12-01 20:39:15 +00:00
|
|
|
const vtkm::cont::DeviceAdapterId &id) const = 0;
|
2014-02-10 19:53:03 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
template<typename DeviceAdapter>
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
void VerifyDeviceAdapter(DeviceAdapter device) const
|
|
|
|
{
|
|
|
|
if (!this->IsDeviceAdapter(device))
|
2014-02-11 21:20:30 +00:00
|
|
|
{
|
2014-02-10 19:53:03 +00:00
|
|
|
throw vtkm::cont::ErrorControlInternal("Device Adapter Mismatch");
|
2014-02-11 21:20:30 +00:00
|
|
|
}
|
2014-02-10 19:53:03 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// \brief Used by ArrayHandle to manage execution arrays
|
|
|
|
///
|
|
|
|
/// This is an internal class used by ArrayHandle to manage execution arrays.
|
|
|
|
/// This class uses virtual method polymorphism to allocate and transfer data
|
|
|
|
/// in the execution environment. This virtual method polymorphism allows the
|
|
|
|
/// ArrayHandle to change its device at run time.
|
|
|
|
///
|
|
|
|
template<typename T,
|
2014-06-23 23:33:04 +00:00
|
|
|
typename Storage,
|
2014-02-10 19:53:03 +00:00
|
|
|
typename DeviceAdapter>
|
|
|
|
class ArrayHandleExecutionManager
|
2014-06-23 23:33:04 +00:00
|
|
|
: public ArrayHandleExecutionManagerBase<T, Storage>
|
2014-02-10 19:53:03 +00:00
|
|
|
{
|
2014-06-23 23:33:04 +00:00
|
|
|
typedef ArrayHandleExecutionManagerBase<T, Storage> Superclass;
|
|
|
|
typedef vtkm::cont::internal::ArrayTransfer<T,Storage,DeviceAdapter>
|
2014-02-10 19:53:03 +00:00
|
|
|
ArrayTransferType;
|
2014-06-23 23:33:04 +00:00
|
|
|
typedef vtkm::cont::internal::Storage<T,Storage> StorageType;
|
2014-02-10 19:53:03 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
typedef typename ArrayTransferType::PortalControl PortalControl;
|
|
|
|
typedef typename ArrayTransferType::PortalConstControl PortalConstControl;
|
|
|
|
|
2015-05-01 02:47:30 +00:00
|
|
|
typedef typename ArrayTransferType::PortalExecution PortalExecution;
|
|
|
|
typedef typename ArrayTransferType::PortalConstExecution PortalConstExecution;
|
|
|
|
|
2014-02-10 19:53:03 +00:00
|
|
|
VTKM_CONT_EXPORT
|
2015-05-01 03:29:58 +00:00
|
|
|
ArrayHandleExecutionManager(StorageType *storage)
|
2015-05-01 02:47:30 +00:00
|
|
|
: Transfer(storage) { }
|
|
|
|
|
2015-07-31 10:58:05 +00:00
|
|
|
template<class IteratorTypeControl>
|
|
|
|
VTKM_CONT_EXPORT void CopyInto(IteratorTypeControl dest) const
|
|
|
|
{
|
|
|
|
this->Transfer.CopyInto(dest);
|
|
|
|
}
|
|
|
|
|
2015-05-01 02:47:30 +00:00
|
|
|
protected:
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
vtkm::Id GetNumberOfValuesImpl() const
|
2014-02-10 19:53:03 +00:00
|
|
|
{
|
|
|
|
return this->Transfer.GetNumberOfValues();
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
2015-05-01 02:47:30 +00:00
|
|
|
void PrepareForInputImpl(bool updateData, void *portalExecutionVoid)
|
2014-02-10 19:53:03 +00:00
|
|
|
{
|
2015-05-01 02:47:30 +00:00
|
|
|
PortalConstExecution portal = this->Transfer.PrepareForInput(updateData);
|
|
|
|
*reinterpret_cast<PortalConstExecution *>(portalExecutionVoid) = portal;
|
2014-02-10 19:53:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
2015-05-01 02:47:30 +00:00
|
|
|
void PrepareForInPlaceImpl(bool updateData, void *portalExecutionVoid)
|
2014-02-10 19:53:03 +00:00
|
|
|
{
|
2015-05-01 02:47:30 +00:00
|
|
|
PortalExecution portal = this->Transfer.PrepareForInPlace(updateData);
|
|
|
|
*reinterpret_cast<PortalExecution *>(portalExecutionVoid) = portal;
|
2014-02-10 19:53:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
2015-05-01 02:47:30 +00:00
|
|
|
void PrepareForOutputImpl(vtkm::Id numberOfValues, void *portalExecutionVoid)
|
2014-02-10 19:53:03 +00:00
|
|
|
{
|
2015-05-01 02:47:30 +00:00
|
|
|
PortalExecution portal = this->Transfer.PrepareForOutput(numberOfValues);
|
|
|
|
*reinterpret_cast<PortalExecution *>(portalExecutionVoid) = portal;
|
2014-02-10 19:53:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
2015-05-01 03:29:58 +00:00
|
|
|
void RetrieveOutputDataImpl(StorageType *storage) const
|
2014-02-10 19:53:03 +00:00
|
|
|
{
|
2015-04-28 00:50:45 +00:00
|
|
|
this->Transfer.RetrieveOutputData(storage);
|
2014-02-10 19:53:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
2015-05-01 02:47:30 +00:00
|
|
|
void ShrinkImpl(Id numberOfValues)
|
2014-02-10 19:53:03 +00:00
|
|
|
{
|
|
|
|
this->Transfer.Shrink(numberOfValues);
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
2015-05-01 02:47:30 +00:00
|
|
|
void ReleaseResourcesImpl()
|
2014-02-10 19:53:03 +00:00
|
|
|
{
|
|
|
|
this->Transfer.ReleaseResources();
|
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
bool IsDeviceAdapterImpl(const DeviceAdapterId &id) const
|
|
|
|
{
|
2015-12-01 20:39:15 +00:00
|
|
|
return id == vtkm::cont::DeviceAdapterTraits<DeviceAdapter>::GetId();
|
2014-02-10 19:53:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ArrayTransferType Transfer;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace vtkm::cont::internal
|
|
|
|
|
2014-06-11 16:43:36 +00:00
|
|
|
#endif //vtk_m_cont_exec_ArrayHandleExecutionManager_h
|