2014-02-10 19:53:03 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2014-02-10 19:53:03 +00:00
|
|
|
// 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.
|
|
|
|
//============================================================================
|
2014-03-07 15:19:09 +00:00
|
|
|
#ifndef vtk_m_cont_internal_ArrayTransfer_h
|
|
|
|
#define vtk_m_cont_internal_ArrayTransfer_h
|
2014-02-10 19:53:03 +00:00
|
|
|
|
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/ArrayManagerExecution.h>
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace cont
|
|
|
|
{
|
|
|
|
namespace internal
|
|
|
|
{
|
2014-02-10 19:53:03 +00:00
|
|
|
|
|
|
|
/// \brief Class that manages the transfer of data between control and execution.
|
|
|
|
///
|
|
|
|
/// This templated class provides a mechanism (used by the ArrayHandle) to
|
|
|
|
/// transfer data from the control environment to the execution environment and
|
|
|
|
/// back. The interface for ArrayTransfer is nearly identical to that of
|
|
|
|
/// ArrayManagerExecution and the default implementation simply delegates all
|
|
|
|
/// calls to that class.
|
|
|
|
///
|
|
|
|
/// The primary motivation for having a separate class is that the
|
|
|
|
/// ArrayManagerExecution is meant to be specialized for each device adapter
|
2014-06-23 23:33:04 +00:00
|
|
|
/// whereas the ArrayTransfer is meant to be specialized for each storage type
|
|
|
|
/// (or specific combination of storage and device adapter). Thus, transfers
|
|
|
|
/// for most storage tyeps will be delegated through the ArrayManagerExecution,
|
|
|
|
/// but some storage types, like implicit storage, will be specialized to
|
|
|
|
/// transfer through a different path.
|
2014-02-10 19:53:03 +00:00
|
|
|
///
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T, class StorageTag, class DeviceAdapterTag>
|
2014-02-10 19:53:03 +00:00
|
|
|
class ArrayTransfer
|
|
|
|
{
|
|
|
|
private:
|
2017-08-10 19:26:05 +00:00
|
|
|
using StorageType = vtkm::cont::internal::Storage<T, StorageTag>;
|
|
|
|
using ArrayManagerType =
|
|
|
|
vtkm::cont::internal::ArrayManagerExecution<T, StorageTag, DeviceAdapterTag>;
|
2014-02-10 19:53:03 +00:00
|
|
|
|
|
|
|
public:
|
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
|
|
|
///
|
2017-06-23 18:50:34 +00:00
|
|
|
using ValueType = T;
|
2014-02-10 19:53:03 +00:00
|
|
|
|
|
|
|
/// An array portal that can be used in the control environment.
|
|
|
|
///
|
2017-06-23 18:50:34 +00:00
|
|
|
using PortalControl = typename StorageType::PortalType;
|
|
|
|
using PortalConstControl = typename StorageType::PortalConstType;
|
2014-02-10 19:53:03 +00:00
|
|
|
|
|
|
|
/// An array portal that can be used in the execution environment.
|
|
|
|
///
|
2017-06-23 18:50:34 +00:00
|
|
|
using PortalExecution = typename ArrayManagerType::PortalType;
|
|
|
|
using PortalConstExecution = typename ArrayManagerType::PortalConstType;
|
2014-02-10 19:53:03 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
ArrayTransfer(StorageType* storage)
|
|
|
|
: ArrayManager(storage)
|
|
|
|
{
|
|
|
|
}
|
2014-02-10 19:53:03 +00:00
|
|
|
|
|
|
|
/// Returns the number of values stored in the array. Results are undefined
|
|
|
|
/// if data has not been loaded or allocated.
|
|
|
|
///
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Id GetNumberOfValues() const { return this->ArrayManager.GetNumberOfValues(); }
|
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 is (or may be) skipped.
|
2014-02-10 19:53:03 +00:00
|
|
|
///
|
2015-05-01 02:47:30 +00:00
|
|
|
/// Returns a constant array portal valid in the execution environment.
|
|
|
|
///
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2015-05-01 02:47:30 +00:00
|
|
|
PortalConstExecution PrepareForInput(bool updateData)
|
2014-02-10 19:53:03 +00:00
|
|
|
{
|
2015-05-01 02:47:30 +00:00
|
|
|
return this->ArrayManager.PrepareForInput(updateData);
|
2014-02-10 19:53:03 +00:00
|
|
|
}
|
|
|
|
|
2015-05-01 02:47:30 +00:00
|
|
|
/// 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 is (or may be)
|
|
|
|
/// skipped.
|
|
|
|
///
|
|
|
|
/// Returns a read-write array portal valid in the execution environment.
|
2014-02-10 19:53:03 +00:00
|
|
|
///
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2015-05-01 02:47:30 +00:00
|
|
|
PortalExecution PrepareForInPlace(bool updateData)
|
2014-02-10 19:53:03 +00:00
|
|
|
{
|
2015-05-01 02:47:30 +00:00
|
|
|
return this->ArrayManager.PrepareForInPlace(updateData);
|
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
|
|
|
///
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2015-05-01 02:47:30 +00:00
|
|
|
PortalExecution PrepareForOutput(vtkm::Id numberOfValues)
|
2014-02-10 19:53:03 +00:00
|
|
|
{
|
2015-05-01 02:47:30 +00:00
|
|
|
return this->ArrayManager.PrepareForOutput(numberOfValues);
|
2014-02-10 19:53:03 +00:00
|
|
|
}
|
|
|
|
|
2014-06-23 23:33:04 +00:00
|
|
|
/// Allocates data in the given Storage and copies data held in the execution
|
2015-05-01 02:47:30 +00:00
|
|
|
/// 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
|
|
|
|
/// called.
|
2014-02-10 19:53:03 +00:00
|
|
|
///
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
void RetrieveOutputData(StorageType* storage) const
|
2014-02-10 19:53:03 +00:00
|
|
|
{
|
2015-04-28 00:50:45 +00:00
|
|
|
this->ArrayManager.RetrieveOutputData(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.
|
|
|
|
///
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
void Shrink(vtkm::Id numberOfValues) { this->ArrayManager.Shrink(numberOfValues); }
|
2014-02-10 19:53:03 +00:00
|
|
|
|
|
|
|
/// Frees any resources (i.e. memory) allocated for the exeuction
|
|
|
|
/// environment, if any.
|
|
|
|
///
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
void ReleaseResources() { this->ArrayManager.ReleaseResources(); }
|
2014-02-10 19:53:03 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
ArrayManagerType ArrayManager;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace vtkm::cont::internal
|
|
|
|
|
2014-06-11 16:43:36 +00:00
|
|
|
#endif //vtk_m_cont_internal_ArrayTransfer_h
|