2015-08-12 18:58:53 +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.
|
|
|
|
//
|
|
|
|
// 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/TransportTagArrayInOut.h>
|
|
|
|
|
|
|
|
#include <vtkm/exec/FunctorBase.h>
|
|
|
|
|
|
|
|
#include <vtkm/cont/ArrayHandle.h>
|
|
|
|
#include <vtkm/cont/DeviceAdapter.h>
|
|
|
|
|
|
|
|
#include <vtkm/cont/testing/Testing.h>
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace
|
|
|
|
{
|
2015-08-12 18:58:53 +00:00
|
|
|
|
|
|
|
static const vtkm::Id ARRAY_SIZE = 10;
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
typedef typename PortalType::ValueType ValueType;
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef vtkm::cont::ArrayHandle<T> ArrayHandleType;
|
|
|
|
ArrayHandleType handle = vtkm::cont::make_ArrayHandle(array, ARRAY_SIZE);
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
typedef typename ArrayHandleType::template ExecutionTypes<Device>::Portal PortalType;
|
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
|
|
|
|
2016-09-12 14:30:03 +00:00
|
|
|
TestKernelInOut<PortalType> kernel;
|
2017-03-24 20:51:46 +00:00
|
|
|
kernel.Portal = transport(handle, handle, ARRAY_SIZE, ARRAY_SIZE);
|
2015-08-12 18:58:53 +00:00
|
|
|
|
|
|
|
vtkm::cont::DeviceAdapterAlgorithm<Device>::Schedule(kernel, ARRAY_SIZE);
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
typename ArrayHandleType::PortalConstControl portal = handle.GetPortalConstControl();
|
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>
|
2015-08-12 18:58:53 +00:00
|
|
|
void TryArrayInOutTransport(Device)
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::testing::Testing::TryTypes(TryArrayInOutType<Device>(), vtkm::TypeListTagCommon());
|
2015-08-12 18:58:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestArrayInOutTransport()
|
|
|
|
{
|
|
|
|
TryArrayInOutTransport(VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
|
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
int UnitTestTransportArrayInOut(int, char* [])
|
2015-08-12 18:58:53 +00:00
|
|
|
{
|
|
|
|
return vtkm::cont::testing::Testing::Run(TestArrayInOutTransport);
|
|
|
|
}
|