2017-09-25 22:28:44 +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 2017 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
|
|
|
// Copyright 2017 UT-Battelle, LLC.
|
|
|
|
// Copyright 2017 Los Alamos National Security.
|
|
|
|
//
|
|
|
|
// Under the terms of Contract DE-NA0003525 with NTESS,
|
|
|
|
// 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_ArrayCopy_h
|
|
|
|
#define vtk_m_cont_ArrayCopy_h
|
|
|
|
|
2019-04-01 21:25:44 +00:00
|
|
|
#include <vtkm/cont/Algorithm.h>
|
2017-09-25 22:28:44 +00:00
|
|
|
#include <vtkm/cont/ArrayHandle.h>
|
|
|
|
#include <vtkm/cont/ArrayHandleCast.h>
|
|
|
|
#include <vtkm/cont/TryExecute.h>
|
|
|
|
|
|
|
|
// TODO: When virtual arrays are available, compile the implementation in a .cxx/.cu file. Common
|
|
|
|
// arrays are copied directly but anything else would be copied through virtual methods.
|
|
|
|
|
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace cont
|
|
|
|
{
|
|
|
|
/// \brief Does a deep copy from one array to another array.
|
|
|
|
///
|
|
|
|
/// Given a source \c ArrayHandle and a destination \c ArrayHandle, this function allocates the
|
|
|
|
/// destination \c ArrayHandle to the correct size and deeply copies all the values from the source
|
|
|
|
/// to the destination.
|
|
|
|
///
|
2017-09-25 22:54:24 +00:00
|
|
|
template <typename InValueType, typename InStorage, typename OutValueType, typename OutStorage>
|
2019-04-01 21:25:44 +00:00
|
|
|
VTKM_CONT inline void ArrayCopy(const vtkm::cont::ArrayHandle<InValueType, InStorage>& source,
|
|
|
|
vtkm::cont::ArrayHandle<OutValueType, OutStorage>& destination)
|
2017-09-25 22:28:44 +00:00
|
|
|
{
|
2019-04-01 21:25:44 +00:00
|
|
|
bool isCopied =
|
|
|
|
vtkm::cont::Algorithm::Copy(vtkm::cont::DeviceAdapterTagAny(), source, destination);
|
2018-07-25 15:11:05 +00:00
|
|
|
if (!isCopied)
|
|
|
|
{ // If after the second pass, still not valid through an exception
|
|
|
|
throw vtkm::cont::ErrorExecution("Failed to run ArrayCopy on any device.");
|
2017-09-25 22:28:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace vtkm::cont
|
|
|
|
|
|
|
|
#endif //vtk_m_cont_ArrayCopy_h
|