Commit d879188d authored by Kenneth Moreland's avatar Kenneth Moreland

Make DispatcherBase invoke using a TryExecute

Rather than force all dispatchers to be templated on a device adapter,
instead use a TryExecute internally within the invoke to select a device
adapter.

Because this removes the need to declare a device when invoking a
worklet, this commit also removes the need to declare a device in
several other areas of the code.
parent 4e0e829b
......@@ -631,8 +631,9 @@ private:
vtkm::cont::ArrayHandle<Value> result;
Timer timer;
vtkm::worklet::DispatcherMapField<InterpolateField, DeviceAdapterTag>().Invoke(
this->EdgePairHandle, this->WeightHandle, this->FieldHandle, result);
vtkm::worklet::DispatcherMapField<InterpolateField> dispatcher;
dispatcher.SetDevice(DeviceAdapterTag());
dispatcher.Invoke(this->EdgePairHandle, this->WeightHandle, this->FieldHandle, result);
return timer.GetElapsedTime();
}
......@@ -663,8 +664,9 @@ private:
vtkm::cont::ArrayHandle<Value> result;
Timer timer;
vtkm::worklet::DispatcherMapField<InterpolateField, DeviceAdapterTag>().Invoke(
dedges, dweight, dfield, result);
vtkm::worklet::DispatcherMapField<InterpolateField> dispatcher;
dispatcher.SetDevice(DeviceAdapterTag());
dispatcher.Invoke(dedges, dweight, dfield, result);
return timer.GetElapsedTime();
}
......@@ -719,7 +721,7 @@ private:
vtkm::Float64 operator()()
{
using EvalWorklet = EvaluateImplicitFunction<vtkm::Sphere>;
using EvalDispatcher = vtkm::worklet::DispatcherMapField<EvalWorklet, DeviceAdapterTag>;
using EvalDispatcher = vtkm::worklet::DispatcherMapField<EvalWorklet>;
auto handle = vtkm::cont::make_ImplicitFunctionHandle(Internal.Sphere1);
auto function =
......@@ -727,7 +729,9 @@ private:
EvalWorklet eval(function);
vtkm::cont::Timer<DeviceAdapterTag> timer;
EvalDispatcher(eval).Invoke(this->Internal.Points, this->Internal.Result);
EvalDispatcher dispatcher(eval);
dispatcher.SetDevice(DeviceAdapterTag());
dispatcher.Invoke(this->Internal.Points, this->Internal.Result);
return timer.GetElapsedTime();
}
......@@ -755,13 +759,15 @@ private:
vtkm::Float64 operator()()
{
using EvalWorklet = EvaluateImplicitFunction<vtkm::ImplicitFunction>;
using EvalDispatcher = vtkm::worklet::DispatcherMapField<EvalWorklet, DeviceAdapterTag>;
using EvalDispatcher = vtkm::worklet::DispatcherMapField<EvalWorklet>;
auto sphere = vtkm::cont::make_ImplicitFunctionHandle(Internal.Sphere1);
EvalWorklet eval(sphere.PrepareForExecution(DeviceAdapterTag()));
vtkm::cont::Timer<DeviceAdapterTag> timer;
EvalDispatcher(eval).Invoke(this->Internal.Points, this->Internal.Result);
EvalDispatcher dispatcher(eval);
dispatcher.SetDevice(DeviceAdapterTag());
dispatcher.Invoke(this->Internal.Points, this->Internal.Result);
return timer.GetElapsedTime();
}
......@@ -789,7 +795,7 @@ private:
vtkm::Float64 operator()()
{
using EvalWorklet = Evaluate2ImplicitFunctions<vtkm::Sphere, vtkm::Sphere>;
using EvalDispatcher = vtkm::worklet::DispatcherMapField<EvalWorklet, DeviceAdapterTag>;
using EvalDispatcher = vtkm::worklet::DispatcherMapField<EvalWorklet>;
auto h1 = vtkm::cont::make_ImplicitFunctionHandle(Internal.Sphere1);
auto h2 = vtkm::cont::make_ImplicitFunctionHandle(Internal.Sphere2);
......@@ -798,7 +804,9 @@ private:
EvalWorklet eval(f1, f2);
vtkm::cont::Timer<DeviceAdapterTag> timer;
EvalDispatcher(eval).Invoke(this->Internal.Points, this->Internal.Result);
EvalDispatcher dispatcher(eval);
dispatcher.SetDevice(DeviceAdapterTag());
dispatcher.Invoke(this->Internal.Points, this->Internal.Result);
return timer.GetElapsedTime();
}
......@@ -827,7 +835,7 @@ private:
{
using EvalWorklet =
Evaluate2ImplicitFunctions<vtkm::ImplicitFunction, vtkm::ImplicitFunction>;
using EvalDispatcher = vtkm::worklet::DispatcherMapField<EvalWorklet, DeviceAdapterTag>;
using EvalDispatcher = vtkm::worklet::DispatcherMapField<EvalWorklet>;
auto s1 = vtkm::cont::make_ImplicitFunctionHandle(Internal.Sphere1);
auto s2 = vtkm::cont::make_ImplicitFunctionHandle(Internal.Sphere2);
......@@ -835,7 +843,9 @@ private:
s2.PrepareForExecution(DeviceAdapterTag()));
vtkm::cont::Timer<DeviceAdapterTag> timer;
EvalDispatcher(eval).Invoke(this->Internal.Points, this->Internal.Result);
EvalDispatcher dispatcher(eval);
dispatcher.SetDevice(DeviceAdapterTag());
dispatcher.Invoke(this->Internal.Points, this->Internal.Result);
return timer.GetElapsedTime();
}
......
......@@ -934,7 +934,8 @@ void CreateFields(bool needPointScalars, bool needCellScalars, bool needPointVec
vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::FloatDefault, 3>> pvecs;
PointVectorGenerator worklet(bounds);
vtkm::worklet::DispatcherMapField<PointVectorGenerator, Device> dispatch(worklet);
vtkm::worklet::DispatcherMapField<PointVectorGenerator> dispatch(worklet);
dispatch.SetDevice(Device());
dispatch.Invoke(points, pvecs);
InputDataSet.AddField(
vtkm::cont::Field("GeneratedPointVectors", vtkm::cont::Field::Association::POINTS, pvecs));
......
# Make DispatcherBase invoke using a TryExecute
Rather than force all dispatchers to be templated on a device adapter,
instead use a TryExecute internally within the invoke to select a device
adapter.
Because this removes the need to declare a device when invoking a worklet,
this commit also removes the need to declare a device in several other
areas of the code.
This changes touches quite a bit a code. The first pass of the change
usually does the minimum amount of work, which is to change the
compile-time specification of the device to a run-time call to `SetDevice`
on the dispatcher. Although functionally equivalent, it might mean calling
`TryExecute` within itself.
......@@ -139,7 +139,7 @@ public:
this->PrintedDeviceMsg = true;
}
using DispatcherType = vtkm::worklet::DispatcherPointNeighborhood<UpdateLifeState, Device>;
using DispatcherType = vtkm::worklet::DispatcherPointNeighborhood<UpdateLifeState>;
vtkm::cont::ArrayHandle<vtkm::UInt8> state;
......@@ -153,7 +153,9 @@ public:
input.GetField("state", vtkm::cont::Field::Association::POINTS).GetData().CopyTo(prevstate);
//Update the game state
DispatcherType().Invoke(vtkm::filter::ApplyPolicy(cells, policy), prevstate, state, colors);
DispatcherType dispatcher;
dispatcher.SetDevice(Device());
dispatcher.Invoke(vtkm::filter::ApplyPolicy(cells, policy), prevstate, state, colors);
//save the results
vtkm::cont::DataSet output;
......
......@@ -53,7 +53,7 @@ vtkm::cont::DataSet make_test3DImageData(vtkm::Id3 dims)
vtkm::cont::DataSet ds = Builder::Create(dims);
vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::FloatDefault, 3>> field;
vtkm::worklet::DispatcherMapField<WaveField, vtkm::cont::DeviceAdapterTagSerial> dispatcher;
vtkm::worklet::DispatcherMapField<WaveField> dispatcher;
dispatcher.Invoke(ds.GetCoordinateSystem(), field);
FieldAdd::AddPointField(ds, "vec_field", field);
......
......@@ -135,15 +135,16 @@ VTKM_CONT void BoundingIntervalHierarchy::CalculatePlaneSplitCost(
vtkm::cont::ArrayHandle<vtkm::FloatDefault> splitPlanes;
vtkm::worklet::spatialstructure::SplitPlaneCalculatorWorklet splitPlaneCalcWorklet(planeIndex,
numPlanes);
vtkm::worklet::DispatcherMapField<vtkm::worklet::spatialstructure::SplitPlaneCalculatorWorklet,
DeviceAdapter>
vtkm::worklet::DispatcherMapField<vtkm::worklet::spatialstructure::SplitPlaneCalculatorWorklet>
splitDispatcher(splitPlaneCalcWorklet);
splitDispatcher.SetDevice(DeviceAdapter());
splitDispatcher.Invoke(segmentRanges, splitPlanes);
// Check if a point is to the left of the split plane or right
vtkm::cont::ArrayHandle<vtkm::Id> isLEQOfSplitPlane, isROfSplitPlane;
vtkm::worklet::DispatcherMapField<vtkm::worklet::spatialstructure::LEQWorklet, DeviceAdapter>()
.Invoke(coords, splitPlanes, isLEQOfSplitPlane, isROfSplitPlane);
vtkm::worklet::DispatcherMapField<vtkm::worklet::spatialstructure::LEQWorklet> LEQDispatcher;
LEQDispatcher.SetDevice(DeviceAdapter());
LEQDispatcher.Invoke(coords, splitPlanes, isLEQOfSplitPlane, isROfSplitPlane);
// Count of points to the left
vtkm::cont::ArrayHandle<vtkm::Id> pointsToLeft;
......@@ -270,9 +271,11 @@ public:
//START_TIMER(s12);
CoordsArrayHandle centerXs, centerYs, centerZs;
RangeArrayHandle xRanges, yRanges, zRanges;
vtkm::worklet::DispatcherMapTopology<vtkm::worklet::spatialstructure::CellRangesExtracter,
DeviceAdapter>()
.Invoke(cellSet, points, xRanges, yRanges, zRanges, centerXs, centerYs, centerZs);
vtkm::worklet::DispatcherMapTopology<vtkm::worklet::spatialstructure::CellRangesExtracter>
cellRangesExtracterDispatcher;
cellRangesExtracterDispatcher.SetDevice(DeviceAdapter());
cellRangesExtracterDispatcher.Invoke(
cellSet, points, xRanges, yRanges, zRanges, centerXs, centerYs, centerZs);
//PRINT_TIMER("1.2", s12);
bool done = false;
......
......@@ -138,8 +138,9 @@ public:
auto coordinates =
this->Coordinates.GetData().Cast<vtkm::cont::ArrayHandleUniformPointCoordinates>();
auto cellset = this->CellSet.ResetCellSetList(StructuredCellSetList());
vtkm::worklet::DispatcherMapField<FindCellWorklet, DeviceAdapter>().Invoke(
points, cellset, coordinates, cellIds, parametricCoords);
vtkm::worklet::DispatcherMapField<FindCellWorklet> dispatcher;
dispatcher.SetDevice(DeviceAdapter());
dispatcher.Invoke(points, cellset, coordinates, cellIds, parametricCoords);
}
else
{
......
......@@ -513,8 +513,9 @@ public:
// 2: For each cell, find the number of top level bins they intersect
vtkm::cont::ArrayHandle<vtkm::Id> binCounts;
CountBinsL1 countL1(ls.TopLevel);
vtkm::worklet::DispatcherMapTopology<CountBinsL1, DeviceAdapter>(countL1).Invoke(
cellset, coords, binCounts);
vtkm::worklet::DispatcherMapTopology<CountBinsL1> countL1Dispatcher(countL1);
countL1Dispatcher.SetDevice(DeviceAdapter());
countL1Dispatcher.Invoke(cellset, coords, binCounts);
// 3: Total number of unique (cell, bin) pairs (for pre-allocating arrays)
vtkm::Id numPairsL1 = Algorithm::ScanExclusive(binCounts, binCounts);
......@@ -523,8 +524,9 @@ public:
vtkm::cont::ArrayHandle<vtkm::Id> binIds;
binIds.Allocate(numPairsL1);
FindBinsL1 findL1(ls.TopLevel);
vtkm::worklet::DispatcherMapTopology<FindBinsL1, DeviceAdapter>(findL1).Invoke(
cellset, coords, binCounts, binIds);
vtkm::worklet::DispatcherMapTopology<FindBinsL1> findL1Dispatcher(findL1);
findL1Dispatcher.SetDevice(DeviceAdapter());
findL1Dispatcher.Invoke(cellset, coords, binCounts, binIds);
binCounts.ReleaseResources();
// 5: From above, find the number of cells that intersect each top level bin
......@@ -544,8 +546,9 @@ public:
Algorithm::Copy(vtkm::cont::make_ArrayHandleConstant(DimVec3(0), numberOfBins),
ls.LeafDimensions);
GenerateBinsL1 generateL1(ls.TopLevel.BinSize, this->DensityL2);
vtkm::worklet::DispatcherMapField<GenerateBinsL1, DeviceAdapter>(generateL1)
.Invoke(bins, cellsPerBin, ls.LeafDimensions);
vtkm::worklet::DispatcherMapField<GenerateBinsL1> generateL1Dispatcher(generateL1);
generateL1Dispatcher.SetDevice(DeviceAdapter());
generateL1Dispatcher.Invoke(bins, cellsPerBin, ls.LeafDimensions);
bins.ReleaseResources();
cellsPerBin.ReleaseResources();
......@@ -557,8 +560,9 @@ public:
// 8: For each cell, find the number of l2 bins they intersect
CountBinsL2 countL2(ls.TopLevel);
vtkm::worklet::DispatcherMapTopology<CountBinsL2, DeviceAdapter>(countL2).Invoke(
cellset, coords, ls.LeafDimensions, binCounts);
vtkm::worklet::DispatcherMapTopology<CountBinsL2> countL2Dispatcher(countL2);
countL2Dispatcher.SetDevice(DeviceAdapter());
countL2Dispatcher.Invoke(cellset, coords, ls.LeafDimensions, binCounts);
// 9: Total number of unique (cell, bin) pairs (for pre-allocating arrays)
vtkm::Id numPairsL2 = Algorithm::ScanExclusive(binCounts, binCounts);
......@@ -567,7 +571,9 @@ public:
binIds.Allocate(numPairsL2);
ls.CellIds.Allocate(numPairsL2);
FindBinsL2 findL2(ls.TopLevel);
vtkm::worklet::DispatcherMapTopology<FindBinsL2, DeviceAdapter>(findL2).Invoke(
vtkm::worklet::DispatcherMapTopology<FindBinsL2> findL2Dispatcher(findL2);
findL2Dispatcher.SetDevice(DeviceAdapter());
findL2Dispatcher.Invoke(
cellset, coords, ls.LeafDimensions, ls.LeafStartIndex, binCounts, binIds, ls.CellIds);
binCounts.ReleaseResources();
......@@ -587,8 +593,9 @@ public:
Algorithm::Copy(vtkm::cont::ArrayHandleConstant<vtkm::Id>(0, numberOfLeaves),
ls.CellStartIndex);
Algorithm::Copy(vtkm::cont::ArrayHandleConstant<vtkm::Id>(0, numberOfLeaves), ls.CellCount);
vtkm::worklet::DispatcherMapField<GenerateBinsL2, DeviceAdapter>().Invoke(
bins, cellsStart, cellsPerBin, ls.CellStartIndex, ls.CellCount);
vtkm::worklet::DispatcherMapField<GenerateBinsL2> dispatchGenerateBinsL2;
dispatchGenerateBinsL2.SetDevice(DeviceAdapter());
dispatchGenerateBinsL2.Invoke(bins, cellsStart, cellsPerBin, ls.CellStartIndex, ls.CellCount);
std::swap(this->LookupStructure, ls);
}
......@@ -708,13 +715,14 @@ public:
DeviceAdapter,
CellSetList cellSetTypes = CellSetList()) const
{
vtkm::worklet::DispatcherMapField<FindCellWorklet, DeviceAdapter>().Invoke(
points,
this->CellSet.ResetCellSetList(cellSetTypes),
this->Coordinates,
this->LookupStructure,
cellIds,
parametricCoords);
vtkm::worklet::DispatcherMapField<FindCellWorklet> dispatcher;
dispatcher.SetDevice(DeviceAdapter());
dispatcher.Invoke(points,
this->CellSet.ResetCellSetList(cellSetTypes),
this->Coordinates,
this->LookupStructure,
cellIds,
parametricCoords);
}
private:
......
......@@ -92,8 +92,9 @@ public:
vtkm::Id connectivityLength = vtkm::cont::DeviceAdapterAlgorithm<Device>::ScanExclusive(
vtkm::cont::make_ArrayHandleCast(conn.NumIndices, vtkm::Id()), conn.IndexOffsets);
conn.Connectivity.Allocate(connectivityLength);
vtkm::worklet::DispatcherMapTopology<WriteConnectivity, Device>().Invoke(
cellset, conn.IndexOffsets, conn.Connectivity);
vtkm::worklet::DispatcherMapTopology<WriteConnectivity> dispatcher;
dispatcher.SetDevice(Device());
dispatcher.Invoke(cellset, conn.IndexOffsets, conn.Connectivity);
return conn;
}
......@@ -126,8 +127,9 @@ public:
conn.NumIndices = make_ArrayHandleConstant(numPointsInCell, numberOfCells);
conn.IndexOffsets = ArrayHandleCounting<vtkm::Id>(0, numPointsInCell, numberOfCells);
conn.Connectivity.Allocate(connectivityLength);
vtkm::worklet::DispatcherMapTopology<WriteConnectivity, Device>().Invoke(
cellset, conn.IndexOffsets, conn.Connectivity);
vtkm::worklet::DispatcherMapTopology<WriteConnectivity> dispatcher;
dispatcher.SetDevice(Device());
dispatcher.Invoke(cellset, conn.IndexOffsets, conn.Connectivity);
return conn;
}
......
......@@ -57,7 +57,8 @@ struct map_color_table
{
using namespace vtkm::worklet::colorconversion;
TransferFunction transfer(colors->PrepareForExecution(device));
vtkm::worklet::DispatcherMapField<TransferFunction, DeviceAdapter> dispatcher(transfer);
vtkm::worklet::DispatcherMapField<TransferFunction> dispatcher(transfer);
dispatcher.SetDevice(DeviceAdapter());
dispatcher.Invoke(std::forward<Args>(args)...);
return true;
}
......@@ -71,7 +72,8 @@ struct map_color_table_with_samples
Args&&... args) const
{
using namespace vtkm::worklet::colorconversion;
vtkm::worklet::DispatcherMapField<LookupTable, DeviceAdapter> dispatcher(lookupTable);
vtkm::worklet::DispatcherMapField<LookupTable> dispatcher(lookupTable);
dispatcher.SetDevice(DeviceAdapter());
dispatcher.Invoke(std::forward<Args>(args)...);
return true;
}
......
......@@ -20,6 +20,7 @@
#ifndef vtk_m_cont_DataSetBuilderRectilinear_h
#define vtk_m_cont_DataSetBuilderRectilinear_h
#include <vtkm/cont/ArrayCopy.h>
#include <vtkm/cont/ArrayHandleCartesianProduct.h>
#include <vtkm/cont/ArrayPortalToIterators.h>
#include <vtkm/cont/CoordinateSystem.h>
......@@ -43,8 +44,7 @@ class VTKM_CONT_EXPORT DataSetBuilderRectilinear
VTKM_CONT static void CopyInto(const vtkm::cont::ArrayHandle<T>& input,
vtkm::cont::ArrayHandle<U>& output)
{
using Algorithm = vtkm::cont::DeviceAdapterAlgorithm<vtkm::cont::DeviceAdapterTagSerial>;
Algorithm::Copy(input, output);
vtkm::cont::ArrayCopy(input, output);
}
template <typename T, typename U>
......
......@@ -36,7 +36,7 @@ class VTKM_ALWAYS_EXPORT ErrorBadValue : public Error
{
public:
ErrorBadValue(const std::string& message)
: Error(message)
: Error(message, true)
{
}
};
......
......@@ -36,7 +36,7 @@ class VTKM_ALWAYS_EXPORT ErrorExecution : public vtkm::cont::Error
{
public:
ErrorExecution(const std::string& message)
: Error(message)
: Error(message, true)
{
}
};
......
......@@ -20,10 +20,9 @@
#ifndef vtk_m_cont_PointLocatorUniformGrid_h
#define vtk_m_cont_PointLocatorUniformGrid_h
#include <vtkm/cont/Algorithm.h>
#include <vtkm/cont/ArrayCopy.h>
#include <vtkm/cont/ArrayHandleCounting.h>
#include <vtkm/cont/DeviceAdapter.h>
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
#include <vtkm/cont/TryExecute.h>
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/worklet/WorkletMapField.h>
......@@ -77,62 +76,29 @@ public:
vtkm::Vec<vtkm::FloatDefault, 3> Dxdydz;
};
/// \brief Construct a 3D uniform grid for nearest neighbor search.
///
/// \param coords An ArrayHandle of x, y, z coordinates of input points.
/// \param device Tag for selecting device adapter
struct BuildFunctor
{
BuildFunctor(vtkm::cont::PointLocatorUniformGrid* self)
: Self(self)
{
}
template <typename Device>
bool operator()(Device)
{
using Algorithm = vtkm::cont::DeviceAdapterAlgorithm<Device>;
// Save training data points.
Algorithm::Copy(this->Self->GetCoords().GetData(), this->Self->coords);
// generate unique id for each input point
vtkm::cont::ArrayHandleCounting<vtkm::Id> pointCounting(
0, 1, this->Self->coords.GetNumberOfValues());
Algorithm::Copy(pointCounting, this->Self->pointIds);
// bin points into cells and give each of them the cell id.
BinPointsWorklet cellIdWorklet(this->Self->Min, this->Self->Max, this->Self->Dims);
vtkm::worklet::DispatcherMapField<BinPointsWorklet, Device> dispatchCellId(cellIdWorklet);
dispatchCellId.Invoke(this->Self->coords, this->Self->cellIds);
// Group points of the same cell together by sorting them according to the cell ids
Algorithm::SortByKey(this->Self->cellIds, this->Self->pointIds);
// for each cell, find the lower and upper bound of indices to the sorted point ids.
vtkm::cont::ArrayHandleCounting<vtkm::Id> cell_ids_counting(
0, 1, this->Self->Dims[0] * this->Self->Dims[1] * this->Self->Dims[2]);
Algorithm::UpperBounds(this->Self->cellIds, cell_ids_counting, this->Self->cellUpper);
Algorithm::LowerBounds(this->Self->cellIds, cell_ids_counting, this->Self->cellLower);
return true;
}
private:
vtkm::cont::PointLocatorUniformGrid* Self;
};
void Build() override
{
BuildFunctor functor(this);
bool success = vtkm::cont::TryExecute(functor);
if (!success)
{
throw vtkm::cont::ErrorExecution("Could not build point locator structure");
}
};
// Save training data points.
vtkm::cont::ArrayCopy(this->GetCoords().GetData(), this->coords);
// generate unique id for each input point
vtkm::cont::ArrayHandleCounting<vtkm::Id> pointCounting(0, 1, this->coords.GetNumberOfValues());
vtkm::cont::ArrayCopy(pointCounting, this->pointIds);
// bin points into cells and give each of them the cell id.
BinPointsWorklet cellIdWorklet(this->Min, this->Max, this->Dims);
vtkm::worklet::DispatcherMapField<BinPointsWorklet> dispatchCellId(cellIdWorklet);
dispatchCellId.Invoke(this->coords, this->cellIds);
// Group points of the same cell together by sorting them according to the cell ids
vtkm::cont::Algorithm::SortByKey(this->cellIds, this->pointIds);
// for each cell, find the lower and upper bound of indices to the sorted point ids.
vtkm::cont::ArrayHandleCounting<vtkm::Id> cell_ids_counting(
0, 1, this->Dims[0] * this->Dims[1] * this->Dims[2]);
vtkm::cont::Algorithm::UpperBounds(this->cellIds, cell_ids_counting, this->cellUpper);
vtkm::cont::Algorithm::LowerBounds(this->cellIds, cell_ids_counting, this->cellLower);
}
using HandleType = vtkm::cont::VirtualObjectHandle<vtkm::exec::PointLocator>;
......
......@@ -58,11 +58,11 @@ void HandleTryExecuteException(vtkm::cont::DeviceAdapterId deviceId,
//deferring to another device adapter?
std::cerr << "caught ErrorBadType : " << e.GetMessage() << std::endl;
}
catch (vtkm::cont::ErrorBadValue& e)
catch (vtkm::cont::ErrorBadValue&)
{
//should bad value errors should stop the filter, instead of deferring
//to another device adapter?
std::cerr << "caught ErrorBadValue : " << e.GetMessage() << std::endl;
// Should bad values be deferred to another device? Seems unlikely they will succeed.
// Re-throw instead.
throw;
}
catch (vtkm::cont::Error& e)
{
......
......@@ -65,6 +65,10 @@ public:
T* lockedValue = ::thrust::raw_pointer_cast(this->Portal.GetIteratorBegin() + index);
return this->vtkmAtomicAdd(lockedValue, value);
#else
// Shut up, compiler
(void)index;
(void)value;
throw vtkm::cont::ErrorExecution("AtomicArray used in control environment, "
"or incorrect array implementation used "
"for device.");
......@@ -85,6 +89,11 @@ public:
T* lockedValue = ::thrust::raw_pointer_cast(this->Portal.GetIteratorBegin() + index);
return this->vtkmCompareAndSwap(lockedValue, newValue, oldValue);
#else
// Shut up, compiler.
(void)index;
(void)newValue;
(void)oldValue;
throw vtkm::cont::ErrorExecution("AtomicArray used in control environment, "
"or incorrect array implementation used "
"for device.");
......
......@@ -92,7 +92,7 @@ struct TriggerICE : public vtkm::worklet::WorkletMapField
template <class ValueType>
ValueType operator()(const ValueType& bad, const ValueType& sane, const vtkm::Id sequenceId) const
{
return bad + sane * sequenceId;
return bad + sane * static_cast<ValueType>(sequenceId);
}
#endif
};
......@@ -156,7 +156,8 @@ void RunEdgeCases()
auto bad = vtkm::cont::make_ArrayHandle(badvalues);
auto sane = vtkm::cont::make_ArrayHandle(sanevalues);
decltype(sane) result;
vtkm::worklet::DispatcherMapField<TriggerICE, Device> dispatcher;
vtkm::worklet::DispatcherMapField<TriggerICE> dispatcher;
dispatcher.SetDevice(Device());
dispatcher.Invoke(bad, sane, result);
auto portal = result.GetPortalConstControl();
......
......@@ -63,12 +63,11 @@ struct DoubleWorklet : public vtkm::worklet::WorkletMapField
}
};
template <typename T, typename S, typename DeviceAdapter>
template <typename T, typename S>
inline void TestVirtualAccess(const vtkm::cont::ArrayHandle<T, S>& in,
vtkm::cont::ArrayHandle<T>& out,
DeviceAdapter)
vtkm::cont::ArrayHandle<T>& out)
{
vtkm::worklet::DispatcherMapField<CopyWorklet, DeviceAdapter>().Invoke(
vtkm::worklet::DispatcherMapField<CopyWorklet>().Invoke(
vtkm::cont::ArrayHandleVirtualCoordinates(in), vtkm::cont::ArrayHandleVirtualCoordinates(out));
VTKM_TEST_ASSERT(test_equal_portals(in.GetPortalConstControl(), out.GetPortalConstControl()),
......@@ -103,11 +102,11 @@ private:
{
a1.GetPortalControl().Set(i, TestValue(i, PointType()));
}
TestVirtualAccess(a1, out, DeviceAdapter{});
TestVirtualAccess(a1, out);
std::cout << "Testing ArrayHandleUniformPointCoordinates as input\n";
auto t = vtkm::cont::ArrayHandleUniformPointCoordinates(vtkm::Id3(4, 4, 4));
TestVirtualAccess(t, out, DeviceAdapter{});
TestVirtualAccess(t, out);
std::cout << "Testing ArrayHandleCartesianProduct as input\n";
vtkm::cont::ArrayHandle<vtkm::FloatDefault> c1, c2, c3;
......@@ -121,13 +120,12 @@ private:
c2.GetPortalControl().Set(i, p[1]);
c3.GetPortalControl().Set(i, p[2]);
}
TestVirtualAccess(
vtkm::cont::make_ArrayHandleCartesianProduct(c1, c2, c3), out, DeviceAdapter{});
TestVirtualAccess(vtkm::cont::make_ArrayHandleCartesianProduct(c1, c2, c3), out);
std::cout << "Testing resources releasing on ArrayHandleVirtualCoordinates\n";
vtkm::cont::ArrayHandleVirtualCoordinates virtualC =
vtkm::cont::ArrayHandleVirtualCoordinates(a1);
vtkm::worklet::DispatcherMapField<DoubleWorklet, DeviceAdapter>().Invoke(a1);
vtkm::worklet::DispatcherMapField<DoubleWorklet>().Invoke(a1);
virtualC.ReleaseResourcesExecution();
VTKM_TEST_ASSERT(a1.GetNumberOfValues() == length,
"ReleaseResourcesExecution"
......@@ -143,7 +141,11 @@ private:
}
public:
static int Run() { return vtkm::cont::testing::Testing::Run(TestAll); }
static int Run()
{
vtkm::cont::GetGlobalRuntimeDeviceTracker().ForceDevice(DeviceAdapter());
return vtkm::cont::testing::Testing::Run(TestAll);
}
};
}
}
......
......@@ -22,6 +22,7 @@
#include <vtkm/TypeTraits.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/RuntimeDeviceTracker.h>
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/worklet/WorkletMapField.h>
......@@ -135,7 +136,7 @@ private:
using Algorithm = vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapterTag>;
using DispatcherPassThrough = vtkm::worklet::DispatcherMapField<PassThrough, DeviceAdapterTag>;
using DispatcherPassThrough = vtkm::worklet::DispatcherMapField<PassThrough>;
struct VerifyEmptyArrays
{
template <typename T>
......@@ -455,7 +456,11 @@ private:
};
public:
static VTKM_CONT int Run() { return vtkm::cont::testing::Testing::Run(TryArrayHandleType()); }
static VTKM_CONT int Run()
{
vtkm::cont::GetGlobalRuntimeDeviceTracker().ForceDevice(DeviceAdapterTag());
return vtkm::cont::testing::Testing::Run(TryArrayHandleType());
}
};
}
}
......
......@@ -118,7 +118,7 @@ vtkm::cont::DataSet MakeTestDataSet(const vtkm::Vec<vtkm::Id, DIMENSIONS>& dims,
cellset = vtkm::worklet::Triangulate().Run(uniformCs, device);
break;
case 3:
cellset = vtkm::worklet::Tetrahedralize().Run(uniformCs, device);
cellset = vtkm::worklet::Tetrahedralize().Run(uniformCs);
break;
default:
VTKM_ASSERT(false);
......@@ -181,8 +181,9 @@ void GenerateRandomInput(const vtkm::cont::DataSet& ds,
pcoords.GetPortalControl().Set(i, pc);
}
vtkm::worklet::DispatcherMapTopology<ParametricToWorldCoordinates, DeviceAdapter> dispatcher(
vtkm::worklet::DispatcherMapTopology<ParametricToWorldCoordinates> dispatcher(
ParametricToWorldCoordinates::MakeScatter(cellIds));
dispatcher.SetDevice(DeviceAdapter());
dispatcher.Invoke(ds.GetCellSet(), ds.GetCoordinateSystem().GetData(), pcoords, wcoords);
}
......
......@@ -461,7 +461,8 @@ public:
vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::UInt8, 4>> colors;
TransferFunction transfer(table.PrepareForExecution(DeviceAdapterTag{}));
vtkm::worklet::DispatcherMapField<TransferFunction, DeviceAdapterTag> dispatcher(transfer);
vtkm::worklet::DispatcherMapField<TransferFunction> dispatcher(transfer);
dispatcher.SetDevice(DeviceAdapterTag());
dispatcher.Invoke(samples, colors);