2014-10-21 16:51:07 +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.
|
|
|
|
//
|
2017-09-20 21:33:44 +00:00
|
|
|
// Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
2014-10-21 16:51:07 +00:00
|
|
|
// Copyright 2014 UT-Battelle, LLC.
|
2015-05-21 12:09:22 +00:00
|
|
|
// Copyright 2014 Los Alamos National Security.
|
2014-10-21 16:51:07 +00:00
|
|
|
//
|
2017-09-20 21:33:44 +00:00
|
|
|
// Under the terms of Contract DE-NA0003525 with NTESS,
|
2014-10-21 16:51:07 +00:00
|
|
|
// 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.
|
|
|
|
//============================================================================
|
|
|
|
|
2017-05-01 19:19:42 +00:00
|
|
|
#include <vtkm/exec/internal/TaskSingular.h>
|
2014-10-21 16:51:07 +00:00
|
|
|
|
2017-05-01 19:19:42 +00:00
|
|
|
#include <vtkm/exec/FunctorBase.h>
|
2014-10-21 16:51:07 +00:00
|
|
|
#include <vtkm/exec/arg/BasicArg.h>
|
2015-10-07 18:14:00 +00:00
|
|
|
#include <vtkm/exec/arg/ThreadIndicesBasic.h>
|
2014-10-21 16:51:07 +00:00
|
|
|
|
2015-09-17 19:45:35 +00:00
|
|
|
#include <vtkm/StaticAssert.h>
|
|
|
|
|
2014-10-21 16:51:07 +00:00
|
|
|
#include <vtkm/internal/FunctionInterface.h>
|
2015-10-07 18:14:00 +00:00
|
|
|
#include <vtkm/internal/Invocation.h>
|
2014-10-21 16:51:07 +00:00
|
|
|
|
|
|
|
#include <vtkm/testing/Testing.h>
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace
|
|
|
|
{
|
2014-10-21 16:51:07 +00:00
|
|
|
|
|
|
|
struct TestExecObject
|
|
|
|
{
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
TestExecObject()
|
|
|
|
: Value(nullptr)
|
|
|
|
{
|
|
|
|
}
|
2014-10-21 16:51:07 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
TestExecObject(vtkm::Id* value)
|
|
|
|
: Value(value)
|
|
|
|
{
|
|
|
|
}
|
2014-10-21 16:51:07 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Id* Value;
|
2014-10-21 16:51:07 +00:00
|
|
|
};
|
|
|
|
|
2015-09-23 19:38:49 +00:00
|
|
|
struct MyOutputToInputMapPortal
|
|
|
|
{
|
2017-08-16 15:34:21 +00:00
|
|
|
using ValueType = vtkm::Id;
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC_CONT
|
2015-09-23 19:38:49 +00:00
|
|
|
vtkm::Id Get(vtkm::Id index) const { return index; }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MyVisitArrayPortal
|
|
|
|
{
|
2017-08-16 15:34:21 +00:00
|
|
|
using ValueType = vtkm::IdComponent;
|
2015-09-23 19:38:49 +00:00
|
|
|
vtkm::IdComponent Get(vtkm::Id) const { return 1; }
|
|
|
|
};
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
struct TestFetchTagInput
|
|
|
|
{
|
|
|
|
};
|
|
|
|
struct TestFetchTagOutput
|
|
|
|
{
|
|
|
|
};
|
2014-10-21 16:51:07 +00:00
|
|
|
|
|
|
|
// Missing TransportTag, but we are not testing that so we can leave it out.
|
|
|
|
struct TestControlSignatureTagInput
|
|
|
|
{
|
2017-08-16 15:34:21 +00:00
|
|
|
using FetchTag = TestFetchTagInput;
|
2014-10-21 16:51:07 +00:00
|
|
|
};
|
|
|
|
struct TestControlSignatureTagOutput
|
|
|
|
{
|
2017-08-16 15:34:21 +00:00
|
|
|
using FetchTag = TestFetchTagOutput;
|
2014-10-21 16:51:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace exec
|
|
|
|
{
|
|
|
|
namespace arg
|
|
|
|
{
|
2014-10-21 16:51:07 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <>
|
2017-05-26 17:53:28 +00:00
|
|
|
struct Fetch<TestFetchTagInput,
|
|
|
|
vtkm::exec::arg::AspectTagDefault,
|
|
|
|
vtkm::exec::arg::ThreadIndicesBasic,
|
|
|
|
TestExecObject>
|
2014-10-21 16:51:07 +00:00
|
|
|
{
|
2017-08-16 15:34:21 +00:00
|
|
|
using ValueType = vtkm::Id;
|
2014-10-21 16:51:07 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2017-05-18 14:29:41 +00:00
|
|
|
ValueType Load(const vtkm::exec::arg::ThreadIndicesBasic& indices,
|
|
|
|
const TestExecObject& execObject) const
|
|
|
|
{
|
|
|
|
return *execObject.Value + 10 * indices.GetInputIndex();
|
2014-10-21 16:51:07 +00:00
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2017-05-18 14:29:41 +00:00
|
|
|
void Store(const vtkm::exec::arg::ThreadIndicesBasic&, const TestExecObject&, ValueType) const
|
|
|
|
{
|
2014-10-21 16:51:07 +00:00
|
|
|
// No-op
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <>
|
2017-05-26 17:53:28 +00:00
|
|
|
struct Fetch<TestFetchTagOutput,
|
|
|
|
vtkm::exec::arg::AspectTagDefault,
|
|
|
|
vtkm::exec::arg::ThreadIndicesBasic,
|
|
|
|
TestExecObject>
|
2014-10-21 16:51:07 +00:00
|
|
|
{
|
2017-08-16 15:34:21 +00:00
|
|
|
using ValueType = vtkm::Id;
|
2014-10-21 16:51:07 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2017-05-18 14:29:41 +00:00
|
|
|
ValueType Load(const vtkm::exec::arg::ThreadIndicesBasic&, const TestExecObject&) const
|
|
|
|
{
|
2014-10-21 16:51:07 +00:00
|
|
|
// No-op
|
|
|
|
return ValueType();
|
|
|
|
}
|
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2017-05-26 17:53:28 +00:00
|
|
|
void Store(const vtkm::exec::arg::ThreadIndicesBasic& indices,
|
|
|
|
const TestExecObject& execObject,
|
2017-05-18 14:29:41 +00:00
|
|
|
ValueType value) const
|
|
|
|
{
|
|
|
|
*execObject.Value = value + 20 * indices.GetOutputIndex();
|
2014-10-21 16:51:07 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // vtkm::exec::arg
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace
|
|
|
|
{
|
2014-10-21 16:51:07 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
typedef void TestControlSignature(TestControlSignatureTagInput, TestControlSignatureTagOutput);
|
2017-08-16 15:34:21 +00:00
|
|
|
using TestControlInterface = vtkm::internal::FunctionInterface<TestControlSignature>;
|
2014-10-21 16:51:07 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
typedef void TestExecutionSignature1(vtkm::exec::arg::BasicArg<1>, vtkm::exec::arg::BasicArg<2>);
|
2017-08-16 15:34:21 +00:00
|
|
|
using TestExecutionInterface1 = vtkm::internal::FunctionInterface<TestExecutionSignature1>;
|
2014-10-21 16:51:07 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
typedef vtkm::exec::arg::BasicArg<2> TestExecutionSignature2(vtkm::exec::arg::BasicArg<1>);
|
2017-08-16 15:34:21 +00:00
|
|
|
using TestExecutionInterface2 = vtkm::internal::FunctionInterface<TestExecutionSignature2>;
|
2014-10-21 16:51:07 +00:00
|
|
|
|
|
|
|
// Not a full worklet, but provides operators that we expect in a worklet.
|
|
|
|
struct TestWorkletProxy : vtkm::exec::FunctorBase
|
|
|
|
{
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2017-05-18 14:29:41 +00:00
|
|
|
void operator()(vtkm::Id input, vtkm::Id& output) const { output = input + 100; }
|
2014-10-21 16:51:07 +00:00
|
|
|
|
2016-10-19 22:42:58 +00:00
|
|
|
VTKM_EXEC
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::Id operator()(vtkm::Id input) const { return input + 200; }
|
2015-10-07 18:14:00 +00:00
|
|
|
|
2017-05-26 17:53:28 +00:00
|
|
|
template <typename T,
|
|
|
|
typename OutToInArrayType,
|
|
|
|
typename VisitArrayType,
|
|
|
|
typename InputDomainType,
|
|
|
|
typename G>
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_EXEC vtkm::exec::arg::ThreadIndicesBasic GetThreadIndices(
|
2017-05-26 17:53:28 +00:00
|
|
|
const T& threadIndex,
|
|
|
|
const OutToInArrayType& outToIn,
|
|
|
|
const VisitArrayType& visit,
|
|
|
|
const InputDomainType&,
|
|
|
|
const G& globalThreadIndexOffset) const
|
2015-10-07 18:14:00 +00:00
|
|
|
{
|
2017-05-26 17:53:28 +00:00
|
|
|
return vtkm::exec::arg::ThreadIndicesBasic(
|
|
|
|
threadIndex, outToIn.Get(threadIndex), visit.Get(threadIndex), globalThreadIndexOffset);
|
2015-10-07 18:14:00 +00:00
|
|
|
}
|
2014-10-21 16:51:07 +00:00
|
|
|
};
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename Invocation>
|
|
|
|
void CallDoWorkletInvokeFunctor(const Invocation& invocation, vtkm::Id index)
|
2015-10-07 18:14:00 +00:00
|
|
|
{
|
|
|
|
vtkm::exec::internal::detail::DoWorkletInvokeFunctor(
|
2017-05-26 17:53:28 +00:00
|
|
|
TestWorkletProxy(),
|
|
|
|
invocation,
|
|
|
|
vtkm::exec::arg::ThreadIndicesBasic(
|
|
|
|
index, invocation.OutputToInputMap.Get(index), invocation.VisitArray.Get(index)));
|
2015-10-07 18:14:00 +00:00
|
|
|
}
|
2014-10-21 16:51:07 +00:00
|
|
|
|
|
|
|
void TestDoWorkletInvoke()
|
|
|
|
{
|
|
|
|
std::cout << "Testing internal worklet invoke." << std::endl;
|
|
|
|
|
|
|
|
vtkm::Id inputTestValue;
|
|
|
|
vtkm::Id outputTestValue;
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::internal::FunctionInterface<void(TestExecObject, TestExecObject)> execObjects =
|
|
|
|
vtkm::internal::make_FunctionInterface<void>(TestExecObject(&inputTestValue),
|
|
|
|
TestExecObject(&outputTestValue));
|
2014-10-21 16:51:07 +00:00
|
|
|
|
|
|
|
std::cout << " Try void return." << std::endl;
|
|
|
|
inputTestValue = 5;
|
2015-05-25 10:50:18 +00:00
|
|
|
outputTestValue = static_cast<vtkm::Id>(0xDEADDEAD);
|
2017-05-26 17:53:28 +00:00
|
|
|
CallDoWorkletInvokeFunctor(vtkm::internal::make_Invocation<1>(execObjects,
|
|
|
|
TestControlInterface(),
|
|
|
|
TestExecutionInterface1(),
|
|
|
|
MyOutputToInputMapPortal(),
|
|
|
|
MyVisitArrayPortal()),
|
2017-05-18 14:29:41 +00:00
|
|
|
1);
|
2014-10-21 16:51:07 +00:00
|
|
|
VTKM_TEST_ASSERT(inputTestValue == 5, "Input value changed.");
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(outputTestValue == inputTestValue + 100 + 30, "Output value not set right.");
|
2014-10-21 16:51:07 +00:00
|
|
|
|
|
|
|
std::cout << " Try return value." << std::endl;
|
|
|
|
inputTestValue = 6;
|
2015-05-25 10:50:18 +00:00
|
|
|
outputTestValue = static_cast<vtkm::Id>(0xDEADDEAD);
|
2017-05-26 17:53:28 +00:00
|
|
|
CallDoWorkletInvokeFunctor(vtkm::internal::make_Invocation<1>(execObjects,
|
|
|
|
TestControlInterface(),
|
|
|
|
TestExecutionInterface2(),
|
|
|
|
MyOutputToInputMapPortal(),
|
|
|
|
MyVisitArrayPortal()),
|
2017-05-18 14:29:41 +00:00
|
|
|
2);
|
2014-10-21 16:51:07 +00:00
|
|
|
VTKM_TEST_ASSERT(inputTestValue == 6, "Input value changed.");
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_TEST_ASSERT(outputTestValue == inputTestValue + 200 + 30 * 2, "Output value not set right.");
|
2014-10-21 16:51:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestWorkletInvokeFunctor()
|
|
|
|
{
|
|
|
|
TestDoWorkletInvoke();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
int UnitTestWorkletInvokeFunctor(int, char* [])
|
2014-10-21 16:51:07 +00:00
|
|
|
{
|
|
|
|
return vtkm::testing::Testing::Run(TestWorkletInvokeFunctor);
|
|
|
|
}
|