TransportTagAtomicArray.h 3.61 KB
Newer Older
1 2 3 4
//============================================================================
//  Copyright (c) Kitware, Inc.
//  All rights reserved.
//  See LICENSE.txt for details.
5
//
6 7 8 9 10 11 12 13 14 15
//  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_arg_TransportTagAtomicArray_h
#define vtk_m_cont_arg_TransportTagAtomicArray_h

#include <vtkm/Types.h>

#include <vtkm/cont/ArrayHandle.h>
16 17

#ifndef VTKM_NO_DEPRECATED_VIRTUAL
18
#include <vtkm/cont/ArrayHandleVirtual.h>
19
#include <vtkm/cont/StorageVirtual.h>
20
#endif
21

22 23 24

#include <vtkm/cont/arg/Transport.h>

25
#include <vtkm/cont/AtomicArray.h>
26

27 28 29 30 31 32
namespace vtkm
{
namespace cont
{
namespace arg
{
33 34 35 36 37 38 39 40 41

/// \brief \c Transport tag for in-place arrays with atomic operations.
///
/// \c TransportTagAtomicArray is a tag used with the \c Transport class to
/// transport \c ArrayHandle objects for data that is both input and output
/// (that is, in place modification of array data). The array will be wrapped
/// in a vtkm::exec::AtomicArray class that provides atomic operations (like
/// add and compare/swap).
///
42 43 44
struct TransportTagAtomicArray
{
};
45

46 47
template <typename T, typename Device>
struct Transport<vtkm::cont::arg::TransportTagAtomicArray,
48 49
                 vtkm::cont::ArrayHandle<T, vtkm::cont::StorageTagBasic>,
                 Device>
50
{
51
  using ExecObjectType = vtkm::exec::AtomicArrayExecutionObject<T, Device>;
52
  using ExecType = vtkm::cont::AtomicArray<T>;
53

54
  template <typename InputDomainType>
55 56 57 58
  VTKM_CONT ExecObjectType
  operator()(vtkm::cont::ArrayHandle<T, vtkm::cont::StorageTagBasic>& array,
             const InputDomainType&,
             vtkm::Id,
59 60
             vtkm::Id,
             vtkm::cont::Token& token) const
61 62 63 64
  {
    // Note: we ignore the size of the domain because the randomly accessed
    // array might not have the same size depending on how the user is using
    // the array.
65
    ExecType obj(array);
66
    return obj.PrepareForExecution(Device(), token);
67 68
  }
};
69

70
#ifndef VTKM_NO_DEPRECATED_VIRTUAL
71
VTKM_DEPRECATED_SUPPRESS_BEGIN
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
template <typename T, typename Device>
struct Transport<vtkm::cont::arg::TransportTagAtomicArray,
                 vtkm::cont::ArrayHandle<T, vtkm::cont::StorageTagVirtual>,
                 Device>
{
  using ExecObjectType = vtkm::exec::AtomicArrayExecutionObject<T, Device>;
  using ExecType = vtkm::cont::AtomicArray<T>;

  template <typename InputDomainType>
  VTKM_CONT ExecObjectType
  operator()(vtkm::cont::ArrayHandle<T, vtkm::cont::StorageTagVirtual>& array,
             const InputDomainType&,
             vtkm::Id,
             vtkm::Id) const
  {
87 88 89
    using ArrayHandleType = vtkm::cont::ArrayHandle<T>;
    const bool is_type = vtkm::cont::IsType<ArrayHandleType>(array);
    if (!is_type)
90 91
    {
#if defined(VTKM_ENABLE_LOGGING)
92
      VTKM_LOG_CAST_FAIL(array, ArrayHandleType);
93 94 95 96 97
#endif
      throw vtkm::cont::ErrorBadValue("Arrays being used as atomic's must always have storage that "
                                      "is of the type StorageTagBasic.");
    }

98
    ArrayHandleType handle = vtkm::cont::Cast<ArrayHandleType>(array);
99 100 101 102

    // Note: we ignore the size of the domain because the randomly accessed
    // array might not have the same size depending on how the user is using
    // the array.
103
    ExecType obj(handle);
104 105 106
    return obj.PrepareForExecution(Device());
  }
};
107
VTKM_DEPRECATED_SUPPRESS_END
108
#endif //VTKM_NO_DEPRECATED_VIRTUAL
109 110 111 112 113
}
}
} // namespace vtkm::cont::arg

#endif //vtk_m_cont_arg_TransportTagAtomicArray_h