Merge branch 'whole-array-control-signature' into 'master'

WholeArray tag for ControlSignature

Add WholeArrayIn, WholeArrayInOut, and WholeArrayOut tags for ControlSignature. They tags behave similarly to using an ExecObject tag with an ExecutionWholeArray or ExecutionWholeArrayConst object. However, the WholeArray* tags can simplify some implementations in two ways. First, it allows you to specify more precisely what data is passed in. You have to pass in an ArrayHandle or else an error will occur (as opposed to be able to pass in any type of execution object). Second, this allows you to easily pass in arrays stored in DynamicArrayHandle objects. The Invoke mechanism will automatically find the appropriate static class. This cannot be done easily with ExecutionWholeArray.


See merge request !284
This commit is contained in:
Kenneth Moreland 2015-12-07 18:24:54 -05:00
commit 763de94aca
11 changed files with 604 additions and 11 deletions

@ -41,6 +41,10 @@ struct TypeListTagId2 : vtkm::ListTagBase<vtkm::Id2> { };
///
struct TypeListTagId3 : vtkm::ListTagBase<vtkm::Id3> { };
/// A list containing the type vtkm::IdComponent
///
struct TypeListTagIdComponent : vtkm::ListTagBase<vtkm::IdComponent> { };
/// A list containing types used to index arrays. Contains vtkm::Id, vtkm::Id2,
/// and vtkm::Id3.
///

@ -28,6 +28,9 @@ set(headers
TransportTagArrayOut.h
TransportTagExecObject.h
TransportTagTopologyIn.h
TransportTagWholeArrayIn.h
TransportTagWholeArrayInOut.h
TransportTagWholeArrayOut.h
TypeCheck.h
TypeCheckTagArray.h
TypeCheckTagExecObject.h

@ -0,0 +1,74 @@
//============================================================================
// 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 2015 Sandia Corporation.
// Copyright 2015 UT-Battelle, LLC.
// Copyright 2015 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// 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_arg_TransportTagWholeArrayIn_h
#define vtk_m_cont_arg_TransportTagWholeArrayIn_h
#include <vtkm/Types.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/arg/Transport.h>
#include <vtkm/exec/ExecutionWholeArray.h>
namespace vtkm {
namespace cont {
namespace arg {
/// \brief \c Transport tag for in-place arrays with random access.
///
/// \c TransportTagWholeArrayIn is a tag used with the \c Transport class to
/// transport \c ArrayHandle objects for input data.
///
/// The worklet will have random access to the array through a portal
/// interface.
///
struct TransportTagWholeArrayIn { };
template<typename ContObjectType, typename Device>
struct Transport<
vtkm::cont::arg::TransportTagWholeArrayIn, ContObjectType, Device>
{
// If you get a compile error here, it means you tried to use an object that
// is not an array handle as an argument that is expected to be one.
VTKM_IS_ARRAY_HANDLE(ContObjectType);
typedef typename ContObjectType::ValueType ValueType;
typedef typename ContObjectType::StorageTag StorageTag;
typedef vtkm::exec::ExecutionWholeArrayConst<ValueType, StorageTag, Device>
ExecObjectType;
VTKM_CONT_EXPORT
ExecObjectType operator()(ContObjectType array, vtkm::Id) const
{
// 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.
return ExecObjectType(array);
}
};
}
}
} // namespace vtkm::cont::arg
#endif //vtk_m_cont_arg_TransportTagWholeArrayIn_h

@ -0,0 +1,76 @@
//============================================================================
// 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 2015 Sandia Corporation.
// Copyright 2015 UT-Battelle, LLC.
// Copyright 2015 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// 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_arg_TransportTagWholeArrayInOut_h
#define vtk_m_cont_arg_TransportTagWholeArrayInOut_h
#include <vtkm/Types.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/arg/Transport.h>
#include <vtkm/exec/ExecutionWholeArray.h>
namespace vtkm {
namespace cont {
namespace arg {
/// \brief \c Transport tag for in-place arrays with random access.
///
/// \c TransportTagWholeArrayInOut 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 worklet will have random access to the array through a portal
/// interface, but care should be taken to not write a value in one instance
/// that will be read by or overridden by another entry.
///
struct TransportTagWholeArrayInOut { };
template<typename ContObjectType, typename Device>
struct Transport<
vtkm::cont::arg::TransportTagWholeArrayInOut, ContObjectType, Device>
{
// If you get a compile error here, it means you tried to use an object that
// is not an array handle as an argument that is expected to be one.
VTKM_IS_ARRAY_HANDLE(ContObjectType);
typedef typename ContObjectType::ValueType ValueType;
typedef typename ContObjectType::StorageTag StorageTag;
typedef vtkm::exec::ExecutionWholeArray<ValueType, StorageTag, Device>
ExecObjectType;
VTKM_CONT_EXPORT
ExecObjectType operator()(ContObjectType array, vtkm::Id) const
{
// 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.
return ExecObjectType(array);
}
};
}
}
} // namespace vtkm::cont::arg
#endif //vtk_m_cont_arg_TransportTagWholeArrayInOut_h

@ -0,0 +1,76 @@
//============================================================================
// 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 2015 Sandia Corporation.
// Copyright 2015 UT-Battelle, LLC.
// Copyright 2015 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// 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_arg_TransportTagWholeArrayOut_h
#define vtk_m_cont_arg_TransportTagWholeArrayOut_h
#include <vtkm/Types.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/arg/Transport.h>
#include <vtkm/exec/ExecutionWholeArray.h>
namespace vtkm {
namespace cont {
namespace arg {
/// \brief \c Transport tag for in-place arrays with random access.
///
/// \c TransportTagWholeArrayOut is a tag used with the \c Transport class to
/// transport \c ArrayHandle objects for output data. The array needs to be
/// allocated before passed as an argument to Invoke.
///
/// The worklet will have random access to the array through a portal
/// interface, but care should be taken to not write a value in one instance
/// that will be overridden by another entry.
///
struct TransportTagWholeArrayOut { };
template<typename ContObjectType, typename Device>
struct Transport<
vtkm::cont::arg::TransportTagWholeArrayOut, ContObjectType, Device>
{
// If you get a compile error here, it means you tried to use an object that
// is not an array handle as an argument that is expected to be one.
VTKM_IS_ARRAY_HANDLE(ContObjectType);
typedef typename ContObjectType::ValueType ValueType;
typedef typename ContObjectType::StorageTag StorageTag;
typedef vtkm::exec::ExecutionWholeArray<ValueType, StorageTag, Device>
ExecObjectType;
VTKM_CONT_EXPORT
ExecObjectType operator()(ContObjectType array, vtkm::Id) const
{
// 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.
return ExecObjectType(array, array.GetNumberOfValues());
}
};
}
}
} // namespace vtkm::cont::arg
#endif //vtk_m_cont_arg_TransportTagWholeArrayOut_h

@ -24,6 +24,7 @@ set(unit_tests
UnitTestTransportArrayInOut.cxx
UnitTestTransportArrayOut.cxx
UnitTestTransportExecObject.cxx
UnitTestTransportWholeArray.cxx
UnitTestTypeCheckArray.cxx
UnitTestTypeCheckExecObject.cxx
)

@ -0,0 +1,163 @@
//============================================================================
// 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 2015 Sandia Corporation.
// Copyright 2015 UT-Battelle, LLC.
// Copyright 2015 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// 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.
//============================================================================
#include <vtkm/cont/arg/TransportTagWholeArrayIn.h>
#include <vtkm/cont/arg/TransportTagWholeArrayInOut.h>
#include <vtkm/cont/arg/TransportTagWholeArrayOut.h>
#include <vtkm/exec/FunctorBase.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/DeviceAdapter.h>
#include <vtkm/cont/testing/Testing.h>
namespace {
static const vtkm::Id ARRAY_SIZE = 10;
#define OFFSET 10
template<typename PortalType>
struct TestOutKernel : public vtkm::exec::FunctorBase
{
PortalType Portal;
VTKM_EXEC_EXPORT
void operator()(vtkm::Id index) const
{
if (this->Portal.GetNumberOfValues() != ARRAY_SIZE)
{
this->RaiseError("Out whole array has wrong size.");
}
typedef typename PortalType::ValueType ValueType;
this->Portal.Set(index, TestValue(index, ValueType()));
}
};
template<typename PortalType>
struct TestInKernel : public vtkm::exec::FunctorBase
{
PortalType Portal;
VTKM_EXEC_EXPORT
void operator()(vtkm::Id index) const
{
if (this->Portal.GetNumberOfValues() != ARRAY_SIZE)
{
this->RaiseError("In whole array has wrong size.");
}
typedef typename PortalType::ValueType ValueType;
if (!test_equal(this->Portal.Get(index), TestValue(index, ValueType())))
{
this->RaiseError("Got bad execution object.");
}
}
};
template<typename PortalType>
struct TestInOutKernel : public vtkm::exec::FunctorBase
{
PortalType Portal;
VTKM_EXEC_EXPORT
void operator()(vtkm::Id index) const
{
if (this->Portal.GetNumberOfValues() != ARRAY_SIZE)
{
this->RaiseError("In/Out whole array has wrong size.");
}
typedef typename PortalType::ValueType ValueType;
this->Portal.Set(index, this->Portal.Get(index) + ValueType(OFFSET));
}
};
template<typename Device>
struct TryWholeArrayType
{
template<typename T>
void operator()(T) const
{
typedef vtkm::cont::ArrayHandle<T> ArrayHandleType;
typedef vtkm::cont::arg::Transport<
vtkm::cont::arg::TransportTagWholeArrayIn, ArrayHandleType, Device>
InTransportType;
typedef vtkm::cont::arg::Transport<
vtkm::cont::arg::TransportTagWholeArrayInOut, ArrayHandleType, Device>
InOutTransportType;
typedef vtkm::cont::arg::Transport<
vtkm::cont::arg::TransportTagWholeArrayOut, ArrayHandleType, Device>
OutTransportType;
ArrayHandleType array;
array.Allocate(ARRAY_SIZE);
std::cout << "Check Transport WholeArrayOut" << std::endl;
TestOutKernel<typename OutTransportType::ExecObjectType> outKernel;
outKernel.Portal = OutTransportType()(array, -1);
vtkm::cont::DeviceAdapterAlgorithm<Device>::Schedule(outKernel, ARRAY_SIZE);
CheckPortal(array.GetPortalConstControl());
std::cout << "Check Transport WholeArrayIn" << std::endl;
TestInKernel<typename InTransportType::ExecObjectType> inKernel;
inKernel.Portal = InTransportType()(array, -1);
vtkm::cont::DeviceAdapterAlgorithm<Device>::Schedule(inKernel, ARRAY_SIZE);
std::cout << "Check Transport WholeArrayInOut" << std::endl;
TestInOutKernel<typename InOutTransportType::ExecObjectType> inOutKernel;
inOutKernel.Portal = InOutTransportType()(array, -1);
vtkm::cont::DeviceAdapterAlgorithm<Device>::Schedule(inOutKernel, ARRAY_SIZE);
VTKM_TEST_ASSERT(array.GetNumberOfValues() == ARRAY_SIZE,
"Array size wrong?");
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
{
T expectedValue = TestValue(index, T()) + T(OFFSET);
T retrievedValue = array.GetPortalConstControl().Get(index);
VTKM_TEST_ASSERT(test_equal(expectedValue, retrievedValue),
"In/Out array not set correctly.");
}
}
};
template<typename Device>
void TryArrayOutTransport(Device)
{
vtkm::testing::Testing::TryTypes(TryWholeArrayType<Device>(),
vtkm::TypeListTagCommon());
}
void TestWholeArrayTransport()
{
std::cout << "Trying WholeArray transport." << std::endl;
TryArrayOutTransport(VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
}
} // Anonymous namespace
int UnitTestTransportWholeArray(int, char *[])
{
return vtkm::cont::testing::Testing::Run(TestWholeArrayTransport);
}

@ -24,7 +24,6 @@
#include <vtkm/VectorAnalysis.h>
#include <vtkm/exec/CellDerivative.h>
#include <vtkm/exec/ExecutionWholeArray.h>
#include <vtkm/exec/ParametricCoordinates.h>
#include <vtkm/cont/ArrayHandle.h>
@ -57,10 +56,11 @@ public:
class ClassifyCell : public vtkm::worklet::WorkletMapPointToCell
{
public:
typedef void ControlSignature(FieldInPoint<Scalar> inNodes,
TopologyIn topology,
FieldOutCell<> outNumTriangles,
ExecObject numTrianglesTable);
typedef void ControlSignature(
FieldInPoint<Scalar> inNodes,
TopologyIn topology,
FieldOutCell<> outNumTriangles,
WholeArrayIn<IdComponentType> numTrianglesTable);
typedef void ExecutionSignature(_1, _3, _4);
typedef _2 InputDomain;
@ -108,7 +108,7 @@ public:
FieldOutCell<> interpolationIds,
FieldOutCell<> vertexOut, // Vertices for output triangles
FieldOutCell<> normalsOut, // Estimated normals (one per tri vertex)
ExecObject TriTable // An array portal with the triangle table
WholeArrayIn<IdComponentType> TriTable // An array portal with the triangle table
);
typedef void ExecutionSignature(
CellShape, _2, _3, _4, _5, _6, _7, _8, VisitIndex, FromIndices);
@ -249,9 +249,6 @@ public:
vtkm::cont::make_ArrayHandle(vtkm::worklet::internal::triTable,
256*16);
typedef vtkm::exec::ExecutionWholeArrayConst<vtkm::IdComponent, VTKM_DEFAULT_STORAGE_TAG, DeviceAdapter>
TableArrayExecObjectType;
vtkm::cont::ArrayHandle<vtkm::IdComponent> numOutputTrisPerCell;
// Call the ClassifyCell functor to compute the Marching Cubes case numbers
@ -266,7 +263,7 @@ public:
classifyCellDispatcher.Invoke(field,
cellSet,
numOutputTrisPerCell,
TableArrayExecObjectType(numTrianglesTable));
numTrianglesTable);
IsosurfaceGenerate isosurface(isovalue,
numOutputTrisPerCell,
@ -283,7 +280,7 @@ public:
vtkm::cont::make_ArrayHandleGroupVec<3>(this->InterpolationIds),
vtkm::cont::make_ArrayHandleGroupVec<3>(vertices),
vtkm::cont::make_ArrayHandleGroupVec<3>(normals),
TableArrayExecObjectType(triangleTableArray));
triangleTableArray);
}
template<typename ArrayHandleIn, typename ArrayHandleOut>

@ -32,6 +32,10 @@
#include <vtkm/cont/arg/ControlSignatureTagBase.h>
#include <vtkm/cont/arg/TransportTagExecObject.h>
#include <vtkm/cont/arg/TransportTagWholeArrayIn.h>
#include <vtkm/cont/arg/TransportTagWholeArrayInOut.h>
#include <vtkm/cont/arg/TransportTagWholeArrayOut.h>
#include <vtkm/cont/arg/TypeCheckTagArray.h>
#include <vtkm/cont/arg/TypeCheckTagExecObject.h>
#include <vtkm/worklet/ScatterIdentity.h>
@ -113,6 +117,12 @@ public:
/// ControlSignature tags to specify the types of worklet arguments.
typedef vtkm::TypeListTagId3 Id3Type;
/// \brief A type list containing the type vtkm::IdComponent.
///
/// This is a convenience type to use as template arguments to \c
/// ControlSignature tags to specify the types of worklet arguments.
typedef vtkm::TypeListTagIdComponent IdComponentType;
/// \brief A list of types commonly used for indexing.
///
/// This is a convenience type to use as template arguments to \c
@ -179,6 +189,60 @@ public:
/// ControlSignature tags to specify the types of worklet arguments.
typedef vtkm::TypeListTagAll AllTypes;
/// \c ControlSignature tag for whole input arrays.
///
/// The \c WholeArrayIn control signature tag specifies an \c ArrayHandle
/// passed to the \c Invoke operation of the dispatcher. This is converted
/// to an \c ArrayPortal object and passed to the appropriate worklet
/// operator argument with one of the default args.
///
/// The template operator specifies all the potential value types of the
/// array. The default value type is all types.
///
template<typename TypeList = AllTypes>
struct WholeArrayIn : vtkm::cont::arg::ControlSignatureTagBase {
typedef vtkm::cont::arg::TypeCheckTagArray<TypeList> TypeCheckTag;
typedef vtkm::cont::arg::TransportTagWholeArrayIn TransportTag;
typedef vtkm::exec::arg::FetchTagExecObject FetchTag;
};
/// \c ControlSignature tag for whole output arrays.
///
/// The \c WholeArrayOut control signature tag specifies an \c ArrayHandle
/// passed to the \c Invoke operation of the dispatcher. This is converted to
/// an \c ArrayPortal object and passed to the appropriate worklet operator
/// argument with one of the default args. Care should be taken to not write
/// a value in one instance that will be overridden by another entry.
///
/// The template operator specifies all the potential value types of the
/// array. The default value type is all types.
///
template<typename TypeList = AllTypes>
struct WholeArrayOut : vtkm::cont::arg::ControlSignatureTagBase {
typedef vtkm::cont::arg::TypeCheckTagArray<TypeList> TypeCheckTag;
typedef vtkm::cont::arg::TransportTagWholeArrayOut TransportTag;
typedef vtkm::exec::arg::FetchTagExecObject FetchTag;
};
/// \c ControlSignature tag for whole input/output arrays.
///
/// The \c WholeArrayOut control signature tag specifies an \c ArrayHandle
/// passed to the \c Invoke operation of the dispatcher. This is converted to
/// an \c ArrayPortal object and passed to the appropriate worklet operator
/// argument with one of the default args. Care should be taken to not write
/// a value in one instance that will be read by or overridden by another
/// entry.
///
/// The template operator specifies all the potential value types of the
/// array. The default value type is all types.
///
template<typename TypeList = AllTypes>
struct WholeArrayInOut : vtkm::cont::arg::ControlSignatureTagBase {
typedef vtkm::cont::arg::TypeCheckTagArray<TypeList> TypeCheckTag;
typedef vtkm::cont::arg::TransportTagWholeArrayInOut TransportTag;
typedef vtkm::exec::arg::FetchTagExecObject FetchTag;
};
/// \brief Creates a \c ThreadIndices object.
///
/// Worklet types can add additional indices by returning different object

@ -34,6 +34,7 @@ set(unit_tests
UnitTestThreshold.cxx
UnitTestWorkletMapField.cxx
UnitTestWorkletMapFieldExecArg.cxx
UnitTestWorkletMapFieldWholeArray.cxx
UnitTestWorkletMapTopologyExplicit.cxx
UnitTestWorkletMapTopologyRegular.cxx
UnitTestVertexClustering.cxx

@ -0,0 +1,134 @@
//============================================================================
// 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 2015 Sandia Corporation.
// Copyright 2015 UT-Battelle, LLC.
// Copyright 2015 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// 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.
//============================================================================
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/ArrayHandleIndex.h>
#include <vtkm/cont/DynamicArrayHandle.h>
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/worklet/WorkletMapField.h>
#include <vtkm/cont/testing/Testing.h>
class TestWholeArrayWorklet : public vtkm::worklet::WorkletMapField
{
public:
typedef void ControlSignature(WholeArrayIn<>,
WholeArrayInOut<>,
WholeArrayOut<>);
typedef void ExecutionSignature(WorkIndex, _1, _2, _3);
template<typename InPortalType,
typename InOutPortalType,
typename OutPortalType>
VTKM_EXEC_EXPORT
void operator()(const vtkm::Id &index,
const InPortalType &inPortal,
const InOutPortalType &inOutPortal,
const OutPortalType &outPortal) const
{
typedef typename InPortalType::ValueType inT;
if (!test_equal(inPortal.Get(index), TestValue(index, inT())))
{
this->RaiseError("Got wrong input value.");
}
typedef typename InOutPortalType::ValueType inOutT;
if (!test_equal(inOutPortal.Get(index),
TestValue(index, inOutT()) + inOutT(100)))
{
this->RaiseError("Got wrong input/output value.");
}
inOutPortal.Set(index, TestValue(index, inOutT()));
typedef typename OutPortalType::ValueType outT;
outPortal.Set(index, TestValue(index, outT()));
}
};
namespace map_whole_array {
static const vtkm::Id ARRAY_SIZE = 10;
template<typename WorkletType>
struct DoTestWorklet
{
// This just demonstrates that the WholeArray tags support dynamic arrays.
VTKM_CONT_EXPORT
void CallWorklet(const vtkm::cont::DynamicArrayHandle &inArray,
const vtkm::cont::DynamicArrayHandle &inOutArray,
const vtkm::cont::DynamicArrayHandle &outArray) const
{
std::cout << "Create and run dispatcher." << std::endl;
vtkm::worklet::DispatcherMapField<WorkletType> dispatcher;
dispatcher.Invoke(inArray, inOutArray, outArray);
}
template<typename T>
VTKM_CONT_EXPORT
void operator()(T) const
{
std::cout << "Set up data." << std::endl;
T inArray[ARRAY_SIZE];
T inOutArray[ARRAY_SIZE];
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
{
inArray[index] = TestValue(index, T());
inOutArray[index] = TestValue(index, T()) + T(100);
}
vtkm::cont::ArrayHandle<T> inHandle =
vtkm::cont::make_ArrayHandle(inArray, ARRAY_SIZE);
vtkm::cont::ArrayHandle<T> inOutHandle =
vtkm::cont::make_ArrayHandle(inOutArray, ARRAY_SIZE);
vtkm::cont::ArrayHandle<T> outHandle;
// Output arrays must be preallocated.
outHandle.Allocate(ARRAY_SIZE);
this->CallWorklet(vtkm::cont::DynamicArrayHandle(inHandle),
vtkm::cont::DynamicArrayHandle(inOutHandle),
vtkm::cont::DynamicArrayHandle(outHandle));
std::cout << "Check result." << std::endl;
CheckPortal(inOutHandle.GetPortalConstControl());
CheckPortal(outHandle.GetPortalConstControl());
}
};
void TestWorkletMapFieldExecArg()
{
typedef vtkm::cont::internal::DeviceAdapterTraits<
VTKM_DEFAULT_DEVICE_ADAPTER_TAG> DeviceAdapterTraits;
std::cout << "Testing Worklet with WholeArray on device adapter: "
<< DeviceAdapterTraits::GetId() << std::endl;
std::cout << "--- Worklet accepting all types." << std::endl;
vtkm::testing::Testing::TryTypes(
map_whole_array::DoTestWorklet< TestWholeArrayWorklet >(),
vtkm::TypeListTagCommon());
}
} // anonymous namespace
int UnitTestWorkletMapFieldWholeArray(int, char *[])
{
return vtkm::cont::testing::Testing::Run(map_whole_array::TestWorkletMapFieldExecArg);
}