2014-10-21 16:51:07 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2014-10-21 16:51:07 +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.
|
|
|
|
//============================================================================
|
|
|
|
|
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; }
|
|
|
|
};
|
|
|
|
|
2019-01-21 02:14:55 +00:00
|
|
|
struct MyThreadToOutputMapPortal
|
|
|
|
{
|
|
|
|
using ValueType = vtkm::Id;
|
|
|
|
VTKM_EXEC_CONT
|
|
|
|
vtkm::Id Get(vtkm::Id index) const { return index; }
|
|
|
|
};
|
|
|
|
|
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 <>
|
2020-04-14 15:00:46 +00:00
|
|
|
struct Fetch<TestFetchTagInput, vtkm::exec::arg::AspectTagDefault, 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 <>
|
2020-04-14 15:00:46 +00:00
|
|
|
struct Fetch<TestFetchTagOutput, vtkm::exec::arg::AspectTagDefault, 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
|
|
|
|
2018-05-25 21:18:41 +00:00
|
|
|
using TestControlSignature = void(TestControlSignatureTagInput, TestControlSignatureTagOutput);
|
2017-08-16 15:34:21 +00:00
|
|
|
using TestControlInterface = vtkm::internal::FunctionInterface<TestControlSignature>;
|
2014-10-21 16:51:07 +00:00
|
|
|
|
2018-05-25 21:18:41 +00:00
|
|
|
using TestExecutionSignature1 = void(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
|
|
|
|
2018-05-25 21:18:41 +00:00
|
|
|
using TestExecutionSignature2 = vtkm::exec::arg::BasicArg<2>(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,
|
2019-01-21 02:14:55 +00:00
|
|
|
typename ThreadToOutArrayType,
|
2017-05-26 17:53:28 +00:00
|
|
|
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,
|
2019-01-21 02:14:55 +00:00
|
|
|
const ThreadToOutArrayType& threadToOut,
|
2017-05-26 17:53:28 +00:00
|
|
|
const InputDomainType&,
|
|
|
|
const G& globalThreadIndexOffset) const
|
2015-10-07 18:14:00 +00:00
|
|
|
{
|
2019-01-21 02:14:55 +00:00
|
|
|
const vtkm::Id outIndex = threadToOut.Get(threadIndex);
|
2017-05-26 17:53:28 +00:00
|
|
|
return vtkm::exec::arg::ThreadIndicesBasic(
|
2019-01-21 02:14:55 +00:00
|
|
|
threadIndex, outToIn.Get(outIndex), visit.Get(outIndex), outIndex, 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
|
|
|
{
|
2019-01-21 02:14:55 +00:00
|
|
|
const vtkm::Id outputIndex = invocation.ThreadToOutputMap.Get(index);
|
2015-10-07 18:14:00 +00:00
|
|
|
vtkm::exec::internal::detail::DoWorkletInvokeFunctor(
|
2017-05-26 17:53:28 +00:00
|
|
|
TestWorkletProxy(),
|
|
|
|
invocation,
|
2019-01-21 02:14:55 +00:00
|
|
|
vtkm::exec::arg::ThreadIndicesBasic(index,
|
|
|
|
invocation.OutputToInputMap.Get(outputIndex),
|
|
|
|
invocation.VisitArray.Get(outputIndex),
|
|
|
|
outputIndex));
|
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(),
|
2019-01-21 02:14:55 +00:00
|
|
|
MyVisitArrayPortal(),
|
|
|
|
MyThreadToOutputMapPortal()),
|
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(),
|
2019-01-21 02:14:55 +00:00
|
|
|
MyVisitArrayPortal(),
|
|
|
|
MyThreadToOutputMapPortal()),
|
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
|
|
|
|
|
2019-01-01 22:19:02 +00:00
|
|
|
int UnitTestWorkletInvokeFunctor(int argc, char* argv[])
|
2014-10-21 16:51:07 +00:00
|
|
|
{
|
2019-01-01 22:19:02 +00:00
|
|
|
return vtkm::testing::Testing::Run(TestWorkletInvokeFunctor, argc, argv);
|
2014-10-21 16:51:07 +00:00
|
|
|
}
|