2014-11-26 17:19:46 +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.
|
|
|
|
//
|
2017-09-20 21:33:44 +00:00
|
|
|
// Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
2014-11-26 17:19:46 +00:00
|
|
|
// Copyright 2014 UT-Battelle, LLC.
|
2015-05-21 12:09:22 +00:00
|
|
|
// Copyright 2014 Los Alamos National Security.
|
2014-11-26 17:19:46 +00:00
|
|
|
//
|
2017-09-20 21:33:44 +00:00
|
|
|
// Under the terms of Contract DE-NA0003525 with NTESS,
|
2014-11-26 17:19:46 +00:00
|
|
|
// 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_cuda_internal_MakeThrustIterator_h
|
|
|
|
#define vtk_m_cont_cuda_internal_MakeThrustIterator_h
|
|
|
|
|
2015-06-08 19:50:48 +00:00
|
|
|
#include <vtkm/Pair.h>
|
2017-05-18 14:51:24 +00:00
|
|
|
#include <vtkm/Types.h>
|
2015-07-13 21:16:27 +00:00
|
|
|
#include <vtkm/cont/ArrayPortalToIterators.h>
|
2017-05-18 14:51:24 +00:00
|
|
|
#include <vtkm/internal/ExportMacros.h>
|
2014-11-26 17:19:46 +00:00
|
|
|
|
2014-12-15 18:27:39 +00:00
|
|
|
#include <vtkm/exec/cuda/internal/ArrayPortalFromThrust.h>
|
2015-06-11 19:21:18 +00:00
|
|
|
#include <vtkm/exec/cuda/internal/WrappedOperators.h>
|
2014-12-15 18:27:39 +00:00
|
|
|
|
2015-05-26 14:49:52 +00:00
|
|
|
// Disable warnings we check vtkm for but Thrust does not.
|
2015-08-12 19:08:45 +00:00
|
|
|
VTKM_THIRDPARTY_PRE_INCLUDE
|
2014-11-26 17:19:46 +00:00
|
|
|
#include <thrust/functional.h>
|
|
|
|
#include <thrust/iterator/counting_iterator.h>
|
|
|
|
#include <thrust/iterator/transform_iterator.h>
|
2017-05-18 14:51:24 +00:00
|
|
|
#include <thrust/system/cuda/memory.h>
|
2015-08-12 19:08:45 +00:00
|
|
|
VTKM_THIRDPARTY_POST_INCLUDE
|
2014-11-26 17:19:46 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace cont
|
|
|
|
{
|
|
|
|
namespace cuda
|
|
|
|
{
|
|
|
|
namespace internal
|
|
|
|
{
|
|
|
|
namespace detail
|
|
|
|
{
|
2014-11-26 17:19:46 +00:00
|
|
|
|
|
|
|
// Tags to specify what type of thrust iterator to use.
|
2017-05-18 14:29:41 +00:00
|
|
|
struct ThrustIteratorFromArrayPortalTag
|
|
|
|
{
|
|
|
|
};
|
|
|
|
struct ThrustIteratorDevicePtrTag
|
|
|
|
{
|
|
|
|
};
|
2014-11-26 17:19:46 +00:00
|
|
|
|
|
|
|
// Traits to help classify what thrust iterators will be used.
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename IteratorType>
|
|
|
|
struct ThrustIteratorTag
|
|
|
|
{
|
2017-08-16 15:34:21 +00:00
|
|
|
using Type = ThrustIteratorFromArrayPortalTag;
|
2014-11-26 17:19:46 +00:00
|
|
|
};
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T>
|
|
|
|
struct ThrustIteratorTag<thrust::system::cuda::pointer<T>>
|
|
|
|
{
|
2017-08-16 15:34:21 +00:00
|
|
|
using Type = ThrustIteratorDevicePtrTag;
|
2014-11-26 17:19:46 +00:00
|
|
|
};
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T>
|
|
|
|
struct ThrustIteratorTag<thrust::system::cuda::pointer<const T>>
|
|
|
|
{
|
2017-08-16 15:34:21 +00:00
|
|
|
using Type = ThrustIteratorDevicePtrTag;
|
2014-11-26 17:19:46 +00:00
|
|
|
};
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename PortalType, typename Tag>
|
|
|
|
struct IteratorChooser;
|
|
|
|
template <typename PortalType>
|
|
|
|
struct IteratorChooser<PortalType, detail::ThrustIteratorFromArrayPortalTag>
|
|
|
|
{
|
2017-08-16 15:34:21 +00:00
|
|
|
using Type = vtkm::exec::cuda::internal::IteratorFromArrayPortal<PortalType>;
|
2015-06-08 19:50:48 +00:00
|
|
|
};
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename PortalType>
|
|
|
|
struct IteratorChooser<PortalType, detail::ThrustIteratorDevicePtrTag>
|
|
|
|
{
|
2017-08-16 15:34:21 +00:00
|
|
|
using PortalToIteratorType = vtkm::cont::ArrayPortalToIterators<PortalType>;
|
2015-07-13 21:16:27 +00:00
|
|
|
|
2017-08-16 15:34:21 +00:00
|
|
|
using Type = typename PortalToIteratorType::IteratorType;
|
2014-11-26 17:19:46 +00:00
|
|
|
};
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename PortalType>
|
2014-11-26 17:19:46 +00:00
|
|
|
struct IteratorTraits
|
|
|
|
{
|
2017-08-16 15:34:21 +00:00
|
|
|
using PortalToIteratorType = vtkm::cont::ArrayPortalToIterators<PortalType>;
|
|
|
|
using Tag = typename detail::ThrustIteratorTag<typename PortalToIteratorType::IteratorType>::Type;
|
|
|
|
using IteratorType = typename IteratorChooser<PortalType, Tag>::Type;
|
2014-11-26 17:19:46 +00:00
|
|
|
};
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename PortalType>
|
|
|
|
VTKM_CONT typename IteratorTraits<PortalType>::IteratorType MakeIteratorBegin(
|
2017-05-26 17:53:28 +00:00
|
|
|
PortalType portal,
|
|
|
|
detail::ThrustIteratorFromArrayPortalTag)
|
2014-11-26 17:19:46 +00:00
|
|
|
{
|
2015-07-14 13:50:38 +00:00
|
|
|
return vtkm::exec::cuda::internal::IteratorFromArrayPortal<PortalType>(portal);
|
2014-11-26 17:19:46 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename PortalType>
|
|
|
|
VTKM_CONT typename IteratorTraits<PortalType>::IteratorType MakeIteratorBegin(
|
2017-05-26 17:53:28 +00:00
|
|
|
PortalType portal,
|
|
|
|
detail::ThrustIteratorDevicePtrTag)
|
2014-11-26 17:19:46 +00:00
|
|
|
{
|
2015-07-14 13:50:38 +00:00
|
|
|
vtkm::cont::ArrayPortalToIterators<PortalType> iterators(portal);
|
|
|
|
return iterators.GetBegin();
|
2014-11-26 17:19:46 +00:00
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename PortalType>
|
|
|
|
VTKM_CONT typename IteratorTraits<PortalType>::IteratorType MakeIteratorEnd(
|
2017-05-26 17:53:28 +00:00
|
|
|
PortalType portal,
|
|
|
|
detail::ThrustIteratorFromArrayPortalTag)
|
2016-06-23 18:12:44 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::exec::cuda::internal::IteratorFromArrayPortal<PortalType> iterator(portal);
|
|
|
|
::thrust::advance(iterator, static_cast<std::size_t>(portal.GetNumberOfValues()));
|
2016-06-23 18:12:44 +00:00
|
|
|
return iterator;
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename PortalType>
|
|
|
|
VTKM_CONT typename IteratorTraits<PortalType>::IteratorType MakeIteratorEnd(
|
2017-05-26 17:53:28 +00:00
|
|
|
PortalType portal,
|
|
|
|
detail::ThrustIteratorDevicePtrTag)
|
2016-06-23 18:12:44 +00:00
|
|
|
{
|
|
|
|
vtkm::cont::ArrayPortalToIterators<PortalType> iterators(portal);
|
|
|
|
return iterators.GetEnd();
|
|
|
|
}
|
|
|
|
|
2014-11-26 17:19:46 +00:00
|
|
|
} // namespace detail
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename PortalType>
|
|
|
|
VTKM_CONT typename detail::IteratorTraits<PortalType>::IteratorType IteratorBegin(PortalType portal)
|
2014-11-26 17:19:46 +00:00
|
|
|
{
|
2017-08-16 15:34:21 +00:00
|
|
|
using IteratorTag = typename detail::IteratorTraits<PortalType>::Tag;
|
2014-11-26 17:19:46 +00:00
|
|
|
return detail::MakeIteratorBegin(portal, IteratorTag());
|
|
|
|
}
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename PortalType>
|
|
|
|
VTKM_CONT typename detail::IteratorTraits<PortalType>::IteratorType IteratorEnd(PortalType portal)
|
2014-11-26 17:19:46 +00:00
|
|
|
{
|
2017-08-16 15:34:21 +00:00
|
|
|
using IteratorTag = typename detail::IteratorTraits<PortalType>::Tag;
|
2016-06-23 18:12:44 +00:00
|
|
|
return detail::MakeIteratorEnd(portal, IteratorTag());
|
2014-11-26 17:19:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-06-08 19:50:48 +00:00
|
|
|
|
2014-11-26 17:19:46 +00:00
|
|
|
} //namespace vtkm::cont::cuda::internal
|
|
|
|
|
|
|
|
#endif
|