2014-10-15 19:52:27 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2014-10-15 19:52:27 +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/exec/arg/FetchTagArrayDirectIn.h>
|
|
|
|
|
2022-02-16 12:50:39 +00:00
|
|
|
#include <vtkm/exec/testing/ThreadIndicesTesting.h>
|
2014-10-15 19:52:27 +00:00
|
|
|
|
|
|
|
#include <vtkm/testing/Testing.h>
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace
|
|
|
|
{
|
2014-10-15 19:52:27 +00:00
|
|
|
|
2018-02-27 14:25:25 +00:00
|
|
|
static constexpr vtkm::Id ARRAY_SIZE = 10;
|
2014-10-15 19:52:27 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T>
|
2014-10-15 19:52:27 +00:00
|
|
|
struct TestPortal
|
|
|
|
{
|
2017-08-16 15:34:21 +00:00
|
|
|
using ValueType = T;
|
2014-10-15 19:52:27 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT
|
2014-10-15 19:52:27 +00:00
|
|
|
vtkm::Id GetNumberOfValues() const { return ARRAY_SIZE; }
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
ValueType Get(vtkm::Id index) const
|
|
|
|
{
|
2014-10-23 16:59:18 +00:00
|
|
|
VTKM_TEST_ASSERT(index >= 0, "Bad portal index.");
|
|
|
|
VTKM_TEST_ASSERT(index < this->GetNumberOfValues(), "Bad portal index.");
|
|
|
|
return TestValue(index, ValueType());
|
|
|
|
}
|
2014-10-15 19:52:27 +00:00
|
|
|
};
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T>
|
2014-10-15 19:52:27 +00:00
|
|
|
struct FetchArrayDirectInTests
|
|
|
|
{
|
2015-09-23 19:38:49 +00:00
|
|
|
void operator()()
|
2014-10-15 19:52:27 +00:00
|
|
|
{
|
2015-09-23 19:38:49 +00:00
|
|
|
TestPortal<T> execObject;
|
|
|
|
|
2017-08-16 15:34:21 +00:00
|
|
|
using FetchType = vtkm::exec::arg::Fetch<vtkm::exec::arg::FetchTagArrayDirectIn,
|
|
|
|
vtkm::exec::arg::AspectTagDefault,
|
|
|
|
TestPortal<T>>;
|
2014-10-15 19:52:27 +00:00
|
|
|
|
|
|
|
FetchType fetch;
|
|
|
|
|
|
|
|
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
|
|
|
|
{
|
2015-09-23 19:38:49 +00:00
|
|
|
vtkm::exec::arg::ThreadIndicesTesting indices(index);
|
2015-10-07 18:14:00 +00:00
|
|
|
|
2015-09-23 19:38:49 +00:00
|
|
|
T value = fetch.Load(indices, execObject);
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(value, TestValue(index, T())), "Got invalid value from Load.");
|
2014-10-15 19:52:27 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
value = T(T(2) * value);
|
2014-10-15 19:52:27 +00:00
|
|
|
|
|
|
|
// This should be a no-op, but we should be able to call it.
|
2015-09-23 19:38:49 +00:00
|
|
|
fetch.Store(indices, execObject, value);
|
2014-10-15 19:52:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TryType
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T>
|
2014-10-15 19:52:27 +00:00
|
|
|
void operator()(T) const
|
|
|
|
{
|
2015-09-23 19:38:49 +00:00
|
|
|
FetchArrayDirectInTests<T>()();
|
2014-10-15 19:52:27 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void TestExecObjectFetch()
|
|
|
|
{
|
2016-08-24 22:02:18 +00:00
|
|
|
vtkm::testing::Testing::TryTypes(TryType());
|
2014-10-15 19:52:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2019-01-01 22:19:02 +00:00
|
|
|
int UnitTestFetchArrayDirectIn(int argc, char* argv[])
|
2014-10-15 19:52:27 +00:00
|
|
|
{
|
2019-01-01 22:19:02 +00:00
|
|
|
return vtkm::testing::Testing::Run(TestExecObjectFetch, argc, argv);
|
2014-10-15 19:52:27 +00:00
|
|
|
}
|