2019-04-15 23:24:21 +00:00
|
|
|
//============================================================================
|
2015-02-13 06:24:43 +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.
|
2019-04-15 23:24:21 +00:00
|
|
|
//============================================================================
|
2015-02-13 06:24:43 +00:00
|
|
|
|
|
|
|
#include <vtkm/cont/ArrayHandle.h>
|
|
|
|
#include <vtkm/cont/ArrayHandleImplicit.h>
|
2022-07-11 17:47:59 +00:00
|
|
|
#include <vtkm/cont/Invoker.h>
|
2016-09-28 15:38:31 +00:00
|
|
|
#include <vtkm/cont/serial/DeviceAdapterSerial.h>
|
2015-02-13 06:24:43 +00:00
|
|
|
|
2022-07-11 17:47:59 +00:00
|
|
|
#include <vtkm/worklet/WorkletMapField.h>
|
|
|
|
|
2015-05-08 16:33:59 +00:00
|
|
|
#include <vtkm/VecTraits.h>
|
|
|
|
|
2015-02-13 06:24:43 +00:00
|
|
|
#include <vtkm/cont/testing/Testing.h>
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace
|
|
|
|
{
|
2015-02-13 06:24:43 +00:00
|
|
|
|
|
|
|
const vtkm::Id ARRAY_SIZE = 10;
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename ValueType>
|
2015-02-13 06:24:43 +00:00
|
|
|
struct IndexSquared
|
|
|
|
{
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT
|
2015-02-13 06:24:43 +00:00
|
|
|
ValueType operator()(vtkm::Id i) const
|
2015-05-08 16:33:59 +00:00
|
|
|
{
|
2017-06-23 18:50:34 +00:00
|
|
|
using ComponentType = typename vtkm::VecTraits<ValueType>::ComponentType;
|
2017-05-18 14:29:41 +00:00
|
|
|
return ValueType(static_cast<ComponentType>(i * i));
|
2015-05-08 16:33:59 +00:00
|
|
|
}
|
2015-02-13 06:24:43 +00:00
|
|
|
};
|
|
|
|
|
2022-07-11 17:47:59 +00:00
|
|
|
struct PassThrough : public vtkm::worklet::WorkletMapField
|
|
|
|
{
|
|
|
|
using ControlSignature = void(FieldIn, FieldOut);
|
|
|
|
using ExecutionSignature = void(_1, _2);
|
|
|
|
|
|
|
|
template <typename InValue, typename OutValue>
|
|
|
|
VTKM_EXEC void operator()(const InValue& inValue, OutValue& outValue) const
|
|
|
|
{
|
|
|
|
outValue = inValue;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-02-13 06:24:43 +00:00
|
|
|
struct ImplicitTests
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename ValueType>
|
2015-02-13 06:24:43 +00:00
|
|
|
void operator()(const ValueType) const
|
|
|
|
{
|
2017-06-23 18:50:34 +00:00
|
|
|
using FunctorType = IndexSquared<ValueType>;
|
2015-02-13 06:24:43 +00:00
|
|
|
FunctorType functor;
|
|
|
|
|
2017-06-23 18:50:34 +00:00
|
|
|
using ImplicitHandle = vtkm::cont::ArrayHandleImplicit<FunctorType>;
|
2015-02-13 06:24:43 +00:00
|
|
|
|
2020-05-12 19:43:40 +00:00
|
|
|
ImplicitHandle implicit = vtkm::cont::make_ArrayHandleImplicit(functor, ARRAY_SIZE);
|
2015-02-13 06:24:43 +00:00
|
|
|
|
2022-07-11 17:47:59 +00:00
|
|
|
std::cout << "verify that the control portal works" << std::endl;
|
2020-05-12 19:43:40 +00:00
|
|
|
auto implicitPortal = implicit.ReadPortal();
|
2017-05-18 14:29:41 +00:00
|
|
|
for (int i = 0; i < ARRAY_SIZE; ++i)
|
|
|
|
{
|
2020-05-12 19:43:40 +00:00
|
|
|
const ValueType v = implicitPortal.Get(i);
|
2015-02-13 06:24:43 +00:00
|
|
|
const ValueType correct_value = functor(i);
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(v == correct_value, "Implicit Handle Failed");
|
|
|
|
}
|
2015-02-13 06:24:43 +00:00
|
|
|
|
2022-07-11 17:47:59 +00:00
|
|
|
std::cout << "verify that the execution portal works" << std::endl;
|
2020-01-21 20:18:03 +00:00
|
|
|
vtkm::cont::Token token;
|
2017-06-23 18:50:34 +00:00
|
|
|
using Device = vtkm::cont::DeviceAdapterTagSerial;
|
2021-02-01 15:03:11 +00:00
|
|
|
using CEPortal = typename ImplicitHandle::ReadPortalType;
|
2020-05-12 19:43:40 +00:00
|
|
|
CEPortal execPortal = implicit.PrepareForInput(Device(), token);
|
2017-05-18 14:29:41 +00:00
|
|
|
for (int i = 0; i < ARRAY_SIZE; ++i)
|
|
|
|
{
|
2015-02-13 06:24:43 +00:00
|
|
|
const ValueType v = execPortal.Get(i);
|
|
|
|
const ValueType correct_value = functor(i);
|
|
|
|
VTKM_TEST_ASSERT(v == correct_value, "Implicit Handle Failed");
|
2017-05-18 14:29:41 +00:00
|
|
|
}
|
2022-07-11 17:47:59 +00:00
|
|
|
|
|
|
|
std::cout << "verify that the array handle works in a worklet on the device" << std::endl;
|
|
|
|
vtkm::cont::Invoker invoke;
|
|
|
|
vtkm::cont::ArrayHandle<ValueType> result;
|
|
|
|
invoke(PassThrough{}, implicit, result);
|
|
|
|
auto resultPortal = result.ReadPortal();
|
|
|
|
for (int i = 0; i < ARRAY_SIZE; ++i)
|
|
|
|
{
|
|
|
|
const ValueType value = resultPortal.Get(i);
|
|
|
|
const ValueType correctValue = functor(i);
|
|
|
|
VTKM_TEST_ASSERT(test_equal(value, correctValue));
|
|
|
|
}
|
2015-02-13 06:24:43 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void TestArrayHandleImplicit()
|
|
|
|
{
|
2019-12-05 17:55:57 +00:00
|
|
|
vtkm::testing::Testing::TryTypes(ImplicitTests(), vtkm::TypeListCommon());
|
2015-02-13 06:24:43 +00:00
|
|
|
}
|
|
|
|
|
2018-06-14 20:49:11 +00:00
|
|
|
} // anonymous namespace
|
2015-02-13 06:24:43 +00:00
|
|
|
|
2019-01-01 22:19:02 +00:00
|
|
|
int UnitTestArrayHandleImplicit(int argc, char* argv[])
|
2015-02-13 06:24:43 +00:00
|
|
|
{
|
2019-01-01 22:19:02 +00:00
|
|
|
return vtkm::cont::testing::Testing::Run(TestArrayHandleImplicit, argc, argv);
|
2015-02-13 06:24:43 +00:00
|
|
|
}
|