Commit c36b4543 authored by Robert Maynard's avatar Robert Maynard

Add UnitTestWorkletMapFieldWholeArrayAtomic

This covers the atomic tests that was previously part of WorkletMapFieldWholeArray
parent d6f66d17
......@@ -74,6 +74,7 @@ set(unit_tests
UnitTestWorkletMapField.cxx
UnitTestWorkletMapFieldExecArg.cxx
UnitTestWorkletMapFieldWholeArray.cxx
UnitTestWorkletMapFieldWholeArrayAtomic.cxx
UnitTestWorkletMapPointNeighborhood.cxx
UnitTestWorkletMapTopologyExplicit.cxx
UnitTestWorkletMapTopologyUniform.cxx
......
......@@ -57,21 +57,6 @@ public:
}
};
class TestAtomicArrayWorklet : public vtkm::worklet::WorkletMapField
{
public:
using ControlSignature = void(FieldIn, AtomicArrayInOut);
using ExecutionSignature = void(WorkIndex, _2);
using InputDomain = _1;
template <typename AtomicArrayType>
VTKM_EXEC void operator()(const vtkm::Id& index, const AtomicArrayType& atomicArray) const
{
using ValueType = typename AtomicArrayType::ValueType;
atomicArray.Add(0, static_cast<ValueType>(index));
}
};
namespace map_whole_array
{
......@@ -121,37 +106,6 @@ struct DoTestWholeArrayWorklet
}
};
struct DoTestAtomicArrayWorklet
{
using WorkletType = TestAtomicArrayWorklet;
// This just demonstrates that the WholeArray tags support dynamic arrays.
VTKM_CONT
void CallWorklet(const vtkm::cont::VariantArrayHandle& inOutArray) const
{
std::cout << "Create and run dispatcher." << std::endl;
vtkm::worklet::DispatcherMapField<WorkletType> dispatcher;
dispatcher.Invoke(vtkm::cont::ArrayHandleIndex(ARRAY_SIZE), inOutArray);
}
template <typename T>
VTKM_CONT void operator()(T) const
{
std::cout << "Set up data." << std::endl;
T inOutValue = 0;
vtkm::cont::ArrayHandle<T> inOutHandle = vtkm::cont::make_ArrayHandle(&inOutValue, 1);
this->CallWorklet(vtkm::cont::VariantArrayHandle(inOutHandle));
std::cout << "Check result." << std::endl;
T result = inOutHandle.GetPortalConstControl().Get(0);
VTKM_TEST_ASSERT(result == (ARRAY_SIZE * (ARRAY_SIZE - 1)) / 2,
"Got wrong summation in atomic array.");
}
};
void TestWorkletMapFieldExecArg(vtkm::cont::DeviceAdapterId id)
{
std::cout << "Testing Worklet with WholeArray on device adapter: " << id.GetName() << std::endl;
......@@ -159,10 +113,6 @@ void TestWorkletMapFieldExecArg(vtkm::cont::DeviceAdapterId id)
std::cout << "--- Worklet accepting all types." << std::endl;
vtkm::testing::Testing::TryTypes(map_whole_array::DoTestWholeArrayWorklet(),
vtkm::TypeListTagCommon());
std::cout << "--- Worklet accepting atomics." << std::endl;
vtkm::testing::Testing::TryTypes(map_whole_array::DoTestAtomicArrayWorklet(),
vtkm::cont::AtomicArrayTypeListTag());
}
} // anonymous namespace
......
//============================================================================
// 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 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
// Copyright 2015 UT-Battelle, LLC.
// Copyright 2015 Los Alamos National Security.
//
// Under the terms of Contract DE-NA0003525 with NTESS,
// 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/VariantArrayHandle.h>
#include <vtkm/cont/internal/DeviceAdapterTag.h>
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/worklet/WorkletMapField.h>
#include <vtkm/cont/testing/Testing.h>
class TestAtomicArrayWorklet : public vtkm::worklet::WorkletMapField
{
public:
using ControlSignature = void(FieldIn, AtomicArrayInOut);
using ExecutionSignature = void(WorkIndex, _2);
using InputDomain = _1;
template <typename AtomicArrayType>
VTKM_EXEC void operator()(const vtkm::Id& index, const AtomicArrayType& atomicArray) const
{
using ValueType = typename AtomicArrayType::ValueType;
atomicArray.Add(0, static_cast<ValueType>(index));
}
};
namespace map_whole_array
{
static constexpr vtkm::Id ARRAY_SIZE = 10;
struct DoTestAtomicArrayWorklet
{
using WorkletType = TestAtomicArrayWorklet;
// This just demonstrates that the WholeArray tags support dynamic arrays.
VTKM_CONT
void CallWorklet(const vtkm::cont::VariantArrayHandle& inOutArray) const
{
std::cout << "Create and run dispatcher." << std::endl;
vtkm::worklet::DispatcherMapField<WorkletType> dispatcher;
dispatcher.Invoke(vtkm::cont::ArrayHandleIndex(ARRAY_SIZE), inOutArray);
}
template <typename T>
VTKM_CONT void operator()(T) const
{
std::cout << "Set up data." << std::endl;
T inOutValue = 0;
vtkm::cont::ArrayHandle<T> inOutHandle = vtkm::cont::make_ArrayHandle(&inOutValue, 1);
this->CallWorklet(vtkm::cont::VariantArrayHandle(inOutHandle));
std::cout << "Check result." << std::endl;
T result = inOutHandle.GetPortalConstControl().Get(0);
VTKM_TEST_ASSERT(result == (ARRAY_SIZE * (ARRAY_SIZE - 1)) / 2,
"Got wrong summation in atomic array.");
}
};
void TestWorkletMapFieldExecArgAtomic(vtkm::cont::DeviceAdapterId id)
{
std::cout << "Testing Worklet with AtomicWholeArray on device adapter: " << id.GetName()
<< std::endl;
vtkm::testing::Testing::TryTypes(map_whole_array::DoTestAtomicArrayWorklet(),
vtkm::cont::AtomicArrayTypeListTag());
}
} // anonymous namespace
int UnitTestWorkletMapFieldWholeArrayAtomic(int argc, char* argv[])
{
return vtkm::cont::testing::Testing::RunOnDevice(
map_whole_array::TestWorkletMapFieldExecArgAtomic, argc, argv);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment