2015-04-23 17:20:03 +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).
|
2015-04-23 17:20:03 +00:00
|
|
|
// Copyright 2014 UT-Battelle, LLC.
|
2015-05-21 12:09:22 +00:00
|
|
|
// Copyright 2014 Los Alamos National Security.
|
2015-04-23 17:20:03 +00:00
|
|
|
//
|
2017-09-20 21:33:44 +00:00
|
|
|
// Under the terms of Contract DE-NA0003525 with NTESS,
|
2015-04-23 17:20:03 +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_ArrayHandleZip_h
|
|
|
|
#define vtk_m_cont_ArrayHandleZip_h
|
|
|
|
|
|
|
|
#include <vtkm/Pair.h>
|
2017-05-18 14:51:24 +00:00
|
|
|
#include <vtkm/cont/ArrayHandle.h>
|
2015-04-23 17:20:03 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace exec
|
|
|
|
{
|
|
|
|
namespace internal
|
|
|
|
{
|
2015-04-23 17:20:03 +00:00
|
|
|
|
|
|
|
/// \brief An array portal that zips two portals together into a single value
|
|
|
|
/// for the execution environment
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename ValueType_, typename PortalTypeFirst_, typename PortalTypeSecond_>
|
2016-08-02 15:26:29 +00:00
|
|
|
class ArrayPortalZip
|
2015-04-23 17:20:03 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-06-23 18:50:34 +00:00
|
|
|
using ValueType = ValueType_;
|
|
|
|
using IteratorType = ValueType_;
|
|
|
|
using PortalTypeFirst = PortalTypeFirst_;
|
|
|
|
using PortalTypeSecond = PortalTypeSecond_;
|
2015-06-08 19:50:48 +00:00
|
|
|
|
2016-03-31 13:13:54 +00:00
|
|
|
VTKM_SUPPRESS_EXEC_WARNINGS
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT
|
2016-08-02 15:26:29 +00:00
|
|
|
ArrayPortalZip()
|
2017-05-18 14:29:41 +00:00
|
|
|
: PortalFirst()
|
|
|
|
, PortalSecond()
|
|
|
|
{
|
|
|
|
} //needs to be host and device so that cuda can create lvalue of these
|
2015-04-23 17:20:03 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
ArrayPortalZip(const PortalTypeFirst& portalfirst, const PortalTypeSecond& portalsecond)
|
|
|
|
: PortalFirst(portalfirst)
|
|
|
|
, PortalSecond(portalsecond)
|
|
|
|
{
|
|
|
|
}
|
2015-04-23 17:20:03 +00:00
|
|
|
|
2016-08-02 15:26:29 +00:00
|
|
|
/// Copy constructor for any other ArrayPortalZip with an iterator
|
2015-04-23 17:20:03 +00:00
|
|
|
/// type that can be copied to this iterator type. This allows us to do any
|
|
|
|
/// type casting that the iterators do (like the non-const to const cast).
|
|
|
|
///
|
2017-05-18 14:29:41 +00:00
|
|
|
template <class OtherV, class OtherF, class OtherS>
|
|
|
|
VTKM_CONT ArrayPortalZip(const ArrayPortalZip<OtherV, OtherF, OtherS>& src)
|
|
|
|
: PortalFirst(src.GetFirstPortal())
|
|
|
|
, PortalSecond(src.GetSecondPortal())
|
|
|
|
{
|
|
|
|
}
|
2015-04-23 17:20:03 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT
|
2015-04-23 17:20:03 +00:00
|
|
|
vtkm::Id GetNumberOfValues() const { return this->PortalFirst.GetNumberOfValues(); }
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2017-05-18 14:29:41 +00:00
|
|
|
ValueType Get(vtkm::Id index) const
|
|
|
|
{
|
|
|
|
return vtkm::make_Pair(this->PortalFirst.Get(index), this->PortalSecond.Get(index));
|
2015-04-23 17:20:03 +00:00
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2017-05-18 14:29:41 +00:00
|
|
|
void Set(vtkm::Id index, const ValueType& value) const
|
|
|
|
{
|
2015-04-23 17:20:03 +00:00
|
|
|
this->PortalFirst.Set(index, value.first);
|
|
|
|
this->PortalSecond.Set(index, value.second);
|
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
const PortalTypeFirst& GetFirstPortal() const { return this->PortalFirst; }
|
2015-04-23 17:20:03 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
const PortalTypeSecond& GetSecondPortal() const { return this->PortalSecond; }
|
2015-04-23 17:20:03 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
PortalTypeFirst PortalFirst;
|
|
|
|
PortalTypeSecond PortalSecond;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace vtkm::exec::internal
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace cont
|
|
|
|
{
|
2015-04-23 17:20:03 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace internal
|
|
|
|
{
|
2015-04-23 17:20:03 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename FirstHandleType, typename SecondHandleType>
|
|
|
|
struct VTKM_ALWAYS_EXPORT StorageTagZip
|
|
|
|
{
|
|
|
|
};
|
2015-04-23 17:20:03 +00:00
|
|
|
|
|
|
|
/// This helper struct defines the value type for a zip container containing
|
|
|
|
/// the given two array handles.
|
|
|
|
///
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename FirstHandleType, typename SecondHandleType>
|
|
|
|
struct ArrayHandleZipTraits
|
|
|
|
{
|
2015-04-23 17:20:03 +00:00
|
|
|
/// The ValueType (a pair containing the value types of the two arrays).
|
|
|
|
///
|
2017-08-16 15:34:21 +00:00
|
|
|
using ValueType =
|
|
|
|
vtkm::Pair<typename FirstHandleType::ValueType, typename SecondHandleType::ValueType>;
|
2015-04-23 17:20:03 +00:00
|
|
|
|
|
|
|
/// The appropriately templated tag.
|
|
|
|
///
|
2017-08-16 15:34:21 +00:00
|
|
|
using Tag = StorageTagZip<FirstHandleType, SecondHandleType>;
|
2015-10-21 19:36:27 +00:00
|
|
|
|
|
|
|
/// The superclass for ArrayHandleZip.
|
|
|
|
///
|
2017-08-16 15:34:21 +00:00
|
|
|
using Superclass = vtkm::cont::ArrayHandle<ValueType, Tag>;
|
2015-04-23 17:20:03 +00:00
|
|
|
};
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T, typename FirstHandleType, typename SecondHandleType>
|
|
|
|
class Storage<T, StorageTagZip<FirstHandleType, SecondHandleType>>
|
2015-04-23 17:20:03 +00:00
|
|
|
{
|
|
|
|
VTKM_IS_ARRAY_HANDLE(FirstHandleType);
|
|
|
|
VTKM_IS_ARRAY_HANDLE(SecondHandleType);
|
|
|
|
|
|
|
|
public:
|
2017-06-23 18:50:34 +00:00
|
|
|
using ValueType = T;
|
2015-04-23 17:20:03 +00:00
|
|
|
|
2017-08-16 15:34:21 +00:00
|
|
|
using PortalType = vtkm::exec::internal::ArrayPortalZip<ValueType,
|
|
|
|
typename FirstHandleType::PortalControl,
|
|
|
|
typename SecondHandleType::PortalControl>;
|
|
|
|
using PortalConstType =
|
|
|
|
vtkm::exec::internal::ArrayPortalZip<ValueType,
|
|
|
|
typename FirstHandleType::PortalConstControl,
|
|
|
|
typename SecondHandleType::PortalConstControl>;
|
2015-04-23 17:20:03 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
Storage()
|
|
|
|
: FirstArray()
|
|
|
|
, SecondArray()
|
|
|
|
{
|
|
|
|
}
|
2015-04-23 17:20:03 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
Storage(const FirstHandleType& farray, const SecondHandleType& sarray)
|
|
|
|
: FirstArray(farray)
|
|
|
|
, SecondArray(sarray)
|
2015-04-23 17:20:03 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
PortalType GetPortal()
|
|
|
|
{
|
|
|
|
return PortalType(this->FirstArray.GetPortalControl(), this->SecondArray.GetPortalControl());
|
2015-04-23 17:20:03 +00:00
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
PortalConstType GetPortalConst() const
|
|
|
|
{
|
2015-04-23 17:20:03 +00:00
|
|
|
return PortalConstType(this->FirstArray.GetPortalConstControl(),
|
|
|
|
this->SecondArray.GetPortalConstControl());
|
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Id GetNumberOfValues() const
|
|
|
|
{
|
|
|
|
VTKM_ASSERT(this->FirstArray.GetNumberOfValues() == this->SecondArray.GetNumberOfValues());
|
2015-04-23 17:20:03 +00:00
|
|
|
return this->FirstArray.GetNumberOfValues();
|
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
void Allocate(vtkm::Id numberOfValues)
|
|
|
|
{
|
2015-04-23 17:20:03 +00:00
|
|
|
this->FirstArray.Allocate(numberOfValues);
|
|
|
|
this->SecondArray.Allocate(numberOfValues);
|
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
void Shrink(vtkm::Id numberOfValues)
|
|
|
|
{
|
2015-04-23 17:20:03 +00:00
|
|
|
this->FirstArray.Shrink(numberOfValues);
|
|
|
|
this->SecondArray.Shrink(numberOfValues);
|
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
void ReleaseResources()
|
|
|
|
{
|
2015-04-23 17:20:03 +00:00
|
|
|
// This request is ignored since it is asking to release the resources
|
|
|
|
// of the two zipped array, which may be used elsewhere.
|
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
const FirstHandleType& GetFirstArray() const { return this->FirstArray; }
|
2015-04-23 17:20:03 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
const SecondHandleType& GetSecondArray() const { return this->SecondArray; }
|
2015-04-23 17:20:03 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
FirstHandleType FirstArray;
|
|
|
|
SecondHandleType SecondArray;
|
|
|
|
};
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T, typename FirstHandleType, typename SecondHandleType, typename Device>
|
|
|
|
class ArrayTransfer<T, StorageTagZip<FirstHandleType, SecondHandleType>, Device>
|
2015-04-23 17:20:03 +00:00
|
|
|
{
|
2017-08-16 15:34:21 +00:00
|
|
|
using StorageTag = StorageTagZip<FirstHandleType, SecondHandleType>;
|
|
|
|
using StorageType = vtkm::cont::internal::Storage<T, StorageTag>;
|
2015-04-23 17:20:03 +00:00
|
|
|
|
|
|
|
public:
|
2017-06-23 18:50:34 +00:00
|
|
|
using ValueType = T;
|
2015-04-23 17:20:03 +00:00
|
|
|
|
2017-06-23 18:50:34 +00:00
|
|
|
using PortalControl = typename StorageType::PortalType;
|
|
|
|
using PortalConstControl = typename StorageType::PortalConstType;
|
2015-04-23 17:20:03 +00:00
|
|
|
|
2017-08-16 15:34:21 +00:00
|
|
|
using PortalExecution = vtkm::exec::internal::ArrayPortalZip<
|
2017-05-26 17:53:28 +00:00
|
|
|
ValueType,
|
|
|
|
typename FirstHandleType::template ExecutionTypes<Device>::Portal,
|
2017-08-16 15:34:21 +00:00
|
|
|
typename SecondHandleType::template ExecutionTypes<Device>::Portal>;
|
2015-04-23 17:20:03 +00:00
|
|
|
|
2017-08-16 15:34:21 +00:00
|
|
|
using PortalConstExecution = vtkm::exec::internal::ArrayPortalZip<
|
2017-05-26 17:53:28 +00:00
|
|
|
ValueType,
|
|
|
|
typename FirstHandleType::template ExecutionTypes<Device>::PortalConst,
|
2017-08-16 15:34:21 +00:00
|
|
|
typename SecondHandleType::template ExecutionTypes<Device>::PortalConst>;
|
2015-04-23 17:20:03 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
ArrayTransfer(StorageType* storage)
|
|
|
|
: FirstArray(storage->GetFirstArray())
|
|
|
|
, SecondArray(storage->GetSecondArray())
|
|
|
|
{
|
|
|
|
}
|
2015-04-23 17:20:03 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2015-04-23 17:20:03 +00:00
|
|
|
vtkm::Id GetNumberOfValues() const
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_ASSERT(this->FirstArray.GetNumberOfValues() == this->SecondArray.GetNumberOfValues());
|
2015-04-23 17:20:03 +00:00
|
|
|
return this->FirstArray.GetNumberOfValues();
|
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
PortalConstExecution PrepareForInput(bool vtkmNotUsed(updateData))
|
|
|
|
{
|
2015-04-23 17:20:03 +00:00
|
|
|
return PortalConstExecution(this->FirstArray.PrepareForInput(Device()),
|
|
|
|
this->SecondArray.PrepareForInput(Device()));
|
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
PortalExecution PrepareForInPlace(bool vtkmNotUsed(updateData))
|
|
|
|
{
|
2017-01-17 22:33:18 +00:00
|
|
|
return PortalExecution(this->FirstArray.PrepareForInPlace(Device()),
|
|
|
|
this->SecondArray.PrepareForInPlace(Device()));
|
2015-04-23 17:20:03 +00:00
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2015-04-23 17:20:03 +00:00
|
|
|
PortalExecution PrepareForOutput(vtkm::Id numberOfValues)
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
return PortalExecution(this->FirstArray.PrepareForOutput(numberOfValues, Device()),
|
|
|
|
this->SecondArray.PrepareForOutput(numberOfValues, Device()));
|
2015-04-23 17:20:03 +00:00
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
void RetrieveOutputData(StorageType* vtkmNotUsed(storage)) const
|
|
|
|
{
|
2015-04-23 17:20:03 +00:00
|
|
|
// Implementation of this method should be unnecessary. The internal
|
|
|
|
// first and second array handles should automatically retrieve the
|
|
|
|
// output data as necessary.
|
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
void Shrink(vtkm::Id numberOfValues)
|
|
|
|
{
|
2015-04-23 17:20:03 +00:00
|
|
|
this->FirstArray.Shrink(numberOfValues);
|
|
|
|
this->SecondArray.Shrink(numberOfValues);
|
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
void ReleaseResources()
|
|
|
|
{
|
2015-04-23 17:20:03 +00:00
|
|
|
this->FirstArray.ReleaseResourcesExecution();
|
|
|
|
this->SecondArray.ReleaseResourcesExecution();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
FirstHandleType FirstArray;
|
|
|
|
SecondHandleType SecondArray;
|
|
|
|
};
|
|
|
|
} // namespace internal
|
|
|
|
|
|
|
|
/// ArrayHandleZip is a specialization of ArrayHandle. It takes two delegate
|
|
|
|
/// array handle and makes a new handle that access the corresponding entries
|
|
|
|
/// in these arrays as a pair.
|
|
|
|
///
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename FirstHandleType, typename SecondHandleType>
|
2015-04-23 17:20:03 +00:00
|
|
|
class ArrayHandleZip
|
2017-05-18 14:29:41 +00:00
|
|
|
: public internal::ArrayHandleZipTraits<FirstHandleType, SecondHandleType>::Superclass
|
2015-04-23 17:20:03 +00:00
|
|
|
{
|
|
|
|
// If the following line gives a compile error, then the FirstHandleType
|
|
|
|
// template argument is not a valid ArrayHandle type.
|
|
|
|
VTKM_IS_ARRAY_HANDLE(FirstHandleType);
|
|
|
|
|
|
|
|
// If the following line gives a compile error, then the SecondHandleType
|
|
|
|
// template argument is not a valid ArrayHandle type.
|
|
|
|
VTKM_IS_ARRAY_HANDLE(SecondHandleType);
|
|
|
|
|
2015-09-20 06:28:11 +00:00
|
|
|
public:
|
2015-10-21 19:36:27 +00:00
|
|
|
VTKM_ARRAY_HANDLE_SUBCLASS(
|
2017-05-26 17:53:28 +00:00
|
|
|
ArrayHandleZip,
|
|
|
|
(ArrayHandleZip<FirstHandleType, SecondHandleType>),
|
2017-05-18 14:29:41 +00:00
|
|
|
(typename internal::ArrayHandleZipTraits<FirstHandleType, SecondHandleType>::Superclass));
|
2015-04-23 17:20:03 +00:00
|
|
|
|
2015-09-20 06:28:11 +00:00
|
|
|
private:
|
2017-08-16 15:34:21 +00:00
|
|
|
using StorageType = vtkm::cont::internal::Storage<ValueType, StorageTag>;
|
2015-04-23 17:20:03 +00:00
|
|
|
|
2015-09-20 06:28:11 +00:00
|
|
|
public:
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
ArrayHandleZip(const FirstHandleType& firstArray, const SecondHandleType& secondArray)
|
|
|
|
: Superclass(StorageType(firstArray, secondArray))
|
|
|
|
{
|
|
|
|
}
|
2015-04-23 17:20:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// A convenience function for creating an ArrayHandleZip. It takes the two
|
|
|
|
/// arrays to be zipped together.
|
|
|
|
///
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename FirstHandleType, typename SecondHandleType>
|
|
|
|
VTKM_CONT vtkm::cont::ArrayHandleZip<FirstHandleType, SecondHandleType> make_ArrayHandleZip(
|
2017-05-26 17:53:28 +00:00
|
|
|
const FirstHandleType& first,
|
|
|
|
const SecondHandleType& second)
|
2015-04-23 17:20:03 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
return ArrayHandleZip<FirstHandleType, SecondHandleType>(first, second);
|
2015-04-23 17:20:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace vtkm::cont
|
|
|
|
|
|
|
|
#endif //vtk_m_cont_ArrayHandleZip_h
|