Remove ArrayManagerExecution

This class was used indirectly by the old `ArrayHandle`, through
`ArrayHandleTransfer`, to move data to and from a device. This
functionality has been replaced in the new `ArrayHandle`s through the
`Buffer` class (which can be compiled into libraries rather than make
every translation unit compile their own template).

This commit removes `ArrayManagerExecution` and all the implementations
that the device adapters were required to make. None of this code was in
any use anymore.
This commit is contained in:
Kenneth Moreland 2020-12-08 13:18:44 -07:00
parent 1968590232
commit 90050b96e4
28 changed files with 1 additions and 974 deletions

@ -16,7 +16,6 @@
#include <vtkm/cont/ExecutionObjectBase.h>
#include <vtkm/cont/Token.h>
#include <vtkm/cont/TryExecute.h>
#include <vtkm/cont/internal/ArrayManagerExecution.h>
namespace vtkm

@ -23,7 +23,6 @@
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
#include <vtkm/cont/DeviceAdapterTag.h>
#include <vtkm/cont/internal/ArrayManagerExecution.h>
#include <vtkm/cont/internal/DeviceAdapterMemoryManager.h>
// clang-format on
@ -59,9 +58,6 @@ namespace cont
///
/// To execute algorithms on any device, see Algorithm.h which allows
/// for abitrary device execution.
/// See the ArrayManagerExecution.h and DeviceAdapterAlgorithm.h files for
/// documentation on all the functions and classes that must be
/// overloaded/specialized to create a new device adapter.
///
struct DeviceAdapterTag___
{

@ -14,7 +14,6 @@
#include <vtkm/cont/DeviceAdapterTag.h>
#include <vtkm/cont/Logging.h>
#include <vtkm/cont/internal/ArrayManagerExecution.h>
#ifdef _WIN32

@ -20,7 +20,6 @@
//in the correct order
#include <vtkm/exec/cuda/internal/ThrustPatches.h>
#include <vtkm/cont/cuda/internal/ArrayManagerExecutionCuda.h>
#include <vtkm/cont/cuda/internal/DeviceAdapterAlgorithmCuda.h>
#include <vtkm/cont/cuda/internal/DeviceAdapterMemoryManagerCuda.h>
#include <vtkm/cont/cuda/internal/VirtualObjectTransferCuda.h>

@ -1,271 +0,0 @@
//============================================================================
// 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_cuda_internal_ArrayManagerExecutionCuda_h
#define vtk_m_cont_cuda_internal_ArrayManagerExecutionCuda_h
#include <vtkm/cont/cuda/ErrorCuda.h>
#include <vtkm/cont/cuda/internal/CudaAllocator.h>
#include <vtkm/cont/cuda/internal/DeviceAdapterTagCuda.h>
#include <vtkm/cont/cuda/internal/ThrustExceptionHandler.h>
#include <vtkm/exec/cuda/internal/ArrayPortalFromThrust.h>
#include <vtkm/cont/internal/ArrayManagerExecution.h>
#include <vtkm/cont/ArrayPortalToIterators.h>
#include <vtkm/cont/ErrorBadAllocation.h>
#include <vtkm/cont/Logging.h>
#include <vtkm/cont/Storage.h>
#include <vtkm/exec/cuda/internal/ThrustPatches.h>
VTKM_THIRDPARTY_PRE_INCLUDE
#include <thrust/copy.h>
#include <thrust/device_ptr.h>
VTKM_THIRDPARTY_POST_INCLUDE
#include <limits>
// These must be placed in the vtkm::cont::internal namespace so that
// the template can be found.
namespace vtkm
{
namespace cont
{
namespace internal
{
template <typename T, class StorageTag>
class ArrayManagerExecution<T, StorageTag, vtkm::cont::DeviceAdapterTagCuda>
{
public:
using ValueType = T;
using PointerType = T*;
using PortalType = vtkm::exec::cuda::internal::ArrayPortalFromThrust<T>;
using PortalConstType = vtkm::exec::cuda::internal::ConstArrayPortalFromThrust<T>;
using StorageType = vtkm::cont::internal::Storage<ValueType, StorageTag>;
using difference_type = std::ptrdiff_t;
VTKM_CONT
ArrayManagerExecution(StorageType* storage)
: Storage(storage)
, Begin(nullptr)
, End(nullptr)
, Capacity(nullptr)
{
}
VTKM_CONT
~ArrayManagerExecution() { this->ReleaseResources(); }
/// Returns the size of the array.
///
VTKM_CONT
vtkm::Id GetNumberOfValues() const { return static_cast<vtkm::Id>(this->End - this->Begin); }
VTKM_CONT
PortalConstType PrepareForInput(bool updateData, vtkm::cont::Token&)
{
try
{
if (updateData)
{
this->CopyToExecution();
}
return PortalConstType(this->Begin, this->End);
}
catch (vtkm::cont::ErrorBadAllocation& error)
{
// Thrust does not seem to be clearing the CUDA error, so do it here.
cudaError_t cudaError = cudaPeekAtLastError();
if (cudaError == cudaErrorMemoryAllocation)
{
cudaGetLastError();
}
throw error;
}
}
VTKM_CONT
PortalType PrepareForInPlace(bool updateData, vtkm::cont::Token&)
{
try
{
if (updateData)
{
this->CopyToExecution();
}
return PortalType(this->Begin, this->End);
}
catch (vtkm::cont::ErrorBadAllocation& error)
{
// Thrust does not seem to be clearing the CUDA error, so do it here.
cudaError_t cudaError = cudaPeekAtLastError();
if (cudaError == cudaErrorMemoryAllocation)
{
cudaGetLastError();
}
throw error;
}
}
VTKM_CONT
PortalType PrepareForOutput(vtkm::Id numberOfValues, vtkm::cont::Token&)
{
try
{
// Can we reuse the existing buffer?
vtkm::Id curCapacity =
this->Begin != nullptr ? static_cast<vtkm::Id>(this->Capacity - this->Begin) : 0;
// Just mark a new end if we don't need to increase the allocation:
if (curCapacity >= numberOfValues)
{
this->End = this->Begin + static_cast<difference_type>(numberOfValues);
return PortalType(this->Begin, this->End);
}
const std::size_t maxNumVals = (std::numeric_limits<std::size_t>::max() / sizeof(ValueType));
if (static_cast<std::size_t>(numberOfValues) > maxNumVals)
{
VTKM_LOG_F(vtkm::cont::LogLevel::MemExec,
"Refusing to allocate CUDA memory; number of values (%llu) exceeds "
"std::size_t capacity.",
static_cast<vtkm::UInt64>(numberOfValues));
std::ostringstream err;
err << "Failed to allocate " << numberOfValues << " values on device: "
<< "Number of bytes is not representable by std::size_t.";
throw vtkm::cont::ErrorBadAllocation(err.str());
}
this->ReleaseResources();
const std::size_t bufferSize = static_cast<std::size_t>(numberOfValues) * sizeof(ValueType);
// Attempt to allocate:
try
{
this->Begin =
static_cast<ValueType*>(vtkm::cont::cuda::internal::CudaAllocator::Allocate(bufferSize));
}
catch (const std::exception& error)
{
std::ostringstream err;
err << "Failed to allocate " << bufferSize << " bytes on device: " << error.what();
throw vtkm::cont::ErrorBadAllocation(err.str());
}
this->Capacity = this->Begin + static_cast<difference_type>(numberOfValues);
this->End = this->Capacity;
return PortalType(this->Begin, this->End);
}
catch (vtkm::cont::ErrorBadAllocation& error)
{
// Thrust does not seem to be clearing the CUDA error, so do it here.
cudaError_t cudaError = cudaPeekAtLastError();
if (cudaError == cudaErrorMemoryAllocation)
{
cudaGetLastError();
}
throw error;
}
}
/// Allocates enough space in \c storage and copies the data in the
/// device vector into it.
///
VTKM_CONT
void RetrieveOutputData(StorageType* storage) const
{
storage->Allocate(this->GetNumberOfValues());
VTKM_LOG_F(vtkm::cont::LogLevel::MemTransfer,
"Copying CUDA dev --> host: %s",
vtkm::cont::GetSizeString(this->End - this->Begin).c_str());
try
{
::thrust::copy(thrust::cuda::pointer<ValueType>(this->Begin),
thrust::cuda::pointer<ValueType>(this->End),
vtkm::cont::ArrayPortalToIteratorBegin(storage->GetPortal()));
}
catch (...)
{
vtkm::cont::cuda::internal::throwAsVTKmException();
}
}
/// Resizes the device vector.
///
VTKM_CONT void Shrink(vtkm::Id numberOfValues)
{
// The operation will succeed even if this assertion fails, but this
// is still supposed to be a precondition to Shrink.
VTKM_ASSERT(this->Begin != nullptr && this->Begin + numberOfValues <= this->End);
this->End = this->Begin + static_cast<difference_type>(numberOfValues);
}
/// Frees all memory.
///
VTKM_CONT void ReleaseResources()
{
if (this->Begin != nullptr)
{
vtkm::cont::cuda::internal::CudaAllocator::Free(this->Begin);
this->Begin = nullptr;
this->End = nullptr;
this->Capacity = nullptr;
}
}
private:
ArrayManagerExecution(ArrayManagerExecution&) = delete;
void operator=(ArrayManagerExecution&) = delete;
StorageType* Storage;
PointerType Begin;
PointerType End;
PointerType Capacity;
VTKM_CONT
void CopyToExecution()
{
try
{
vtkm::cont::Token token;
this->PrepareForOutput(this->Storage->GetNumberOfValues(), token);
VTKM_LOG_F(vtkm::cont::LogLevel::MemTransfer,
"Copying host --> CUDA dev: %s.",
vtkm::cont::GetSizeString(this->End - this->Begin).c_str());
::thrust::copy(vtkm::cont::ArrayPortalToIteratorBegin(this->Storage->GetPortalConst()),
vtkm::cont::ArrayPortalToIteratorEnd(this->Storage->GetPortalConst()),
thrust::cuda::pointer<ValueType>(this->Begin));
}
catch (...)
{
vtkm::cont::cuda::internal::throwAsVTKmException();
}
}
};
} // namespace internal
}
} // namespace vtkm::cont
#endif //vtk_m_cont_cuda_internal_ArrayManagerExecutionCuda_h

@ -9,7 +9,6 @@
##============================================================================
set(headers
ArrayManagerExecutionCuda.h
CudaAllocator.h
DeviceAdapterAlgorithmCuda.h
DeviceAdapterMemoryManagerCuda.h

@ -1,144 +0,0 @@
//============================================================================
// 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_ArrayManagerExecution_h
#define vtk_m_cont_internal_ArrayManagerExecution_h
#include <vtkm/cont/DeviceAdapterTag.h>
#include <vtkm/cont/Token.h>
namespace vtkm
{
namespace cont
{
namespace internal
{
/// \brief Class that manages data in the execution environment.
///
/// This templated class must be partially specialized for each
/// DeviceAdapterTag created, which will define the implementation for that tag.
///
/// This is a class that is responsible for allocating data in the execution
/// environment and copying data back and forth between control and
/// execution. It is also expected that this class will automatically release
/// any resources in its destructor.
///
/// This class typically takes on one of two forms. If the control and
/// execution environments have separate memory spaces, then this class
/// behaves how you would expect. It allocates/deallocates arrays and copies
/// data. However, if the control and execution environments share the same
/// memory space, this class should delegate all its operations to the
/// \c Storage. The latter can probably be implemented with a
/// trivial subclass of
/// vtkm::cont::internal::ArrayManagerExecutionShareWithControl.
///
template <typename T, class StorageTag, class DeviceAdapterTag>
class ArrayManagerExecution
#ifdef VTKM_DOXYGEN_ONLY
{
private:
using StorageType = vtkm::cont::internal::Storage<T, StorageTag>;
public:
/// The type of value held in the array (vtkm::FloatDefault, vtkm::Vec, etc.)
///
using ValueType = T;
/// An array portal that can be used in the execution environment to access
/// portions of the arrays. This example defines the portal with a pointer,
/// but any portal with methods that can be called and data that can be
/// accessed from the execution environment can be used.
///
using PortalType = vtkm::exec::internal::ArrayPortalFromIterators<ValueType*>;
/// Const version of PortalType. You must be able to cast PortalType to
/// PortalConstType.
///
using PortalConstType = vtkm::exec::internal::ArrayPortalFromIterators<const ValueType*>;
/// All ArrayManagerExecution classes must have a constructor that takes a
/// storage reference. The reference may be saved (and will remain valid
/// throughout the life of the ArrayManagerExecution). Copying storage
/// objects should be avoided (copy references or pointers only). The
/// reference can also, of course, be ignored.
///
VTKM_CONT
ArrayManagerExecution(vtkm::cont::internal::Storage<T, StorageTag>& storage);
/// Returns the number of values stored in the array. Results are undefined
/// if data has not been loaded or allocated.
///
VTKM_CONT
vtkm::Id GetNumberOfValues() const;
/// 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.
///
VTKM_CONT
PortalConstExecution PrepareForInput(bool updateData);
/// 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.
///
VTKM_CONT
PortalExecution LoadDataForInPlace(bool updateData);
/// Allocates an array in the execution environment of the specified size. If
/// control and execution share arrays, then this class can allocate data
/// using the given Storage it can be used directly in the execution
/// environment.
///
/// Returns a writable array portal valid in the execution environment.
///
VTKM_CONT
PortalExecution PrepareForOutput(vtkm::Id numberOfValues);
/// 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
/// called.
///
VTKM_CONT
void RetrieveOutputData(vtkm::cont::internal::Storage<T, StorageTag>* storage) const;
/// \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
void Shrink(vtkm::Id numberOfValues);
/// Frees any resources (i.e. memory) allocated for the exeuction
/// environment, if any.
///
VTKM_CONT
void ReleaseResources();
};
#else // VTKM_DOXGEN_ONLY
;
#endif // VTKM_DOXYGEN_ONLY
}
}
} // namespace vtkm::cont::internal
#endif //vtk_m_cont_internal_ArrayManagerExecution_h

@ -1,110 +0,0 @@
//============================================================================
// 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

@ -12,7 +12,6 @@
#include <vtkm/cont/Storage.h>
#include <vtkm/cont/Token.h>
#include <vtkm/cont/internal/ArrayManagerExecution.h>
namespace vtkm
{
@ -21,21 +20,7 @@ namespace cont
namespace internal
{
/// \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
/// 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.
/// \brief Class that manages the transfer of data between control and execution (obsolete).
///
template <typename T, class StorageTag, class DeviceAdapterTag>
class ArrayTransfer

@ -10,8 +10,6 @@
set(headers
ArrayHandleExecutionManager.h
ArrayManagerExecution.h
ArrayManagerExecutionShareWithControl.h
ArrayPortalFromIterators.h
ArrayTransfer.h
AtomicInterfaceControl.h

@ -16,7 +16,6 @@
#if !defined(VTKM_KOKKOS_CUDA) || defined(VTKM_CUDA)
#include <vtkm/cont/kokkos/internal/ArrayManagerExecutionKokkos.h>
#include <vtkm/cont/kokkos/internal/DeviceAdapterAlgorithmKokkos.h>
#include <vtkm/cont/kokkos/internal/DeviceAdapterMemoryManagerKokkos.h>
#include <vtkm/cont/kokkos/internal/DeviceAdapterRuntimeDetectorKokkos.h>

@ -1,215 +0,0 @@
//============================================================================
// 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_kokkos_internal_ArrayManagerExecutionKokkos_h
#define vtk_m_cont_kokkos_internal_ArrayManagerExecutionKokkos_h
#include <vtkm/cont/internal/ArrayManagerExecution.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/Logging.h>
#include <vtkm/cont/Storage.h>
#include <vtkm/cont/kokkos/internal/DeviceAdapterTagKokkos.h>
#include <vtkm/cont/kokkos/internal/KokkosAlloc.h>
#include <vtkm/cont/kokkos/internal/KokkosTypes.h>
#include <vtkm/internal/ArrayPortalBasic.h>
#include <limits>
// These must be placed in the vtkm::cont::internal namespace so that
// the template can be found.
namespace vtkm
{
namespace cont
{
namespace internal
{
template <typename T, class StorageTag>
class ArrayManagerExecution<T, StorageTag, vtkm::cont::DeviceAdapterTagKokkos>
{
public:
using ValueType = T;
using PortalType = vtkm::internal::ArrayPortalBasicWrite<T>;
using PortalConstType = vtkm::internal::ArrayPortalBasicRead<T>;
using StorageType = vtkm::cont::internal::Storage<ValueType, StorageTag>;
VTKM_CONT
ArrayManagerExecution(StorageType* storage)
: Storage(storage)
{
}
VTKM_CONT
~ArrayManagerExecution() { this->ReleaseResources(); }
/// Returns the size of the array.
///
VTKM_CONT
vtkm::Id GetNumberOfValues() const { return this->Storage->GetNumberOfValues(); }
VTKM_CONT
PortalConstType PrepareForInput(bool updateData, vtkm::cont::Token&)
{
if (updateData)
{
this->CopyToExecution();
}
return PortalConstType(this->DeviceArray, this->DeviceArrayLength);
}
VTKM_CONT
PortalType PrepareForInPlace(bool updateData, vtkm::cont::Token&)
{
if (updateData)
{
this->CopyToExecution();
}
return PortalType(this->DeviceArray, this->DeviceArrayLength);
}
VTKM_CONT
PortalType PrepareForOutput(vtkm::Id numberOfValues, vtkm::cont::Token&)
{
if (numberOfValues > this->DeviceArrayLength)
{
this->ReallocDeviceArray(numberOfValues);
}
this->DeviceArrayLength = numberOfValues;
return PortalType(this->DeviceArray, this->DeviceArrayLength);
}
/// Allocates enough space in \c storage and copies the data in the
/// device vector into it.
///
VTKM_CONT
void RetrieveOutputData(StorageType* storage) const
{
VTKM_LOG_F(vtkm::cont::LogLevel::MemTransfer,
"Copying Kokkos dev --> host: %s",
vtkm::cont::GetSizeString(this->DeviceArrayLength).c_str());
vtkm::cont::kokkos::internal::KokkosViewConstExec<T> deviceView(
this->DeviceArray, static_cast<std::size_t>(this->DeviceArrayLength));
auto hostView = Kokkos::create_mirror_view(deviceView);
if (hostView.data() != deviceView.data())
{
Kokkos::realloc(hostView, this->DeviceArrayLength);
Kokkos::deep_copy(
vtkm::cont::kokkos::internal::GetExecutionSpaceInstance(), hostView, deviceView);
}
vtkm::cont::kokkos::internal::GetExecutionSpaceInstance().fence();
storage->Allocate(this->DeviceArrayLength);
std::copy_n(hostView.data(),
this->DeviceArrayLength,
vtkm::cont::ArrayPortalToIteratorBegin(storage->GetPortal()));
}
/// Resizes the device vector.
///
VTKM_CONT void Shrink(vtkm::Id numberOfValues)
{
// The operation will succeed even if this assertion fails, but this
// is still supposed to be a precondition to Shrink.
VTKM_ASSERT(numberOfValues <= this->DeviceArrayLength);
this->ReallocDeviceArray(numberOfValues);
this->DeviceArrayLength = numberOfValues;
}
/// Frees all memory.
///
VTKM_CONT void ReleaseResources()
{
vtkm::cont::kokkos::internal::Free(this->DeviceArray);
this->DeviceArray = nullptr;
this->DeviceArrayLength = 0;
}
private:
ArrayManagerExecution(ArrayManagerExecution&) = delete;
void operator=(ArrayManagerExecution&) = delete;
void ReallocDeviceArray(vtkm::Id numberOfValues)
{
size_t size = static_cast<std::size_t>(numberOfValues) * sizeof(T);
try
{
if (!this->DeviceArray)
{
this->DeviceArray = static_cast<T*>(vtkm::cont::kokkos::internal::Allocate(size));
}
else
{
this->DeviceArray =
static_cast<T*>(vtkm::cont::kokkos::internal::Reallocate(this->DeviceArray, size));
}
}
catch (...)
{
std::ostringstream err;
err << "Failed to allocate " << size << " bytes on Kokkos device";
throw vtkm::cont::ErrorBadAllocation(err.str());
}
}
VTKM_CONT
static void CopyToExecutionImpl(
ArrayManagerExecution<T, vtkm::cont::StorageTagBasic, vtkm::cont::DeviceAdapterTagKokkos>* self)
{
self->ReallocDeviceArray(self->Storage->GetNumberOfValues());
self->DeviceArrayLength = self->Storage->GetNumberOfValues();
vtkm::cont::kokkos::internal::KokkosViewConstCont<T> hostView(
self->Storage->GetArray(), self->Storage->GetNumberOfValues());
vtkm::cont::kokkos::internal::KokkosViewExec<T> deviceView(self->DeviceArray,
self->DeviceArrayLength);
Kokkos::deep_copy(
vtkm::cont::kokkos::internal::GetExecutionSpaceInstance(), deviceView, hostView);
}
template <typename S>
VTKM_CONT static void CopyToExecutionImpl(
ArrayManagerExecution<T, S, vtkm::cont::DeviceAdapterTagKokkos>* self)
{
std::vector<T> buffer(static_cast<std::size_t>(self->Storage->GetNumberOfValues()));
std::copy(vtkm::cont::ArrayPortalToIteratorBegin(self->Storage->GetPortalConst()),
vtkm::cont::ArrayPortalToIteratorEnd(self->Storage->GetPortalConst()),
buffer.begin());
self->ReallocDeviceArray(self->Storage->GetNumberOfValues());
self->DeviceArrayLength = self->Storage->GetNumberOfValues();
vtkm::cont::kokkos::internal::KokkosViewConstCont<T> hostView(buffer.data(), buffer.size());
vtkm::cont::kokkos::internal::KokkosViewExec<T> deviceView(
self->DeviceArray, static_cast<std::size_t>(self->DeviceArrayLength));
Kokkos::deep_copy(
vtkm::cont::kokkos::internal::GetExecutionSpaceInstance(), deviceView, hostView);
}
VTKM_CONT
void CopyToExecution() { CopyToExecutionImpl(this); }
StorageType* Storage;
T* DeviceArray = nullptr;
vtkm::Id DeviceArrayLength = 0;
};
}
}
} // namespace vtkm::cont::internal
#endif //vtk_m_cont_kokkos_internal_ArrayManagerExecutionKokkos_h

@ -9,7 +9,6 @@
##============================================================================
set(headers
ArrayManagerExecutionKokkos.h
DeviceAdapterAlgorithmKokkos.h
DeviceAdapterMemoryManagerKokkos.h
DeviceAdapterRuntimeDetectorKokkos.h

@ -15,7 +15,6 @@
#include <vtkm/cont/openmp/internal/DeviceAdapterTagOpenMP.h>
#ifdef VTKM_ENABLE_OPENMP
#include <vtkm/cont/openmp/internal/ArrayManagerExecutionOpenMP.h>
#include <vtkm/cont/openmp/internal/DeviceAdapterAlgorithmOpenMP.h>
#include <vtkm/cont/openmp/internal/DeviceAdapterMemoryManagerOpenMP.h>
#include <vtkm/cont/openmp/internal/VirtualObjectTransferOpenMP.h>

@ -1,66 +0,0 @@
//============================================================================
// 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_openmp_internal_ArrayManagerExecutionOpenMP_h
#define vtk_m_cont_openmp_internal_ArrayManagerExecutionOpenMP_h
#include <vtkm/cont/openmp/internal/DeviceAdapterTagOpenMP.h>
#include <vtkm/cont/internal/ArrayManagerExecution.h>
#include <vtkm/cont/internal/ArrayManagerExecutionShareWithControl.h>
namespace vtkm
{
namespace cont
{
namespace internal
{
template <typename T, class StorageTag>
class ArrayManagerExecution<T, StorageTag, vtkm::cont::DeviceAdapterTagOpenMP>
: public vtkm::cont::internal::ArrayManagerExecutionShareWithControl<T, StorageTag>
{
public:
using Superclass = vtkm::cont::internal::ArrayManagerExecutionShareWithControl<T, StorageTag>;
using ValueType = typename Superclass::ValueType;
using PortalType = typename Superclass::PortalType;
using PortalConstType = typename Superclass::PortalConstType;
using StorageType = typename Superclass::StorageType;
VTKM_CONT
ArrayManagerExecution(StorageType* storage)
: Superclass(storage)
{
}
VTKM_CONT
PortalConstType PrepareForInput(bool updateData, vtkm::cont::Token& token)
{
return this->Superclass::PrepareForInput(updateData, token);
}
VTKM_CONT
PortalType PrepareForInPlace(bool updateData, vtkm::cont::Token& token)
{
return this->Superclass::PrepareForInPlace(updateData, token);
}
VTKM_CONT
PortalType PrepareForOutput(vtkm::Id numberOfValues, vtkm::cont::Token& token)
{
return this->Superclass::PrepareForOutput(numberOfValues, token);
}
};
}
}
} // namespace vtkm::cont::internal
#endif // vtk_m_cont_openmp_internal_ArrayManagerExecutionOpenMP_h

@ -9,7 +9,6 @@
##============================================================================
set(headers
ArrayManagerExecutionOpenMP.h
DeviceAdapterAlgorithmOpenMP.h
DeviceAdapterMemoryManagerOpenMP.h
DeviceAdapterRuntimeDetectorOpenMP.h

@ -8,7 +8,6 @@
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#include <vtkm/cont/openmp/internal/ArrayManagerExecutionOpenMP.h>
#include <vtkm/cont/openmp/internal/FunctorsOpenMP.h>
#include <vtkm/cont/openmp/internal/ParallelQuickSortOpenMP.h>
#include <vtkm/cont/openmp/internal/ParallelRadixSortOpenMP.h>

@ -15,7 +15,6 @@
#include <vtkm/cont/serial/internal/DeviceAdapterTagSerial.h>
#include <vtkm/cont/serial/internal/DeviceAdapterRuntimeDetectorSerial.h>
#include <vtkm/cont/serial/internal/DeviceAdapterMemoryManagerSerial.h>
#include <vtkm/cont/serial/internal/ArrayManagerExecutionSerial.h>
#include <vtkm/cont/serial/internal/DeviceAdapterAlgorithmSerial.h>
#include <vtkm/cont/serial/internal/VirtualObjectTransferSerial.h>
// clang-format on

@ -1,44 +0,0 @@
//============================================================================
// 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_serial_internal_ArrayManagerExecutionSerial_h
#define vtk_m_cont_serial_internal_ArrayManagerExecutionSerial_h
#include <vtkm/cont/internal/ArrayManagerExecution.h>
#include <vtkm/cont/internal/ArrayManagerExecutionShareWithControl.h>
#include <vtkm/cont/serial/internal/DeviceAdapterTagSerial.h>
namespace vtkm
{
namespace cont
{
namespace internal
{
template <typename T, class StorageTag>
class ArrayManagerExecution<T, StorageTag, vtkm::cont::DeviceAdapterTagSerial>
: public vtkm::cont::internal::ArrayManagerExecutionShareWithControl<T, StorageTag>
{
public:
using Superclass = vtkm::cont::internal::ArrayManagerExecutionShareWithControl<T, StorageTag>;
using ValueType = typename Superclass::ValueType;
using PortalType = typename Superclass::PortalType;
using PortalConstType = typename Superclass::PortalConstType;
VTKM_CONT
ArrayManagerExecution(typename Superclass::StorageType* storage)
: Superclass(storage)
{
}
};
}
}
} // namespace vtkm::cont::internal
#endif //vtk_m_cont_serial_internal_ArrayManagerExecutionSerial_h

@ -9,7 +9,6 @@
##============================================================================
set(headers
ArrayManagerExecutionSerial.h
DeviceAdapterAlgorithmSerial.h
DeviceAdapterMemoryManagerSerial.h
DeviceAdapterRuntimeDetectorSerial.h

@ -14,7 +14,6 @@
#include <vtkm/cont/tbb/internal/DeviceAdapterTagTBB.h>
#ifdef VTKM_ENABLE_TBB
#include <vtkm/cont/tbb/internal/ArrayManagerExecutionTBB.h>
#include <vtkm/cont/tbb/internal/DeviceAdapterAlgorithmTBB.h>
#include <vtkm/cont/tbb/internal/DeviceAdapterMemoryManagerTBB.h>
#include <vtkm/cont/tbb/internal/VirtualObjectTransferTBB.h>

@ -1,67 +0,0 @@
//============================================================================
// 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_tbb_internal_ArrayManagerExecutionTBB_h
#define vtk_m_cont_tbb_internal_ArrayManagerExecutionTBB_h
#include <vtkm/cont/internal/ArrayManagerExecution.h>
#include <vtkm/cont/internal/ArrayManagerExecutionShareWithControl.h>
#include <vtkm/cont/tbb/internal/DeviceAdapterTagTBB.h>
// These must be placed in the vtkm::cont::internal namespace so that
// the template can be found.
namespace vtkm
{
namespace cont
{
namespace internal
{
template <typename T, class StorageTag>
class ArrayManagerExecution<T, StorageTag, vtkm::cont::DeviceAdapterTagTBB>
: public vtkm::cont::internal::ArrayManagerExecutionShareWithControl<T, StorageTag>
{
public:
using Superclass = vtkm::cont::internal::ArrayManagerExecutionShareWithControl<T, StorageTag>;
using ValueType = typename Superclass::ValueType;
using PortalType = typename Superclass::PortalType;
using PortalConstType = typename Superclass::PortalConstType;
using StorageType = typename Superclass::StorageType;
VTKM_CONT
ArrayManagerExecution(StorageType* storage)
: Superclass(storage)
{
}
VTKM_CONT
PortalConstType PrepareForInput(bool updateData, vtkm::cont::Token& token)
{
return this->Superclass::PrepareForInput(updateData, token);
}
VTKM_CONT
PortalType PrepareForInPlace(bool updateData, vtkm::cont::Token& token)
{
return this->Superclass::PrepareForInPlace(updateData, token);
}
VTKM_CONT
PortalType PrepareForOutput(vtkm::Id numberOfValues, vtkm::cont::Token& token)
{
return this->Superclass::PrepareForOutput(numberOfValues, token);
}
};
}
}
} // namespace vtkm::cont::internal
#endif //vtk_m_cont_tbb_internal_ArrayManagerExecutionTBB_h

@ -9,7 +9,6 @@
##============================================================================
set(headers
ArrayManagerExecutionTBB.h
DeviceAdapterAlgorithmTBB.h
DeviceAdapterMemoryManagerTBB.h
DeviceAdapterRuntimeDetectorTBB.h

@ -18,7 +18,6 @@
#include <vtkm/cont/Logging.h>
#include <vtkm/cont/internal/DeviceAdapterAlgorithmGeneral.h>
#include <vtkm/cont/internal/IteratorFromArrayPortal.h>
#include <vtkm/cont/tbb/internal/ArrayManagerExecutionTBB.h>
#include <vtkm/cont/tbb/internal/DeviceAdapterTagTBB.h>
#include <vtkm/cont/tbb/internal/FunctorsTBB.h>
#include <vtkm/cont/tbb/internal/ParallelSortTBB.h>

@ -16,7 +16,6 @@
#include <vtkm/cont/ArrayHandleZip.h>
#include <vtkm/cont/internal/ParallelRadixSortInterface.h>
#include <vtkm/cont/tbb/internal/ArrayManagerExecutionTBB.h>
#include <vtkm/cont/tbb/internal/DeviceAdapterTagTBB.h>
#include <vtkm/cont/tbb/internal/FunctorsTBB.h>
#include <vtkm/cont/tbb/internal/ParallelSortTBB.hxx>

@ -12,7 +12,6 @@
#include <vtkm/cont/ArrayHandleDiscard.h>
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
#include <vtkm/cont/serial/internal/ArrayManagerExecutionSerial.h>
#include <vtkm/cont/serial/internal/DeviceAdapterAlgorithmSerial.h>
#include <vtkm/cont/serial/internal/DeviceAdapterTagSerial.h>

@ -18,7 +18,6 @@
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
#include <vtkm/cont/serial/internal/ArrayManagerExecutionSerial.h>
#include <vtkm/cont/serial/internal/DeviceAdapterAlgorithmSerial.h>
#include <vtkm/cont/serial/internal/DeviceAdapterTagSerial.h>

@ -80,24 +80,6 @@ class DeviceAdapterMemoryManager<vtkm::cont::DeviceAdapterTagTestAlgorithmGenera
}
};
template <typename T, class StorageTag>
class ArrayManagerExecution<T, StorageTag, vtkm::cont::DeviceAdapterTagTestAlgorithmGeneral>
: public vtkm::cont::internal::
ArrayManagerExecution<T, StorageTag, vtkm::cont::DeviceAdapterTagSerial>
{
public:
using Superclass =
vtkm::cont::internal::ArrayManagerExecution<T, StorageTag, vtkm::cont::DeviceAdapterTagSerial>;
using ValueType = typename Superclass::ValueType;
using PortalType = typename Superclass::PortalType;
using PortalConstType = typename Superclass::PortalConstType;
ArrayManagerExecution(vtkm::cont::internal::Storage<T, StorageTag>* storage)
: Superclass(storage)
{
}
};
template <typename TargetClass>
struct VirtualObjectTransfer<TargetClass, vtkm::cont::DeviceAdapterTagTestAlgorithmGeneral> final
: public VirtualObjectTransferShareWithControl<TargetClass>