56bec1dd7b
This encapsulates a lot of the required memory management into the Buffer object and related code. Many now unneeded classes were deleted.
111 lines
3.1 KiB
C++
111 lines
3.1 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.
|
|
//============================================================================
|
|
#ifndef vtk_m_cont_internal_ArrayManagerExecutionShareWithControl_h
|
|
#define vtk_m_cont_internal_ArrayManagerExecutionShareWithControl_h
|
|
|
|
#include <vtkm/Assert.h>
|
|
#include <vtkm/Types.h>
|
|
|
|
#include <vtkm/cont/ArrayHandle.h>
|
|
#include <vtkm/cont/Storage.h>
|
|
|
|
#include <algorithm>
|
|
|
|
namespace vtkm
|
|
{
|
|
namespace cont
|
|
{
|
|
namespace internal
|
|
{
|
|
|
|
/// \c ArrayManagerExecutionShareWithControl provides an implementation for a
|
|
/// \c ArrayManagerExecution class for a device adapter when the execution
|
|
/// and control environments share memory. This class basically defers all its
|
|
/// calls to a \c Storage class and uses the array allocated there.
|
|
///
|
|
template <typename T, class StorageTag>
|
|
class ArrayManagerExecutionShareWithControl
|
|
{
|
|
public:
|
|
using ValueType = T;
|
|
using StorageType = vtkm::cont::internal::Storage<ValueType, StorageTag>;
|
|
using PortalType = typename StorageType::PortalType;
|
|
using PortalConstType = typename StorageType::PortalConstType;
|
|
|
|
VTKM_CONT
|
|
ArrayManagerExecutionShareWithControl(StorageType* storage)
|
|
: Storage(storage)
|
|
{
|
|
}
|
|
|
|
/// Returns the size of the storage.
|
|
///
|
|
VTKM_CONT
|
|
vtkm::Id GetNumberOfValues() const { return this->Storage->GetNumberOfValues(); }
|
|
|
|
/// Returns the constant portal from the storage.
|
|
///
|
|
VTKM_CONT
|
|
PortalConstType PrepareForInput(bool vtkmNotUsed(uploadData), vtkm::cont::Token&) const
|
|
{
|
|
return this->Storage->GetPortalConst();
|
|
}
|
|
|
|
/// Returns the read-write portal from the storage.
|
|
///
|
|
VTKM_CONT
|
|
PortalType PrepareForInPlace(bool vtkmNotUsed(uploadData), vtkm::cont::Token&)
|
|
{
|
|
return this->Storage->GetPortal();
|
|
}
|
|
|
|
/// Allocates data in the storage and return the portal to that.
|
|
///
|
|
VTKM_CONT
|
|
PortalType PrepareForOutput(vtkm::Id numberOfValues, vtkm::cont::Token&)
|
|
{
|
|
this->Storage->Allocate(numberOfValues);
|
|
return this->Storage->GetPortal();
|
|
}
|
|
|
|
/// This method is a no-op (except for a few checks). Any data written to
|
|
/// this class's portals should already be written to the given \c
|
|
/// controlArray (under correct operation).
|
|
///
|
|
VTKM_CONT
|
|
void RetrieveOutputData(StorageType* storage) const
|
|
{
|
|
(void)storage;
|
|
VTKM_ASSERT(storage == this->Storage);
|
|
}
|
|
|
|
/// Shrinks the storage.
|
|
///
|
|
VTKM_CONT
|
|
void Shrink(vtkm::Id numberOfValues) { this->Storage->Shrink(numberOfValues); }
|
|
|
|
/// A no-op.
|
|
///
|
|
VTKM_CONT
|
|
void ReleaseResources() {}
|
|
|
|
private:
|
|
ArrayManagerExecutionShareWithControl(ArrayManagerExecutionShareWithControl<T, StorageTag>&) =
|
|
delete;
|
|
void operator=(ArrayManagerExecutionShareWithControl<T, StorageTag>&) = delete;
|
|
|
|
StorageType* Storage;
|
|
};
|
|
}
|
|
}
|
|
} // namespace vtkm::cont::internal
|
|
|
|
#endif //vtk_m_cont_internal_ArrayManagerExecutionShareWithControl_h
|