2015-08-12 18:58:53 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2015-08-12 18:58:53 +00:00
|
|
|
// 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.
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
#include <vtkm/cont/arg/TransportTagArrayInOut.h>
|
|
|
|
|
|
|
|
#include <vtkm/exec/FunctorBase.h>
|
|
|
|
|
|
|
|
#include <vtkm/cont/ArrayHandle.h>
|
|
|
|
#include <vtkm/cont/DeviceAdapter.h>
|
2022-07-13 20:04:08 +00:00
|
|
|
#include <vtkm/cont/TryExecute.h>
|
2015-08-12 18:58:53 +00:00
|
|
|
|
|
|
|
#include <vtkm/cont/testing/Testing.h>
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace
|
|
|
|
{
|
2015-08-12 18:58:53 +00:00
|
|
|
|
2018-02-27 14:25:25 +00:00
|
|
|
static constexpr vtkm::Id ARRAY_SIZE = 10;
|
2015-08-12 18:58:53 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename PortalType>
|
2016-09-12 14:30:03 +00:00
|
|
|
struct TestKernelInOut : public vtkm::exec::FunctorBase
|
2015-08-12 18:58:53 +00:00
|
|
|
{
|
|
|
|
PortalType Portal;
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2015-08-12 18:58:53 +00:00
|
|
|
void operator()(vtkm::Id index) const
|
|
|
|
{
|
2017-06-23 18:50:34 +00:00
|
|
|
using ValueType = typename PortalType::ValueType;
|
2015-08-12 18:58:53 +00:00
|
|
|
ValueType inValue = this->Portal.Get(index);
|
|
|
|
this->Portal.Set(index, inValue + inValue);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename Device>
|
2015-08-12 18:58:53 +00:00
|
|
|
struct TryArrayInOutType
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T>
|
2015-08-12 18:58:53 +00:00
|
|
|
void operator()(T) const
|
|
|
|
{
|
|
|
|
T array[ARRAY_SIZE];
|
|
|
|
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
|
|
|
|
{
|
|
|
|
array[index] = TestValue(index, T());
|
|
|
|
}
|
|
|
|
|
2017-06-23 18:50:34 +00:00
|
|
|
using ArrayHandleType = vtkm::cont::ArrayHandle<T>;
|
2020-07-16 16:32:32 +00:00
|
|
|
ArrayHandleType handle = vtkm::cont::make_ArrayHandle(array, ARRAY_SIZE, vtkm::CopyFlag::Off);
|
2015-08-12 18:58:53 +00:00
|
|
|
|
2021-02-01 15:03:11 +00:00
|
|
|
using PortalType = typename ArrayHandleType::WritePortalType;
|
2015-08-12 18:58:53 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::cont::arg::Transport<vtkm::cont::arg::TransportTagArrayInOut, ArrayHandleType, Device>
|
|
|
|
transport;
|
2015-08-12 18:58:53 +00:00
|
|
|
|
2020-01-19 06:36:14 +00:00
|
|
|
vtkm::cont::Token token;
|
|
|
|
|
2016-09-12 14:30:03 +00:00
|
|
|
TestKernelInOut<PortalType> kernel;
|
2020-01-19 06:36:14 +00:00
|
|
|
kernel.Portal = transport(handle, handle, ARRAY_SIZE, ARRAY_SIZE, token);
|
2015-08-12 18:58:53 +00:00
|
|
|
|
|
|
|
vtkm::cont::DeviceAdapterAlgorithm<Device>::Schedule(kernel, ARRAY_SIZE);
|
2020-01-19 22:50:48 +00:00
|
|
|
token.DetachFromAll();
|
2015-08-12 18:58:53 +00:00
|
|
|
|
2020-01-28 19:14:32 +00:00
|
|
|
typename ArrayHandleType::ReadPortalType portal = handle.ReadPortal();
|
2015-08-12 18:58:53 +00:00
|
|
|
VTKM_TEST_ASSERT(portal.GetNumberOfValues() == ARRAY_SIZE,
|
|
|
|
"Portal has wrong number of values.");
|
|
|
|
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
|
|
|
|
{
|
|
|
|
T expectedValue = TestValue(index, T()) + TestValue(index, T());
|
|
|
|
T retrievedValue = portal.Get(index);
|
|
|
|
VTKM_TEST_ASSERT(test_equal(expectedValue, retrievedValue),
|
|
|
|
"Functor did not modify in place.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename Device>
|
2022-07-13 20:04:08 +00:00
|
|
|
bool TryArrayInOutTransport(Device device)
|
2015-08-12 18:58:53 +00:00
|
|
|
{
|
2022-07-13 20:04:08 +00:00
|
|
|
std::cout << "Trying ArrayInOut transport with " << device.GetName() << std::endl;
|
2019-12-05 17:55:57 +00:00
|
|
|
vtkm::testing::Testing::TryTypes(TryArrayInOutType<Device>(), vtkm::TypeListCommon());
|
2022-07-13 20:04:08 +00:00
|
|
|
return true;
|
2015-08-12 18:58:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestArrayInOutTransport()
|
|
|
|
{
|
2022-07-13 20:04:08 +00:00
|
|
|
VTKM_TEST_ASSERT(
|
|
|
|
vtkm::cont::TryExecute([](auto device) { return TryArrayInOutTransport(device); }));
|
2015-08-12 18:58:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2019-01-01 22:19:02 +00:00
|
|
|
int UnitTestTransportArrayInOut(int argc, char* argv[])
|
2015-08-12 18:58:53 +00:00
|
|
|
{
|
2019-01-01 22:19:02 +00:00
|
|
|
return vtkm::cont::testing::Testing::Run(TestArrayInOutTransport, argc, argv);
|
2015-08-12 18:58:53 +00:00
|
|
|
}
|