2016-02-10 15:51:31 +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 2015 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
2016-02-10 15:51:31 +00:00
|
|
|
// Copyright 2015 UT-Battelle, LLC.
|
|
|
|
// Copyright 2015 Los Alamos National Security.
|
|
|
|
//
|
2017-09-20 21:33:44 +00:00
|
|
|
// Under the terms of Contract DE-NA0003525 with NTESS,
|
2016-02-10 15:51:31 +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.
|
|
|
|
//============================================================================
|
2018-06-07 21:08:02 +00:00
|
|
|
#ifndef vtk_m_exec_AtomicArrayExecutionObject_h
|
|
|
|
#define vtk_m_exec_AtomicArrayExecutionObject_h
|
2016-02-10 15:51:31 +00:00
|
|
|
|
2016-03-24 23:12:17 +00:00
|
|
|
#include <vtkm/ListTag.h>
|
2016-02-10 15:51:31 +00:00
|
|
|
#include <vtkm/cont/ArrayHandle.h>
|
2017-05-18 14:51:24 +00:00
|
|
|
#include <vtkm/cont/DeviceAdapter.h>
|
2016-02-10 15:51:31 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace exec
|
|
|
|
{
|
2016-02-10 15:51:31 +00:00
|
|
|
|
2018-06-07 19:16:28 +00:00
|
|
|
template <typename T, typename Device>
|
|
|
|
class AtomicArrayExecutionObject
|
2016-02-10 15:51:31 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-06-23 18:50:34 +00:00
|
|
|
using ValueType = T;
|
2016-03-24 23:12:17 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2018-06-07 19:16:28 +00:00
|
|
|
AtomicArrayExecutionObject()
|
2017-08-17 12:43:39 +00:00
|
|
|
: AtomicImplementation((vtkm::cont::ArrayHandle<T>()))
|
2017-05-18 14:29:41 +00:00
|
|
|
{
|
|
|
|
}
|
2016-03-24 23:12:17 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename StorageType>
|
2018-06-07 19:16:28 +00:00
|
|
|
VTKM_CONT AtomicArrayExecutionObject(vtkm::cont::ArrayHandle<T, StorageType> handle)
|
2017-05-18 14:29:41 +00:00
|
|
|
: AtomicImplementation(handle)
|
2016-02-10 15:51:31 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-01-18 20:27:40 +00:00
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2016-02-10 15:51:31 +00:00
|
|
|
T Add(vtkm::Id index, const T& value) const
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
return this->AtomicImplementation.Add(index, value);
|
2016-02-10 15:51:31 +00:00
|
|
|
}
|
|
|
|
|
2016-03-08 17:58:20 +00:00
|
|
|
//
|
2016-03-23 18:18:36 +00:00
|
|
|
// Compare and Swap is an atomic exchange operation. If the value at
|
2016-03-08 17:58:20 +00:00
|
|
|
// the index is equal to oldValue, then newValue is written to the index.
|
2016-03-23 18:18:36 +00:00
|
|
|
// The operation was successful if return value is equal to oldValue
|
2016-03-08 17:58:20 +00:00
|
|
|
//
|
2018-01-18 20:27:40 +00:00
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2016-03-08 17:41:02 +00:00
|
|
|
T CompareAndSwap(vtkm::Id index, const T& newValue, const T& oldValue) const
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
return this->AtomicImplementation.CompareAndSwap(index, newValue, oldValue);
|
2016-03-08 17:41:02 +00:00
|
|
|
}
|
|
|
|
|
2016-02-10 15:51:31 +00:00
|
|
|
private:
|
2018-06-07 19:16:28 +00:00
|
|
|
vtkm::cont::DeviceAdapterAtomicArrayImplementation<T, Device> AtomicImplementation;
|
|
|
|
};
|
2016-02-10 15:51:31 +00:00
|
|
|
}
|
|
|
|
} // namespace vtkm::exec
|
|
|
|
|
2018-06-07 21:08:02 +00:00
|
|
|
#endif //vtk_m_exec_AtomicArrayExecutionObject_h
|