mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-16 17:22:55 +00:00
Add BitFieldIn/Out/InOut worklet signature tags.
These provide an appropriate BitPortal for use in worklets.
This commit is contained in:
parent
a66510e819
commit
0c70f9b9ac
@ -25,6 +25,7 @@ set(headers
|
||||
TransportTagArrayInOut.h
|
||||
TransportTagArrayOut.h
|
||||
TransportTagAtomicArray.h
|
||||
TransportTagBitField.h
|
||||
TransportTagCellSetIn.h
|
||||
TransportTagExecObject.h
|
||||
TransportTagKeyedValuesIn.h
|
||||
@ -38,6 +39,7 @@ set(headers
|
||||
TypeCheck.h
|
||||
TypeCheckTagArray.h
|
||||
TypeCheckTagAtomicArray.h
|
||||
TypeCheckTagBitField.h
|
||||
TypeCheckTagCellSet.h
|
||||
TypeCheckTagCellSetStructured.h
|
||||
TypeCheckTagExecObject.h
|
||||
|
89
vtkm/cont/arg/TransportTagBitField.h
Normal file
89
vtkm/cont/arg/TransportTagBitField.h
Normal file
@ -0,0 +1,89 @@
|
||||
//============================================================================
|
||||
// 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 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
||||
// Copyright 2015 UT-Battelle, LLC.
|
||||
// Copyright 2015 Los Alamos National Security.
|
||||
//
|
||||
// Under the terms of Contract DE-NA0003525 with NTESS,
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_cont_arg_TransportTagBitField_h
|
||||
#define vtk_m_cont_arg_TransportTagBitField_h
|
||||
|
||||
#include <vtkm/cont/arg/Transport.h>
|
||||
|
||||
#include <vtkm/cont/BitField.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace cont
|
||||
{
|
||||
namespace arg
|
||||
{
|
||||
|
||||
struct TransportTagBitFieldIn
|
||||
{
|
||||
};
|
||||
struct TransportTagBitFieldOut
|
||||
{
|
||||
};
|
||||
struct TransportTagBitFieldInOut
|
||||
{
|
||||
};
|
||||
|
||||
template <typename Device>
|
||||
struct Transport<vtkm::cont::arg::TransportTagBitFieldIn, vtkm::cont::BitField, Device>
|
||||
{
|
||||
using ExecObjectType =
|
||||
typename vtkm::cont::BitField::template ExecutionTypes<Device>::PortalConst;
|
||||
|
||||
template <typename InputDomainType>
|
||||
VTKM_CONT ExecObjectType
|
||||
operator()(vtkm::cont::BitField& field, const InputDomainType&, vtkm::Id, vtkm::Id) const
|
||||
{
|
||||
return field.PrepareForInput(Device{});
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Device>
|
||||
struct Transport<vtkm::cont::arg::TransportTagBitFieldOut, vtkm::cont::BitField, Device>
|
||||
{
|
||||
using ExecObjectType = typename vtkm::cont::BitField::template ExecutionTypes<Device>::Portal;
|
||||
|
||||
template <typename InputDomainType>
|
||||
VTKM_CONT ExecObjectType
|
||||
operator()(vtkm::cont::BitField& field, const InputDomainType&, vtkm::Id, vtkm::Id) const
|
||||
{
|
||||
// This behaves similarly to WholeArray tags, where "Out" maps to InPlace
|
||||
// since we don't want to reallocate or enforce size restrictions.
|
||||
return field.PrepareForInPlace(Device{});
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Device>
|
||||
struct Transport<vtkm::cont::arg::TransportTagBitFieldInOut, vtkm::cont::BitField, Device>
|
||||
{
|
||||
using ExecObjectType = typename vtkm::cont::BitField::template ExecutionTypes<Device>::Portal;
|
||||
|
||||
template <typename InputDomainType>
|
||||
VTKM_CONT ExecObjectType
|
||||
operator()(vtkm::cont::BitField& field, const InputDomainType&, vtkm::Id, vtkm::Id) const
|
||||
{
|
||||
return field.PrepareForInPlace(Device{});
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::cont::arg
|
||||
|
||||
#endif //vtk_m_cont_arg_TransportTagBitField_h
|
48
vtkm/cont/arg/TypeCheckTagBitField.h
Normal file
48
vtkm/cont/arg/TypeCheckTagBitField.h
Normal file
@ -0,0 +1,48 @@
|
||||
//============================================================================
|
||||
// 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 2016 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
||||
// Copyright 2016 UT-Battelle, LLC.
|
||||
// Copyright 2016 Los Alamos National Security.
|
||||
//
|
||||
// Under the terms of Contract DE-NA0003525 with NTESS,
|
||||
// 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.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_cont_arg_TypeCheckTagBitField_h
|
||||
#define vtk_m_cont_arg_TypeCheckTagBitField_h
|
||||
|
||||
#include <vtkm/cont/arg/TypeCheck.h>
|
||||
|
||||
#include <vtkm/cont/BitField.h>
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace cont
|
||||
{
|
||||
namespace arg
|
||||
{
|
||||
|
||||
struct TypeCheckTagBitField
|
||||
{
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct TypeCheck<TypeCheckTagBitField, T> : public std::is_base_of<vtkm::cont::BitField, T>
|
||||
{
|
||||
};
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::cont::arg
|
||||
|
||||
#endif //vtk_m_cont_arg_TypeCheckTagBitField_h
|
@ -30,7 +30,7 @@
|
||||
|
||||
#include <vtkm/exec/FunctorBase.h>
|
||||
|
||||
#include <vtkm/worklet/WorkletMapField.h>
|
||||
#include <vtkm/worklet/Invoker.h>
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
@ -71,6 +71,7 @@ namespace cont
|
||||
namespace testing
|
||||
{
|
||||
|
||||
// Takes an ArrayHandleBitField as the boolean condition field
|
||||
class ConditionalMergeWorklet : public vtkm::worklet::WorkletMapField
|
||||
{
|
||||
public:
|
||||
@ -84,6 +85,26 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
// Takes a BitFieldInOut as the condition information, and reverses
|
||||
// the bits in place after performing the merge.
|
||||
class ConditionalMergeWorklet2 : public vtkm::worklet::WorkletMapField
|
||||
{
|
||||
public:
|
||||
using ControlSignature = void(BitFieldInOut bits,
|
||||
FieldIn trueVals,
|
||||
FieldIn falseVal,
|
||||
FieldOut result);
|
||||
using ExecutionSignature = _4(InputIndex, _1, _2, _3);
|
||||
using InputDomain = _2;
|
||||
|
||||
template <typename BitPortal, typename T>
|
||||
VTKM_EXEC T
|
||||
operator()(const vtkm::Id i, BitPortal& bits, const T& trueVal, const T& falseVal) const
|
||||
{
|
||||
return bits.XorBitAtomic(i, true) ? trueVal : falseVal;
|
||||
}
|
||||
};
|
||||
|
||||
/// This class has a single static member, Run, that runs all tests with the
|
||||
/// given DeviceAdapter.
|
||||
template <class DeviceAdapterTag>
|
||||
@ -588,8 +609,8 @@ struct TestingBitField
|
||||
auto falseArray = vtkm::cont::make_ArrayHandleCounting<vtkm::Id>(13, 2, NUM_BITS);
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> output;
|
||||
|
||||
vtkm::worklet::DispatcherMapField<ConditionalMergeWorklet> dispatcher;
|
||||
dispatcher.Invoke(condArray, trueArray, falseArray, output);
|
||||
vtkm::worklet::Invoker invoke;
|
||||
invoke(ConditionalMergeWorklet{}, condArray, trueArray, falseArray, output);
|
||||
|
||||
auto condVals = condArray.GetPortalConstControl();
|
||||
auto trueVals = trueArray.GetPortalConstControl();
|
||||
@ -606,6 +627,35 @@ struct TestingBitField
|
||||
}
|
||||
}
|
||||
|
||||
VTKM_CONT
|
||||
static void TestArrayInvokeWorklet2()
|
||||
{
|
||||
auto condBits = RandomBitField();
|
||||
auto trueArray = vtkm::cont::make_ArrayHandleCounting<vtkm::Id>(20, 2, NUM_BITS);
|
||||
auto falseArray = vtkm::cont::make_ArrayHandleCounting<vtkm::Id>(13, 2, NUM_BITS);
|
||||
vtkm::cont::ArrayHandle<vtkm::Id> output;
|
||||
|
||||
vtkm::worklet::Invoker invoke;
|
||||
invoke(ConditionalMergeWorklet2{}, condBits, trueArray, falseArray, output);
|
||||
|
||||
auto condVals = condBits.GetPortalConstControl();
|
||||
auto trueVals = trueArray.GetPortalConstControl();
|
||||
auto falseVals = falseArray.GetPortalConstControl();
|
||||
auto outVals = output.GetPortalConstControl();
|
||||
|
||||
VTKM_TEST_ASSERT(condVals.GetNumberOfBits() == trueVals.GetNumberOfValues());
|
||||
VTKM_TEST_ASSERT(condVals.GetNumberOfBits() == falseVals.GetNumberOfValues());
|
||||
VTKM_TEST_ASSERT(condVals.GetNumberOfBits() == outVals.GetNumberOfValues());
|
||||
|
||||
for (vtkm::Id i = 0; i < condVals.GetNumberOfBits(); ++i)
|
||||
{
|
||||
// The worklet flips the bitfield in place after choosing true/false paths
|
||||
VTKM_TEST_ASSERT(condVals.GetBit(i) == !RandomBitFromIndex(i));
|
||||
VTKM_TEST_ASSERT(outVals.Get(i) ==
|
||||
(!condVals.GetBit(i) ? trueVals.Get(i) : falseVals.Get(i)));
|
||||
}
|
||||
}
|
||||
|
||||
struct TestRunner
|
||||
{
|
||||
VTKM_CONT
|
||||
@ -617,6 +667,7 @@ struct TestingBitField
|
||||
TestingBitField::TestFinalWordMask();
|
||||
TestingBitField::TestArrayHandleBitField();
|
||||
TestingBitField::TestArrayInvokeWorklet();
|
||||
TestingBitField::TestArrayInvokeWorklet2();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -36,6 +36,7 @@
|
||||
|
||||
#include <vtkm/cont/arg/ControlSignatureTagBase.h>
|
||||
#include <vtkm/cont/arg/TransportTagAtomicArray.h>
|
||||
#include <vtkm/cont/arg/TransportTagBitField.h>
|
||||
#include <vtkm/cont/arg/TransportTagCellSetIn.h>
|
||||
#include <vtkm/cont/arg/TransportTagExecObject.h>
|
||||
#include <vtkm/cont/arg/TransportTagWholeArrayIn.h>
|
||||
@ -43,6 +44,7 @@
|
||||
#include <vtkm/cont/arg/TransportTagWholeArrayOut.h>
|
||||
#include <vtkm/cont/arg/TypeCheckTagArray.h>
|
||||
#include <vtkm/cont/arg/TypeCheckTagAtomicArray.h>
|
||||
#include <vtkm/cont/arg/TypeCheckTagBitField.h>
|
||||
#include <vtkm/cont/arg/TypeCheckTagCellSet.h>
|
||||
#include <vtkm/cont/arg/TypeCheckTagExecObject.h>
|
||||
|
||||
@ -217,6 +219,36 @@ public:
|
||||
using FetchTag = vtkm::exec::arg::FetchTagExecObject;
|
||||
};
|
||||
|
||||
/// \c ControlSignature tags for whole BitFields.
|
||||
///
|
||||
/// When a BitField is passed in to a worklet expecting this ControlSignature
|
||||
/// type, the appropriate BitPortal is generated and given to the worklet's
|
||||
/// execution.
|
||||
///
|
||||
/// Be aware that this data structure is especially prone to race conditions,
|
||||
/// so be sure to use the appropriate atomic methods when necessary.
|
||||
/// @{
|
||||
///
|
||||
struct BitFieldIn : vtkm::cont::arg::ControlSignatureTagBase
|
||||
{
|
||||
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagBitField;
|
||||
using TransportTag = vtkm::cont::arg::TransportTagBitFieldIn;
|
||||
using FetchTag = vtkm::exec::arg::FetchTagExecObject;
|
||||
};
|
||||
struct BitFieldOut : vtkm::cont::arg::ControlSignatureTagBase
|
||||
{
|
||||
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagBitField;
|
||||
using TransportTag = vtkm::cont::arg::TransportTagBitFieldOut;
|
||||
using FetchTag = vtkm::exec::arg::FetchTagExecObject;
|
||||
};
|
||||
struct BitFieldInOut : vtkm::cont::arg::ControlSignatureTagBase
|
||||
{
|
||||
using TypeCheckTag = vtkm::cont::arg::TypeCheckTagBitField;
|
||||
using TransportTag = vtkm::cont::arg::TransportTagBitFieldInOut;
|
||||
using FetchTag = vtkm::exec::arg::FetchTagExecObject;
|
||||
};
|
||||
/// @}
|
||||
|
||||
/// \c ControlSignature tag for whole input topology.
|
||||
///
|
||||
/// The \c WholeCellSetIn control signature tag specifies an \c CellSet
|
||||
|
Loading…
Reference in New Issue
Block a user