Make separate exec and cont versions of Variant

The `Variant` class is templated to hold objects of other types.
Depending on whether those objects of are meant to be used in the
control or execution side, the methods on `Variant` might need to be
declared with (or without) special modifiers. We can sometimes try to
compile the `Variant` methods for both host and device and ask the
device compiler to ignore incompatibilities, but that does not always
work.

To get around that, create two different implementations of `Variant`.
Their API and implementation is exactly the same except one declares its
methods with `VTKM_CONT` and the other its methods `VTKM_EXEC`.
This commit is contained in:
Kenneth Moreland 2020-10-06 15:57:04 -06:00
parent c8c92ffdc4
commit 21db210a73
12 changed files with 310 additions and 312 deletions

@ -13,13 +13,14 @@
#include <vtkm/Assert.h>
#include <vtkm/TypeTraits.h>
#include <vtkm/internal/Variant.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/ArrayHandleCartesianProduct.h>
#include <vtkm/cont/ArrayHandleCast.h>
#include <vtkm/cont/ArrayHandleUniformPointCoordinates.h>
#include <vtkm/cont/internal/Variant.h>
#include <vtkm/exec/internal/Variant.h>
namespace vtkm
{
@ -88,7 +89,7 @@ private:
template <typename... PortalTypes>
struct ArrayPortalMultiplexer
{
using PortalVariantType = vtkm::internal::Variant<PortalTypes...>;
using PortalVariantType = vtkm::exec::internal::Variant<PortalTypes...>;
PortalVariantType PortalVariant;
using ValueType = typename PortalVariantType::template TypeAt<0>::ValueType;
@ -209,7 +210,8 @@ private:
template <typename S>
using StorageToPortalConstControl = typename StorageToArrayHandle<S>::ReadPortalType;
using ArrayHandleVariantType = vtkm::internal::Variant<StorageToArrayHandle<StorageTags>...>;
using ArrayHandleVariantType =
vtkm::cont::internal::Variant<StorageToArrayHandle<StorageTags>...>;
ArrayHandleVariantType ArrayHandleVariant;
public:

@ -33,6 +33,7 @@ set(headers
ReverseConnectivityBuilder.h
StorageError.h
TransferInfo.h
Variant.h
VirtualObjectTransfer.h
VirtualObjectTransferInstantiate.h
VirtualObjectTransferShareWithControl.h

@ -0,0 +1,19 @@
//============================================================================
// 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.
//============================================================================
#ifndef vtk_m_cont_internal_Variant_h
#define vtk_m_cont_internal_Variant_h
// These specify cont version of Variant.
#define VTK_M_DEVICE VTKM_CONT
#define VTK_M_NAMESPACE cont
#include <vtkm/internal/VariantImpl.h>
#endif //vtk_m_cont_internal_Variant_h

@ -13,8 +13,9 @@ set(headers
FastVec.h
ReduceByKeyLookup.h
TaskSingular.h
WorkletInvokeFunctorDetail.h
TwoLevelUniformGridExecutionObject.h
Variant.h
WorkletInvokeFunctorDetail.h
)
vtkm_declare_headers(${headers})

@ -0,0 +1,19 @@
//============================================================================
// 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.
//============================================================================
#ifndef vtk_m_exec_internal_Variant_h
#define vtk_m_exec_internal_Variant_h
// These specify exec version of Variant.
#define VTK_M_DEVICE VTKM_EXEC
#define VTK_M_NAMESPACE exec
#include <vtkm/internal/VariantImpl.h>
#endif //vtk_m_exec_internal_Variant_h

@ -17,6 +17,7 @@ vtkm_declare_headers(${headers})
set(unit_tests
UnitTestErrorMessageBuffer.cxx
UnitTestTaskSingular.cxx
UnitTestVariant.cxx
UnitTestWorkletInvokeFunctor.cxx
)
vtkm_unit_tests(SOURCES ${unit_tests})

@ -8,7 +8,7 @@
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#include <vtkm/internal/Variant.h>
#include <vtkm/exec/internal/Variant.h>
#include <vtkm/testing/Testing.h>
@ -33,7 +33,7 @@ void TestSize()
{
std::cout << "Test size" << std::endl;
using VariantType = vtkm::internal::Variant<float, double, char, short, int, long>;
using VariantType = vtkm::exec::internal::Variant<float, double, char, short, int, long>;
constexpr size_t variantSize = sizeof(VariantType);
@ -46,36 +46,36 @@ void TestIndexing()
{
std::cout << "Test indexing" << std::endl;
using VariantType = vtkm::internal::Variant<TypePlaceholder<0>,
TypePlaceholder<1>,
TypePlaceholder<2>,
TypePlaceholder<3>,
TypePlaceholder<4>,
TypePlaceholder<5>,
TypePlaceholder<6>,
TypePlaceholder<7>,
TypePlaceholder<8>,
TypePlaceholder<9>,
TypePlaceholder<10>,
TypePlaceholder<11>,
TypePlaceholder<12>,
TypePlaceholder<13>,
TypePlaceholder<14>,
TypePlaceholder<15>,
TypePlaceholder<16>,
TypePlaceholder<17>,
TypePlaceholder<18>,
TypePlaceholder<19>,
TypePlaceholder<20>,
TypePlaceholder<21>,
TypePlaceholder<22>,
TypePlaceholder<23>,
TypePlaceholder<24>,
TypePlaceholder<25>,
TypePlaceholder<26>,
TypePlaceholder<27>,
TypePlaceholder<28>,
TypePlaceholder<29>>;
using VariantType = vtkm::exec::internal::Variant<TypePlaceholder<0>,
TypePlaceholder<1>,
TypePlaceholder<2>,
TypePlaceholder<3>,
TypePlaceholder<4>,
TypePlaceholder<5>,
TypePlaceholder<6>,
TypePlaceholder<7>,
TypePlaceholder<8>,
TypePlaceholder<9>,
TypePlaceholder<10>,
TypePlaceholder<11>,
TypePlaceholder<12>,
TypePlaceholder<13>,
TypePlaceholder<14>,
TypePlaceholder<15>,
TypePlaceholder<16>,
TypePlaceholder<17>,
TypePlaceholder<18>,
TypePlaceholder<19>,
TypePlaceholder<20>,
TypePlaceholder<21>,
TypePlaceholder<22>,
TypePlaceholder<23>,
TypePlaceholder<24>,
TypePlaceholder<25>,
TypePlaceholder<26>,
TypePlaceholder<27>,
TypePlaceholder<28>,
TypePlaceholder<29>>;
VariantType variant;
@ -191,48 +191,50 @@ void TestTriviallyCopyable()
VTKM_STATIC_ASSERT(!std::is_trivial<TrivialCopy>::value);
// A variant of trivially constructable things should be trivially constructable
VTKM_STATIC_ASSERT((vtkm::internal::detail::AllTriviallyConstructible<float, int>::value));
VTKM_STATIC_ASSERT((std::is_trivially_constructible<vtkm::internal::Variant<float, int>>::value));
VTKM_STATIC_ASSERT((vtkm::exec::internal::detail::AllTriviallyConstructible<float, int>::value));
VTKM_STATIC_ASSERT(
(std::is_trivially_constructible<vtkm::exec::internal::Variant<float, int>>::value));
// A variant of trivially copyable things should be trivially copyable
VTKM_STATIC_ASSERT(
(vtkm::internal::detail::AllTriviallyCopyable<float, int, TrivialCopy>::value));
(vtkm::exec::internal::detail::AllTriviallyCopyable<float, int, TrivialCopy>::value));
VTKM_STATIC_ASSERT(
(std::is_trivially_copyable<vtkm::internal::Variant<float, int, TrivialCopy>>::value));
(std::is_trivially_copyable<vtkm::exec::internal::Variant<float, int, TrivialCopy>>::value));
// A variant of any non-trivially constructable things is not trivially copyable
VTKM_STATIC_ASSERT((
!vtkm::internal::detail::AllTriviallyConstructible<std::shared_ptr<float>, float, int>::value));
VTKM_STATIC_ASSERT((
!vtkm::internal::detail::AllTriviallyConstructible<float, std::shared_ptr<float>, int>::value));
VTKM_STATIC_ASSERT((
!vtkm::internal::detail::AllTriviallyConstructible<float, int, std::shared_ptr<float>>::value));
VTKM_STATIC_ASSERT((!vtkm::exec::internal::detail::
AllTriviallyConstructible<std::shared_ptr<float>, float, int>::value));
VTKM_STATIC_ASSERT((!vtkm::exec::internal::detail::
AllTriviallyConstructible<float, std::shared_ptr<float>, int>::value));
VTKM_STATIC_ASSERT((!vtkm::exec::internal::detail::
AllTriviallyConstructible<float, int, std::shared_ptr<float>>::value));
VTKM_STATIC_ASSERT((!std::is_trivially_constructible<
vtkm::internal::Variant<std::shared_ptr<float>, float, int>>::value));
vtkm::exec::internal::Variant<std::shared_ptr<float>, float, int>>::value));
VTKM_STATIC_ASSERT((!std::is_trivially_constructible<
vtkm::internal::Variant<float, std::shared_ptr<float>, int>>::value));
vtkm::exec::internal::Variant<float, std::shared_ptr<float>, int>>::value));
VTKM_STATIC_ASSERT((!std::is_trivially_constructible<
vtkm::internal::Variant<float, int, std::shared_ptr<float>>>::value));
vtkm::exec::internal::Variant<float, int, std::shared_ptr<float>>>::value));
// A variant of any non-trivially copyable things is not trivially copyable
VTKM_STATIC_ASSERT(
(!vtkm::internal::detail::AllTriviallyCopyable<std::shared_ptr<float>, float, int>::value));
VTKM_STATIC_ASSERT(
(!vtkm::internal::detail::AllTriviallyCopyable<float, std::shared_ptr<float>, int>::value));
VTKM_STATIC_ASSERT(
(!vtkm::internal::detail::AllTriviallyCopyable<float, int, std::shared_ptr<float>>::value));
VTKM_STATIC_ASSERT((!vtkm::exec::internal::detail::
AllTriviallyCopyable<std::shared_ptr<float>, float, int>::value));
VTKM_STATIC_ASSERT((!vtkm::exec::internal::detail::
AllTriviallyCopyable<float, std::shared_ptr<float>, int>::value));
VTKM_STATIC_ASSERT((!vtkm::exec::internal::detail::
AllTriviallyCopyable<float, int, std::shared_ptr<float>>::value));
VTKM_STATIC_ASSERT((!std::is_trivially_copyable<
vtkm::internal::Variant<std::shared_ptr<float>, float, int>>::value));
vtkm::exec::internal::Variant<std::shared_ptr<float>, float, int>>::value));
VTKM_STATIC_ASSERT((!std::is_trivially_copyable<
vtkm::internal::Variant<float, std::shared_ptr<float>, int>>::value));
vtkm::exec::internal::Variant<float, std::shared_ptr<float>, int>>::value));
VTKM_STATIC_ASSERT((!std::is_trivially_copyable<
vtkm::internal::Variant<float, int, std::shared_ptr<float>>>::value));
vtkm::exec::internal::Variant<float, int, std::shared_ptr<float>>>::value));
// A variant of trivial things should be trivial
VTKM_STATIC_ASSERT((std::is_trivial<vtkm::internal::Variant<float, int>>::value));
VTKM_STATIC_ASSERT((!std::is_trivial<vtkm::internal::Variant<float, int, TrivialCopy>>::value));
VTKM_STATIC_ASSERT((std::is_trivial<vtkm::exec::internal::Variant<float, int>>::value));
VTKM_STATIC_ASSERT(
(!std::is_trivial<vtkm::internal::Variant<float, int, std::shared_ptr<float>>>::value));
(!std::is_trivial<vtkm::exec::internal::Variant<float, int, TrivialCopy>>::value));
VTKM_STATIC_ASSERT(
(!std::is_trivial<vtkm::exec::internal::Variant<float, int, std::shared_ptr<float>>>::value));
#endif // !VTKM_USING_GLIBCXX_4
}
@ -250,36 +252,36 @@ void TestGet()
{
std::cout << "Test Get" << std::endl;
using VariantType = vtkm::internal::Variant<TypePlaceholder<0>,
TypePlaceholder<1>,
vtkm::Id,
TypePlaceholder<3>,
TypePlaceholder<4>,
TypePlaceholder<5>,
TypePlaceholder<6>,
TypePlaceholder<7>,
TypePlaceholder<8>,
TypePlaceholder<9>,
TypePlaceholder<10>,
TypePlaceholder<11>,
TypePlaceholder<12>,
TypePlaceholder<13>,
TypePlaceholder<14>,
TypePlaceholder<15>,
TypePlaceholder<16>,
TypePlaceholder<17>,
TypePlaceholder<18>,
TypePlaceholder<19>,
TypePlaceholder<20>,
TypePlaceholder<21>,
TypePlaceholder<22>,
TypePlaceholder<23>,
TypePlaceholder<24>,
TypePlaceholder<25>,
TypePlaceholder<26>,
vtkm::Float32,
TypePlaceholder<28>,
TypePlaceholder<29>>;
using VariantType = vtkm::exec::internal::Variant<TypePlaceholder<0>,
TypePlaceholder<1>,
vtkm::Id,
TypePlaceholder<3>,
TypePlaceholder<4>,
TypePlaceholder<5>,
TypePlaceholder<6>,
TypePlaceholder<7>,
TypePlaceholder<8>,
TypePlaceholder<9>,
TypePlaceholder<10>,
TypePlaceholder<11>,
TypePlaceholder<12>,
TypePlaceholder<13>,
TypePlaceholder<14>,
TypePlaceholder<15>,
TypePlaceholder<16>,
TypePlaceholder<17>,
TypePlaceholder<18>,
TypePlaceholder<19>,
TypePlaceholder<20>,
TypePlaceholder<21>,
TypePlaceholder<22>,
TypePlaceholder<23>,
TypePlaceholder<24>,
TypePlaceholder<25>,
TypePlaceholder<26>,
vtkm::Float32,
TypePlaceholder<28>,
TypePlaceholder<29>>;
{
const vtkm::Id expectedValue = TestValue(3, vtkm::Id{});
@ -308,36 +310,36 @@ void TestCastAndCall()
{
std::cout << "Test CastAndCall" << std::endl;
using VariantType = vtkm::internal::Variant<TypePlaceholder<0>,
TypePlaceholder<1>,
TypePlaceholder<2>,
TypePlaceholder<3>,
TypePlaceholder<4>,
TypePlaceholder<5>,
TypePlaceholder<6>,
TypePlaceholder<7>,
TypePlaceholder<8>,
TypePlaceholder<9>,
TypePlaceholder<10>,
TypePlaceholder<11>,
TypePlaceholder<12>,
TypePlaceholder<13>,
TypePlaceholder<14>,
TypePlaceholder<15>,
TypePlaceholder<16>,
TypePlaceholder<17>,
TypePlaceholder<18>,
TypePlaceholder<19>,
TypePlaceholder<20>,
TypePlaceholder<21>,
TypePlaceholder<22>,
TypePlaceholder<23>,
TypePlaceholder<24>,
TypePlaceholder<25>,
TypePlaceholder<26>,
TypePlaceholder<27>,
TypePlaceholder<28>,
TypePlaceholder<29>>;
using VariantType = vtkm::exec::internal::Variant<TypePlaceholder<0>,
TypePlaceholder<1>,
TypePlaceholder<2>,
TypePlaceholder<3>,
TypePlaceholder<4>,
TypePlaceholder<5>,
TypePlaceholder<6>,
TypePlaceholder<7>,
TypePlaceholder<8>,
TypePlaceholder<9>,
TypePlaceholder<10>,
TypePlaceholder<11>,
TypePlaceholder<12>,
TypePlaceholder<13>,
TypePlaceholder<14>,
TypePlaceholder<15>,
TypePlaceholder<16>,
TypePlaceholder<17>,
TypePlaceholder<18>,
TypePlaceholder<19>,
TypePlaceholder<20>,
TypePlaceholder<21>,
TypePlaceholder<22>,
TypePlaceholder<23>,
TypePlaceholder<24>,
TypePlaceholder<25>,
TypePlaceholder<26>,
TypePlaceholder<27>,
TypePlaceholder<28>,
TypePlaceholder<29>>;
vtkm::FloatDefault result;
VariantType variant0{ TypePlaceholder<0>{} };
@ -381,11 +383,11 @@ void TestCopyDestroy()
{
std::cout << "Test copy destroy" << std::endl;
using VariantType = vtkm::internal::Variant<TypePlaceholder<0>,
TypePlaceholder<1>,
CountConstructDestruct,
TypePlaceholder<2>,
TypePlaceholder<3>>;
using VariantType = vtkm::exec::internal::Variant<TypePlaceholder<0>,
TypePlaceholder<1>,
CountConstructDestruct,
TypePlaceholder<2>,
TypePlaceholder<3>>;
#ifndef VTKM_USING_GLIBCXX_4
VTKM_STATIC_ASSERT(!std::is_trivially_copyable<VariantType>::value);
#endif // !VTKM_USING_GLIBCXX_4
@ -438,7 +440,7 @@ void TestEmplace()
{
std::cout << "Test Emplace" << std::endl;
using VariantType = vtkm::internal::Variant<vtkm::Id, vtkm::Id3, std::vector<vtkm::Id>>;
using VariantType = vtkm::exec::internal::Variant<vtkm::Id, vtkm::Id3, std::vector<vtkm::Id>>;
VariantType variant;
variant.Emplace<vtkm::Id>(TestValue(0, vtkm::Id{}));

@ -67,8 +67,8 @@ set(headers
IndicesExtrude.h
Invocation.h
Unreachable.h
Variant.h
VariantDetail.h
VariantImpl.h
VariantImplDetail.h
VecOperators.h
Windows.h
)
@ -77,7 +77,7 @@ vtkm_declare_headers(${headers})
vtkm_pyexpander_generated_file(FunctionInterfaceDetailPre.h)
vtkm_pyexpander_generated_file(FunctionInterfaceDetailPost.h)
vtkm_pyexpander_generated_file(VariantDetail.h)
vtkm_pyexpander_generated_file(VariantImplDetail.h)
vtkm_pyexpander_generated_file(VecOperators.h)
add_subdirectory(testing)

@ -7,10 +7,15 @@
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#ifndef vtk_m_internal_Variant_h
#define vtk_m_internal_Variant_h
#include <vtkm/internal/VariantDetail.h>
#if !defined(VTK_M_DEVICE) || !defined(VTK_M_NAMESPACE)
#error VariantImpl.h must be included from Variant.h
// Some defines to make my IDE happy.
#define VTK_M_DEVICE
#define VTK_M_NAMESPACE tmp
#endif
#include <vtkm/internal/VariantImplDetail.h>
#include <vtkm/Deprecated.h>
#include <vtkm/List.h>
@ -20,6 +25,8 @@
namespace vtkm
{
namespace VTK_M_NAMESPACE
{
namespace internal
{
@ -32,9 +39,8 @@ namespace detail
struct VariantCopyFunctor
{
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename T>
VTKM_EXEC_CONT void operator()(const T& src, void* destPointer) const noexcept
VTK_M_DEVICE void operator()(const T& src, void* destPointer) const noexcept
{
new (destPointer) T(src);
}
@ -42,9 +48,8 @@ struct VariantCopyFunctor
struct VariantDestroyFunctor
{
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename T>
VTKM_EXEC_CONT void operator()(T& src) const noexcept
VTK_M_DEVICE void operator()(T& src) const noexcept
{
src.~T();
}
@ -104,7 +109,8 @@ template <typename VariantType>
struct VariantTriviallyCopyable;
template <typename... Ts>
struct VariantTriviallyCopyable<vtkm::internal::Variant<Ts...>> : AllTriviallyCopyable<Ts...>
struct VariantTriviallyCopyable<vtkm::VTK_M_NAMESPACE::internal::Variant<Ts...>>
: AllTriviallyCopyable<Ts...>
{
};
@ -165,7 +171,7 @@ template <typename VariantType>
struct VariantTriviallyConstructible;
template <typename... Ts>
struct VariantTriviallyConstructible<vtkm::internal::Variant<Ts...>>
struct VariantTriviallyConstructible<vtkm::VTK_M_NAMESPACE::internal::Variant<Ts...>>
: AllTriviallyConstructible<Ts...>
{
};
@ -180,19 +186,19 @@ struct VariantStorageImpl
template <vtkm::IdComponent Index>
using TypeAt = typename vtkm::ListAt<vtkm::List<Ts...>, Index>;
VTKM_EXEC_CONT void* GetPointer() { return reinterpret_cast<void*>(&this->Storage); }
VTKM_EXEC_CONT const void* GetPointer() const
VTK_M_DEVICE void* GetPointer() { return reinterpret_cast<void*>(&this->Storage); }
VTK_M_DEVICE const void* GetPointer() const
{
return reinterpret_cast<const void*>(&this->Storage);
}
VTKM_EXEC_CONT vtkm::IdComponent GetIndex() const noexcept { return this->Index; }
VTKM_EXEC_CONT bool IsValid() const noexcept
VTK_M_DEVICE vtkm::IdComponent GetIndex() const noexcept { return this->Index; }
VTK_M_DEVICE bool IsValid() const noexcept
{
return (this->Index >= 0) && (this->Index < static_cast<vtkm::IdComponent>(sizeof...(Ts)));
}
VTKM_EXEC_CONT void Reset() noexcept
VTK_M_DEVICE void Reset() noexcept
{
if (this->IsValid())
{
@ -202,7 +208,7 @@ struct VariantStorageImpl
}
template <typename Functor, typename... Args>
VTKM_EXEC_CONT auto CastAndCall(Functor&& f, Args&&... args) const
VTK_M_DEVICE auto CastAndCall(Functor&& f, Args&&... args) const
noexcept(noexcept(f(std::declval<const TypeAt<0>&>(), args...)))
-> decltype(f(std::declval<const TypeAt<0>&>(), args...))
{
@ -216,7 +222,7 @@ struct VariantStorageImpl
}
template <typename Functor, typename... Args>
VTKM_EXEC_CONT auto CastAndCall(Functor&& f, Args&&... args) noexcept(
VTK_M_DEVICE auto CastAndCall(Functor&& f, Args&&... args) noexcept(
noexcept(f(std::declval<const TypeAt<0>&>(), args...)))
-> decltype(f(std::declval<TypeAt<0>&>(), args...))
{
@ -238,8 +244,9 @@ struct VariantConstructorImpl;
// Can trivially construct, deconstruct, and copy all data. (Probably all trivial classes.)
template <typename... Ts>
struct VariantConstructorImpl<vtkm::internal::Variant<Ts...>, std::true_type, std::true_type>
: VariantStorageImpl<Ts...>
struct VariantConstructorImpl<vtkm::VTK_M_NAMESPACE::internal::Variant<Ts...>,
std::true_type,
std::true_type> : VariantStorageImpl<Ts...>
{
VariantConstructorImpl() = default;
~VariantConstructorImpl() = default;
@ -253,10 +260,11 @@ struct VariantConstructorImpl<vtkm::internal::Variant<Ts...>, std::true_type, st
// Can trivially copy, but cannot trivially construct. Common if a class is simple but
// initializes itself.
template <typename... Ts>
struct VariantConstructorImpl<vtkm::internal::Variant<Ts...>, std::false_type, std::true_type>
: VariantStorageImpl<Ts...>
struct VariantConstructorImpl<vtkm::VTK_M_NAMESPACE::internal::Variant<Ts...>,
std::false_type,
std::true_type> : VariantStorageImpl<Ts...>
{
VTKM_EXEC_CONT VariantConstructorImpl() { this->Index = -1; }
VTK_M_DEVICE VariantConstructorImpl() { this->Index = -1; }
// Any trivially copyable class is trivially destructable.
~VariantConstructorImpl() = default;
@ -269,26 +277,27 @@ struct VariantConstructorImpl<vtkm::internal::Variant<Ts...>, std::false_type, s
// Cannot trivially copy. We assume we cannot trivially construct/destruct.
template <typename construct_type, typename... Ts>
struct VariantConstructorImpl<vtkm::internal::Variant<Ts...>, construct_type, std::false_type>
: VariantStorageImpl<Ts...>
struct VariantConstructorImpl<vtkm::VTK_M_NAMESPACE::internal::Variant<Ts...>,
construct_type,
std::false_type> : VariantStorageImpl<Ts...>
{
VTKM_EXEC_CONT VariantConstructorImpl() { this->Index = -1; }
VTKM_EXEC_CONT ~VariantConstructorImpl() { this->Reset(); }
VTK_M_DEVICE VariantConstructorImpl() { this->Index = -1; }
VTK_M_DEVICE ~VariantConstructorImpl() { this->Reset(); }
VTKM_EXEC_CONT VariantConstructorImpl(const VariantConstructorImpl& src) noexcept
VTK_M_DEVICE VariantConstructorImpl(const VariantConstructorImpl& src) noexcept
{
src.CastAndCall(VariantCopyFunctor{}, this->GetPointer());
this->Index = src.Index;
}
VTKM_EXEC_CONT VariantConstructorImpl(VariantConstructorImpl&& rhs) noexcept
VTK_M_DEVICE VariantConstructorImpl(VariantConstructorImpl&& rhs) noexcept
{
this->Storage = std::move(rhs.Storage);
this->Index = std::move(rhs.Index);
rhs.Index = -1;
}
VTKM_EXEC_CONT VariantConstructorImpl& operator=(const VariantConstructorImpl& src) noexcept
VTK_M_DEVICE VariantConstructorImpl& operator=(const VariantConstructorImpl& src) noexcept
{
this->Reset();
src.CastAndCall(detail::VariantCopyFunctor{}, this->GetPointer());
@ -296,7 +305,7 @@ struct VariantConstructorImpl<vtkm::internal::Variant<Ts...>, construct_type, st
return *this;
}
VTKM_EXEC_CONT VariantConstructorImpl& operator=(VariantConstructorImpl&& rhs) noexcept
VTK_M_DEVICE VariantConstructorImpl& operator=(VariantConstructorImpl&& rhs) noexcept
{
this->Reset();
// Get rid of spurious GCC-10 warning:
@ -326,10 +335,7 @@ public:
/// Returns the index of the type of object this variant is storing. If no object is currently
/// stored (i.e. the `Variant` is invalid), an invalid is returned.
///
VTKM_EXEC_CONT vtkm::IdComponent GetIndex() const noexcept
{
return this->Superclass::GetIndex();
}
VTK_M_DEVICE vtkm::IdComponent GetIndex() const noexcept { return this->Superclass::GetIndex(); }
/// Returns true if this `Variant` is storing an object from one of the types in the template
/// list, false otherwise.
@ -338,7 +344,7 @@ public:
/// is undefined. The `Variant` could report itself as validly containing an object that
/// is trivially constructed.
///
VTKM_EXEC_CONT bool IsValid() const noexcept { return this->Superclass::IsValid(); }
VTK_M_DEVICE bool IsValid() const noexcept { return this->Superclass::IsValid(); }
/// Type that converts to a std::integral_constant containing the index of the given type (or
/// -1 if that type is not in the list).
@ -348,7 +354,7 @@ public:
/// Returns the index for the given type (or -1 if that type is not in the list).
///
template <typename T>
VTKM_EXEC_CONT static constexpr vtkm::IdComponent GetIndexOf()
VTK_M_DEVICE static constexpr vtkm::IdComponent GetIndexOf()
{
return IndexOf<T>::value;
}
@ -369,9 +375,8 @@ public:
Variant& operator=(const Variant&) = default;
Variant& operator=(Variant&&) = default;
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename T>
VTKM_EXEC_CONT Variant(const T& src) noexcept
VTK_M_DEVICE Variant(const T& src) noexcept
{
constexpr vtkm::IdComponent index = GetIndexOf<T>();
// Might be a way to use an enable_if to enforce a proper type.
@ -381,9 +386,8 @@ public:
this->Index = index;
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename T>
VTKM_EXEC_CONT Variant(const T&& src) noexcept
VTK_M_DEVICE Variant(const T&& src) noexcept
{
constexpr vtkm::IdComponent index = IndexOf<T>::value;
// Might be a way to use an enable_if to enforce a proper type.
@ -394,7 +398,7 @@ public:
}
template <typename T, typename... Args>
VTKM_EXEC_CONT T& Emplace(Args&&... args)
VTK_M_DEVICE T& Emplace(Args&&... args)
{
constexpr vtkm::IdComponent I = GetIndexOf<T>();
VTKM_STATIC_ASSERT_MSG(I >= 0, "Variant::Emplace called with invalid type.");
@ -402,7 +406,7 @@ public:
}
template <typename T, typename U, typename... Args>
VTKM_EXEC_CONT T& Emplace(std::initializer_list<U> il, Args&&... args)
VTK_M_DEVICE T& Emplace(std::initializer_list<U> il, Args&&... args)
{
constexpr vtkm::IdComponent I = GetIndexOf<T>();
VTKM_STATIC_ASSERT_MSG(I >= 0, "Variant::Emplace called with invalid type.");
@ -410,7 +414,7 @@ public:
}
template <vtkm::IdComponent I, typename... Args>
VTKM_EXEC_CONT TypeAt<I>& Emplace(Args&&... args)
VTK_M_DEVICE TypeAt<I>& Emplace(Args&&... args)
{
VTKM_STATIC_ASSERT_MSG((I >= 0) && (I < NumberOfTypes),
"Variant::Emplace called with invalid index");
@ -418,7 +422,7 @@ public:
}
template <vtkm::IdComponent I, typename U, typename... Args>
VTKM_EXEC_CONT TypeAt<I>& Emplace(std::initializer_list<U> il, Args&&... args)
VTK_M_DEVICE TypeAt<I>& Emplace(std::initializer_list<U> il, Args&&... args)
{
VTKM_STATIC_ASSERT_MSG((I >= 0) && (I < NumberOfTypes),
"Variant::Emplace called with invalid index");
@ -426,9 +430,8 @@ public:
}
private:
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename T, vtkm::IdComponent I, typename... Args>
VTKM_EXEC_CONT T& EmplaceImpl(Args&&... args)
VTK_M_DEVICE T& EmplaceImpl(Args&&... args)
{
this->Reset();
T* value = new (this->GetPointer()) T{ args... };
@ -436,9 +439,8 @@ private:
return *value;
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename T, vtkm::IdComponent I, typename U, typename... Args>
VTKM_EXEC_CONT T& EmplaceImpl(std::initializer_list<U> il, Args&&... args)
VTK_M_DEVICE T& EmplaceImpl(std::initializer_list<U> il, Args&&... args)
{
this->Reset();
T* value = new (this->GetPointer()) T(il, args...);
@ -452,14 +454,14 @@ public:
/// variant does not contain the value at the given index.
///
template <vtkm::IdComponent I>
VTKM_EXEC_CONT TypeAt<I>& Get() noexcept
VTK_M_DEVICE TypeAt<I>& Get() noexcept
{
VTKM_ASSERT(I == this->GetIndex());
return *reinterpret_cast<TypeAt<I>*>(this->GetPointer());
}
template <vtkm::IdComponent I>
VTKM_EXEC_CONT const TypeAt<I>& Get() const noexcept
VTK_M_DEVICE const TypeAt<I>& Get() const noexcept
{
VTKM_ASSERT(I == this->GetIndex());
return *reinterpret_cast<const TypeAt<I>*>(this->GetPointer());
@ -471,14 +473,14 @@ public:
/// contain a value of the given type.
///
template <typename T>
VTKM_EXEC_CONT T& Get() noexcept
VTK_M_DEVICE T& Get() noexcept
{
VTKM_ASSERT(this->GetIndexOf<T>() == this->GetIndex());
return *reinterpret_cast<T*>(this->GetPointer());
}
template <typename T>
VTKM_EXEC_CONT const T& Get() const noexcept
VTK_M_DEVICE const T& Get() const noexcept
{
VTKM_ASSERT(this->GetIndexOf<T>() == this->GetIndex());
return *reinterpret_cast<const T*>(this->GetPointer());
@ -493,7 +495,7 @@ public:
/// The results are undefined if the Variant is not valid.
///
template <typename Functor, typename... Args>
VTKM_EXEC_CONT auto CastAndCall(Functor&& f, Args&&... args) const
VTK_M_DEVICE auto CastAndCall(Functor&& f, Args&&... args) const
noexcept(noexcept(f(std::declval<const TypeAt<0>&>(), args...)))
-> decltype(f(std::declval<const TypeAt<0>&>(), args...))
{
@ -501,7 +503,7 @@ public:
}
template <typename Functor, typename... Args>
VTKM_EXEC_CONT auto CastAndCall(Functor&& f, Args&&... args) noexcept(
VTK_M_DEVICE auto CastAndCall(Functor&& f, Args&&... args) noexcept(
noexcept(f(std::declval<const TypeAt<0>&>(), args...)))
-> decltype(f(std::declval<TypeAt<0>&>(), args...))
{
@ -511,7 +513,7 @@ public:
/// Destroys any object the Variant is holding and sets the Variant to an invalid state. This
/// method is not thread safe.
///
VTKM_EXEC_CONT void Reset() noexcept { this->Superclass::Reset(); }
VTK_M_DEVICE void Reset() noexcept { this->Superclass::Reset(); }
};
/// \brief Convert a ListTag to a Variant.
@ -522,13 +524,15 @@ template <typename ListTag>
using ListTagAsVariant VTKM_DEPRECATED(
1.6,
"vtkm::ListTag is no longer supported. Use vtkm::List instead.") =
vtkm::ListApply<ListTag, vtkm::internal::Variant>;
vtkm::ListApply<ListTag, vtkm::VTK_M_NAMESPACE::internal::Variant>;
/// \brief Convert a `List` to a `Variant`.
///
template <typename List>
using ListAsVariant = vtkm::ListApply<List, vtkm::internal::Variant>;
using ListAsVariant = vtkm::ListApply<List, vtkm::VTK_M_NAMESPACE::internal::Variant>;
}
} // namespace vtkm::internal
}
} // namespace vtkm::VTK_M_NAMESPACE::internal
#endif //vtk_m_internal_Variant_h
#undef VTK_M_DEVICE
#undef VTK_M_NAMESPACE

@ -10,11 +10,8 @@
// **** DO NOT EDIT THIS FILE!!! ****
// This file is automatically generated by VariantDetail.h.in
#ifndef vtk_m_internal_VariantDetail_h
#define vtk_m_internal_VariantDetail_h
#ifndef vtk_m_internal_Variant_h
#error VariantDetail.h must be included from Variant.h
#if !defined(VTK_M_DEVICE) || !defined(VTK_M_NAMESPACE)
#error VarianImplDetail.h must be included from VariantImpl.h
#endif
#include <vtkm/Types.h>
@ -27,6 +24,8 @@
namespace vtkm
{
namespace VTK_M_NAMESPACE
{
namespace internal
{
namespace detail
@ -35,20 +34,20 @@ namespace detail
template <typename ReturnType>
struct VariantDummyReturn
{
VTKM_EXEC_CONT static inline ReturnType F() noexcept { return ReturnType{}; }
VTK_M_DEVICE static inline ReturnType F() noexcept { return ReturnType{}; }
};
template <>
struct VariantDummyReturn<void>
{
VTKM_EXEC_CONT static inline void F() noexcept {}
VTK_M_DEVICE static inline void F() noexcept {}
};
template <typename ReturnType, typename Functor, typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(brigand::list<>,
vtkm::IdComponent,
Functor&&,
const void*,
Args&&...) noexcept
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(brigand::list<>,
vtkm::IdComponent,
Functor&&,
const void*,
Args&&...) noexcept
{
// If we are here, it means we failed to find the appropriate type in a variant
VTKM_ASSERT(false && "Internal error, bad Variant state.");
@ -57,12 +56,11 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(brigand::list<>,
// clang-format off
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0>,
vtkm::IdComponent index,
Functor&& f,
@ -80,12 +78,11 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0>,
vtkm::IdComponent index,
Functor&& f,
@ -103,13 +100,12 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename T1,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0, T1>,
vtkm::IdComponent index,
Functor&& f,
@ -129,13 +125,12 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename T1,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0, T1>,
vtkm::IdComponent index,
Functor&& f,
@ -155,14 +150,13 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename T1,
typename T2,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0, T1, T2>,
vtkm::IdComponent index,
Functor&& f,
@ -184,14 +178,13 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename T1,
typename T2,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0, T1, T2>,
vtkm::IdComponent index,
Functor&& f,
@ -213,7 +206,6 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename T1,
@ -221,7 +213,7 @@ template <typename ReturnType,
typename T3,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0, T1, T2, T3>,
vtkm::IdComponent index,
Functor&& f,
@ -245,7 +237,6 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename T1,
@ -253,7 +244,7 @@ template <typename ReturnType,
typename T3,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0, T1, T2, T3>,
vtkm::IdComponent index,
Functor&& f,
@ -277,7 +268,6 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename T1,
@ -286,7 +276,7 @@ template <typename ReturnType,
typename T4,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0, T1, T2, T3, T4>,
vtkm::IdComponent index,
Functor&& f,
@ -312,7 +302,6 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename T1,
@ -321,7 +310,7 @@ template <typename ReturnType,
typename T4,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0, T1, T2, T3, T4>,
vtkm::IdComponent index,
Functor&& f,
@ -347,7 +336,6 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename T1,
@ -357,7 +345,7 @@ template <typename ReturnType,
typename T5,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0, T1, T2, T3, T4, T5>,
vtkm::IdComponent index,
Functor&& f,
@ -385,7 +373,6 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename T1,
@ -395,7 +382,7 @@ template <typename ReturnType,
typename T5,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0, T1, T2, T3, T4, T5>,
vtkm::IdComponent index,
Functor&& f,
@ -423,7 +410,6 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename T1,
@ -434,7 +420,7 @@ template <typename ReturnType,
typename T6,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0, T1, T2, T3, T4, T5, T6>,
vtkm::IdComponent index,
Functor&& f,
@ -464,7 +450,6 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename T1,
@ -475,7 +460,7 @@ template <typename ReturnType,
typename T6,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0, T1, T2, T3, T4, T5, T6>,
vtkm::IdComponent index,
Functor&& f,
@ -505,7 +490,6 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename T1,
@ -517,7 +501,7 @@ template <typename ReturnType,
typename T7,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0, T1, T2, T3, T4, T5, T6, T7>,
vtkm::IdComponent index,
Functor&& f,
@ -549,7 +533,6 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename T1,
@ -561,7 +544,7 @@ template <typename ReturnType,
typename T7,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0, T1, T2, T3, T4, T5, T6, T7>,
vtkm::IdComponent index,
Functor&& f,
@ -593,7 +576,6 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename T1,
@ -606,7 +588,7 @@ template <typename ReturnType,
typename T8,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0, T1, T2, T3, T4, T5, T6, T7, T8>,
vtkm::IdComponent index,
Functor&& f,
@ -640,7 +622,6 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename T1,
@ -653,7 +634,7 @@ template <typename ReturnType,
typename T8,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0, T1, T2, T3, T4, T5, T6, T7, T8>,
vtkm::IdComponent index,
Functor&& f,
@ -687,7 +668,6 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename T1,
@ -701,7 +681,7 @@ template <typename ReturnType,
typename T9,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>,
vtkm::IdComponent index,
Functor&& f,
@ -737,7 +717,6 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename T1,
@ -751,7 +730,7 @@ template <typename ReturnType,
typename T9,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>,
vtkm::IdComponent index,
Functor&& f,
@ -787,7 +766,6 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename T1,
@ -802,7 +780,7 @@ template <typename ReturnType,
typename T10,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>,
vtkm::IdComponent index,
Functor&& f,
@ -840,7 +818,6 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename T1,
@ -855,7 +832,7 @@ template <typename ReturnType,
typename T10,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10>,
vtkm::IdComponent index,
Functor&& f,
@ -893,7 +870,6 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename T1,
@ -909,7 +885,7 @@ template <typename ReturnType,
typename T11,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>,
vtkm::IdComponent index,
Functor&& f,
@ -949,7 +925,6 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename T1,
@ -965,7 +940,7 @@ template <typename ReturnType,
typename T11,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>,
vtkm::IdComponent index,
Functor&& f,
@ -1005,7 +980,6 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename T1,
@ -1022,7 +996,7 @@ template <typename ReturnType,
typename T12,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>,
vtkm::IdComponent index,
Functor&& f,
@ -1064,7 +1038,6 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename T1,
@ -1081,7 +1054,7 @@ template <typename ReturnType,
typename T12,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>,
vtkm::IdComponent index,
Functor&& f,
@ -1123,7 +1096,6 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename T1,
@ -1141,7 +1113,7 @@ template <typename ReturnType,
typename T13,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>,
vtkm::IdComponent index,
Functor&& f,
@ -1185,7 +1157,6 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename T1,
@ -1203,7 +1174,7 @@ template <typename ReturnType,
typename T13,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>,
vtkm::IdComponent index,
Functor&& f,
@ -1247,7 +1218,6 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename T1,
@ -1266,7 +1236,7 @@ template <typename ReturnType,
typename T14,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>,
vtkm::IdComponent index,
Functor&& f,
@ -1312,7 +1282,6 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename T1,
@ -1331,7 +1300,7 @@ template <typename ReturnType,
typename T14,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14>,
vtkm::IdComponent index,
Functor&& f,
@ -1377,7 +1346,6 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename T1,
@ -1397,7 +1365,7 @@ template <typename ReturnType,
typename T15,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>,
vtkm::IdComponent index,
Functor&& f,
@ -1445,7 +1413,6 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename T1,
@ -1465,7 +1432,7 @@ template <typename ReturnType,
typename T15,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15>,
vtkm::IdComponent index,
Functor&& f,
@ -1513,7 +1480,6 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename T1,
@ -1534,7 +1500,7 @@ template <typename ReturnType,
typename T16,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>,
vtkm::IdComponent index,
Functor&& f,
@ -1584,7 +1550,6 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename T1,
@ -1605,7 +1570,7 @@ template <typename ReturnType,
typename T16,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>,
vtkm::IdComponent index,
Functor&& f,
@ -1655,7 +1620,6 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename T1,
@ -1677,7 +1641,7 @@ template <typename ReturnType,
typename T17,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17>,
vtkm::IdComponent index,
Functor&& f,
@ -1729,7 +1693,6 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename T1,
@ -1751,7 +1714,7 @@ template <typename ReturnType,
typename T17,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17>,
vtkm::IdComponent index,
Functor&& f,
@ -1803,7 +1766,6 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename T1,
@ -1826,7 +1788,7 @@ template <typename ReturnType,
typename T18,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18>,
vtkm::IdComponent index,
Functor&& f,
@ -1880,7 +1842,6 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename T1,
@ -1903,7 +1864,7 @@ template <typename ReturnType,
typename T18,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18>,
vtkm::IdComponent index,
Functor&& f,
@ -1957,7 +1918,6 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename T1,
@ -1981,7 +1941,7 @@ template <typename ReturnType,
typename T19,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19>,
vtkm::IdComponent index,
Functor&& f,
@ -2037,7 +1997,6 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename T1,
@ -2061,7 +2020,7 @@ template <typename ReturnType,
typename T19,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19>,
vtkm::IdComponent index,
Functor&& f,
@ -2120,7 +2079,6 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
//clang-format on
// Recurse for cases where Variant has more than 20 types
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename T1,
@ -2146,7 +2104,7 @@ template <typename ReturnType,
typename... RemainingT,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, RemainingT...>,
vtkm::IdComponent index,
Functor&& f,
@ -2169,7 +2127,6 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
typename T0,
typename T1,
@ -2195,7 +2152,7 @@ template <typename ReturnType,
typename... RemainingT,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, RemainingT...>,
vtkm::IdComponent index,
Functor&& f,
@ -2220,6 +2177,5 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
} // vtkm::internal::detail
#endif //vtk_m_internal_VariantDetail_h
}
} // vtkm::VTK_M_NAMESPACE::internal::detail

@ -22,11 +22,8 @@ $# Ignore the following comment. It is meant for the generated file.
// **** DO NOT EDIT THIS FILE!!! ****
// This file is automatically generated by VariantDetail.h.in
#ifndef vtk_m_internal_VariantDetail_h
#define vtk_m_internal_VariantDetail_h
#ifndef vtk_m_internal_Variant_h
#error VariantDetail.h must be included from Variant.h
#if !defined(VTK_M_DEVICE) || !defined(VTK_M_NAMESPACE)
#error VarianImplDetail.h must be included from VariantImpl.h
#endif
#include <vtkm/Types.h>
@ -52,6 +49,8 @@ $extend(type_list)\
namespace vtkm
{
namespace VTK_M_NAMESPACE
{
namespace internal
{
namespace detail
@ -60,20 +59,20 @@ namespace detail
template <typename ReturnType>
struct VariantDummyReturn
{
VTKM_EXEC_CONT static inline ReturnType F() noexcept { return ReturnType{}; }
VTK_M_DEVICE static inline ReturnType F() noexcept { return ReturnType{}; }
};
template <>
struct VariantDummyReturn<void>
{
VTKM_EXEC_CONT static inline void F() noexcept {}
VTK_M_DEVICE static inline void F() noexcept {}
};
template <typename ReturnType, typename Functor, typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(brigand::list<>,
vtkm::IdComponent,
Functor&&,
const void*,
Args&&...) noexcept
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(brigand::list<>,
vtkm::IdComponent,
Functor&&,
const void*,
Args&&...) noexcept
{
// If we are here, it means we failed to find the appropriate type in a variant
VTKM_ASSERT(false && "Internal error, bad Variant state.");
@ -83,14 +82,13 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(brigand::list<>,
// clang-format off
$for(num_params in range(0, max_expanded))\
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
$for(param_index in range(0, num_params + 1))\
typename T$(param_index),
$endfor\
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<$type_list(num_params)>,
vtkm::IdComponent index,
Functor&& f,
@ -110,14 +108,13 @@ $endfor\
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
$for(param_index in range(0, num_params + 1))\
typename T$(param_index),
$endfor\
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<$type_list(num_params)>,
vtkm::IdComponent index,
Functor&& f,
@ -141,7 +138,6 @@ $endfor\
//clang-format on
// Recurse for cases where Variant has more than $(max_expanded) types
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
$for(param_index in range(0, max_expanded + 1))\
typename T$(param_index),
@ -149,7 +145,7 @@ $endfor\
typename... RemainingT,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<$type_list(max_expanded), RemainingT...>,
vtkm::IdComponent index,
Functor&& f,
@ -172,7 +168,6 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
VTKM_SUPPRESS_EXEC_WARNINGS
template <typename ReturnType,
$for(param_index in range(0, max_expanded + 1))\
typename T$(param_index),
@ -180,7 +175,7 @@ $endfor\
typename... RemainingT,
typename Functor,
typename... Args>
VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
VTK_M_DEVICE inline ReturnType VariantCastAndCallImpl(
brigand::list<$type_list(max_expanded), RemainingT...>,
vtkm::IdComponent index,
Functor&& f,
@ -205,6 +200,5 @@ VTKM_EXEC_CONT inline ReturnType VariantCastAndCallImpl(
}
}
} // vtkm::internal::detail
#endif //vtk_m_internal_VariantDetail_h
}
} // vtkm::VTK_M_NAMESPACE::internal::detail

@ -14,6 +14,5 @@ set(unit_tests
UnitTestConfigureFor32.cxx
UnitTestConfigureFor64.cxx
#UnitTestFunctionInterface.cxx #FIXME
UnitTestVariant.cxx
)
vtkm_unit_tests(SOURCES ${unit_tests})