mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-16 17:22:55 +00:00
Add Transport class
The Transport class is responsible for moving data from the control environment to the execution environment. (Actually, it might be more accurate to say it gets the execution environment associated with a given control object.) The Transport class is templated with a tag that controls the mechanism used for the transport.
This commit is contained in:
parent
797508aa0d
commit
30558cf7ed
@ -43,6 +43,14 @@ namespace cont {
|
||||
|
||||
namespace internal {
|
||||
|
||||
/// \brief Base class of all ArrayHandle classes.
|
||||
///
|
||||
/// This is an empty class that is used to check if something is an \c
|
||||
/// ArrayHandle class (or at least something that behaves exactly like one).
|
||||
/// The \c ArrayHandle template class inherits from this.
|
||||
///
|
||||
class ArrayHandleBase { };
|
||||
|
||||
/// Checks to see if the given type and storage can form a valid array handle
|
||||
/// (some storage objects cannot support all types). This check is compatable
|
||||
/// with the Boost meta-template programming library (MPL). It contains a
|
||||
@ -59,6 +67,29 @@ struct IsValidArrayHandle {
|
||||
>::type type;
|
||||
};
|
||||
|
||||
/// Checks to see if the given object is an array handle. This check is
|
||||
/// compatiable with the Boost meta-template programming library (MPL). It
|
||||
/// contains a typedef named type that is eitehr boost::mpl::true_ or
|
||||
/// boost::mpl::false_. Both of these have a typedef named value with the
|
||||
/// respective boolean value.
|
||||
///
|
||||
/// Unlike \c IsValidArrayHandle, if an \c ArrayHandle is used with this
|
||||
/// class, then it must be created by the compiler and therefore must already
|
||||
/// be valid. Where \c IsValidArrayHandle is used when you know something is
|
||||
/// an \c ArrayHandle but you are not sure if the \c StorageTag is valid, this
|
||||
/// class is used to ensure that a given type is an \c ArrayHandle. It is
|
||||
/// used internally in the VTKM_IS_ARRAY_HANDLE macro.
|
||||
///
|
||||
template<typename T>
|
||||
struct ArrayHandleCheck
|
||||
{
|
||||
typedef typename boost::is_base_of<
|
||||
::vtkm::cont::internal::ArrayHandleBase, T>::type type;
|
||||
};
|
||||
|
||||
#define VTKM_IS_ARRAY_HANDLE(type) \
|
||||
BOOST_MPL_ASSERT(( ::vtkm::cont::internal::ArrayHandleCheck<type> ))
|
||||
|
||||
} // namespace internal
|
||||
|
||||
/// \brief Manages an array-worth of data.
|
||||
@ -85,7 +116,7 @@ struct IsValidArrayHandle {
|
||||
template<
|
||||
typename T,
|
||||
typename StorageTag_ = VTKM_DEFAULT_STORAGE_TAG>
|
||||
class ArrayHandle
|
||||
class ArrayHandle : public internal::ArrayHandleBase
|
||||
{
|
||||
private:
|
||||
typedef vtkm::cont::internal::Storage<T,StorageTag_> StorageType;
|
||||
|
@ -51,6 +51,7 @@ set(headers
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
add_subdirectory(internal)
|
||||
add_subdirectory(arg)
|
||||
|
||||
vtkm_declare_headers(${impl_headers} ${headers})
|
||||
|
||||
|
34
vtkm/cont/arg/CMakeLists.txt
Normal file
34
vtkm/cont/arg/CMakeLists.txt
Normal file
@ -0,0 +1,34 @@
|
||||
##============================================================================
|
||||
## 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 2014 Sandia Corporation.
|
||||
## Copyright 2014 UT-Battelle, LLC.
|
||||
## Copyright 2014. Los Alamos National Security
|
||||
##
|
||||
## Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
## 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.
|
||||
##============================================================================
|
||||
|
||||
include_directories(${Boost_INCLUDE_DIRS})
|
||||
|
||||
set(headers
|
||||
Transport.h
|
||||
TransportTagArrayIn.h
|
||||
TransportTagArrayOut.h
|
||||
TransportTagExecObject.h
|
||||
)
|
||||
|
||||
vtkm_declare_headers(${headers})
|
||||
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
add_subdirectory(testing)
|
79
vtkm/cont/arg/Transport.h
Normal file
79
vtkm/cont/arg/Transport.h
Normal file
@ -0,0 +1,79 @@
|
||||
//============================================================================
|
||||
// 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 2014 Sandia Corporation.
|
||||
// Copyright 2014 UT-Battelle, LLC.
|
||||
// Copyright 2014. Los Alamos National Security
|
||||
//
|
||||
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
// 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_Transport_h
|
||||
#define vtk_m_cont_arg_Transport_h
|
||||
|
||||
namespace vtkm {
|
||||
namespace cont {
|
||||
namespace arg {
|
||||
|
||||
/// \brief Class for transporting from the control to the execution environment.
|
||||
///
|
||||
/// The \c Transport class is used to transport data of a certain type from the
|
||||
/// control environment to the execution environment. It is used internally in
|
||||
/// VTK-m's dispatch mechanism.
|
||||
///
|
||||
/// \c Transport is a templated class with three arguments. The first argument
|
||||
/// is a tag declaring the mechanism of transport. The second argument is the
|
||||
/// type of data to transport. The third argument is device adapter tag for
|
||||
/// the device to move the data to.
|
||||
///
|
||||
/// There is no generic implementation of \c Transport. There are partial
|
||||
/// specializations of \c Transport for each mechanism supported. If you get a
|
||||
/// compiler error about an incomplete type for \c Transport, it means you used
|
||||
/// an invalid \c TransportTag or it is an invalid combination of data type or
|
||||
/// device adapter.
|
||||
///
|
||||
template<typename TransportTag,
|
||||
typename ContObjectType,
|
||||
typename DeviceAdapterTag>
|
||||
struct Transport
|
||||
#ifdef VTKM_DOXYGEN_ONLY
|
||||
{
|
||||
/// \brief The type used in the execution environment.
|
||||
///
|
||||
/// All \c Transport specializations are expected to declare a type named \c
|
||||
/// ExecObjectType that is the object type used in the execution environment.
|
||||
/// For example, for an \c ArrayHandle, the \c ExecObjectType is the portal
|
||||
/// used in the execution environment.
|
||||
///
|
||||
typedef typename ContObjectType::
|
||||
template ExecutionTypes<DeviceAdapterTag>::PortalConst ExecObjectType;
|
||||
|
||||
/// \brief Send data to the execution environment.
|
||||
///
|
||||
/// All \c Transport specializations are expected to have a constant
|
||||
/// parenthesis operator that takes the data in the control environment and
|
||||
/// returns an object that is accessible in the execution environment. The
|
||||
/// operator also has a second argument that is the size of the dispatch that
|
||||
/// can be used, for example, to allocate data for an output array.
|
||||
///
|
||||
VTKM_CONT_EXPORT
|
||||
ExecObjectType operator()(const ContObjectType contData, vtkm::Id size) const;
|
||||
};
|
||||
#else // VTKM_DOXYGEN_ONLY
|
||||
;
|
||||
#endif // VTKM_DOXYGEN_ONLY
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::cont::arg
|
||||
|
||||
#endif //vtk_m_cont_arg_Transport_h
|
61
vtkm/cont/arg/TransportTagArrayIn.h
Normal file
61
vtkm/cont/arg/TransportTagArrayIn.h
Normal file
@ -0,0 +1,61 @@
|
||||
//============================================================================
|
||||
// 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 2014 Sandia Corporation.
|
||||
// Copyright 2014 UT-Battelle, LLC.
|
||||
// Copyright 2014. Los Alamos National Security
|
||||
//
|
||||
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
// 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_TransportTagArrayIn_h
|
||||
#define vtk_m_cont_arg_TransportTagArrayIn_h
|
||||
|
||||
#include <vtkm/Types.h>
|
||||
|
||||
#include <vtkm/cont/ArrayHandle.h>
|
||||
|
||||
#include <vtkm/cont/arg/Transport.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace cont {
|
||||
namespace arg {
|
||||
|
||||
/// \brief \c Transport tag for input arrays.
|
||||
///
|
||||
/// \c TransportTagArrayIn is a tag used with the \c Transport class to
|
||||
/// transport \c ArrayHandle objects for input data.
|
||||
///
|
||||
struct TransportTagArrayIn { };
|
||||
|
||||
template<typename ContObjectType, typename Device>
|
||||
struct Transport<vtkm::cont::arg::TransportTagArrayIn, ContObjectType, Device>
|
||||
{
|
||||
// If you get a compile error here, it means you tried to use an object that
|
||||
// is not an array handle as an argument that is expected to be one.
|
||||
VTKM_IS_ARRAY_HANDLE(ContObjectType);
|
||||
|
||||
typedef typename ContObjectType::template ExecutionTypes<Device>::PortalConst
|
||||
ExecObjectType;
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
ExecObjectType operator()(const ContObjectType &object, vtkm::Id) const
|
||||
{
|
||||
return object.PrepareForInput(Device());
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::cont::arg
|
||||
|
||||
#endif //vtk_m_cont_arg_TransportTagArrayIn_h
|
61
vtkm/cont/arg/TransportTagArrayOut.h
Normal file
61
vtkm/cont/arg/TransportTagArrayOut.h
Normal file
@ -0,0 +1,61 @@
|
||||
//============================================================================
|
||||
// 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 2014 Sandia Corporation.
|
||||
// Copyright 2014 UT-Battelle, LLC.
|
||||
// Copyright 2014. Los Alamos National Security
|
||||
//
|
||||
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
// 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_TransportTagArrayOut_h
|
||||
#define vtk_m_cont_arg_TransportTagArrayOut_h
|
||||
|
||||
#include <vtkm/Types.h>
|
||||
|
||||
#include <vtkm/cont/ArrayHandle.h>
|
||||
|
||||
#include <vtkm/cont/arg/Transport.h>
|
||||
|
||||
namespace vtkm {
|
||||
namespace cont {
|
||||
namespace arg {
|
||||
|
||||
/// \brief \c Transport tag for output arrays.
|
||||
///
|
||||
/// \c TransportTagArrayOut is a tag used with the \c Transport class to
|
||||
/// transport \c ArrayHandle objects for output data.
|
||||
///
|
||||
struct TransportTagArrayOut { };
|
||||
|
||||
template<typename ContObjectType, typename Device>
|
||||
struct Transport<vtkm::cont::arg::TransportTagArrayOut, ContObjectType, Device>
|
||||
{
|
||||
// If you get a compile error here, it means you tried to use an object that
|
||||
// is not an array handle as an argument that is expected to be one.
|
||||
VTKM_IS_ARRAY_HANDLE(ContObjectType);
|
||||
|
||||
typedef typename ContObjectType::template ExecutionTypes<Device>::Portal
|
||||
ExecObjectType;
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
ExecObjectType operator()(ContObjectType object, vtkm::Id size) const
|
||||
{
|
||||
return object.PrepareForOutput(size, Device());
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::cont::arg
|
||||
|
||||
#endif //vtk_m_cont_arg_TransportTagArrayOut_h
|
65
vtkm/cont/arg/TransportTagExecObject.h
Normal file
65
vtkm/cont/arg/TransportTagExecObject.h
Normal file
@ -0,0 +1,65 @@
|
||||
//============================================================================
|
||||
// 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 2014 Sandia Corporation.
|
||||
// Copyright 2014 UT-Battelle, LLC.
|
||||
// Copyright 2014. Los Alamos National Security
|
||||
//
|
||||
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
// 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_TransportTagExecObject_h
|
||||
#define vtk_m_cont_arg_TransportTagExecObject_h
|
||||
|
||||
#include <vtkm/Types.h>
|
||||
|
||||
#include <vtkm/cont/arg/Transport.h>
|
||||
|
||||
#include <vtkm/exec/ExecutionObjectBase.h>
|
||||
|
||||
#include <boost/mpl/assert.hpp>
|
||||
#include <boost/type_traits/is_base_of.hpp>
|
||||
|
||||
namespace vtkm {
|
||||
namespace cont {
|
||||
namespace arg {
|
||||
|
||||
/// \brief \c Transport tag for execution objects.
|
||||
///
|
||||
/// \c TransportTagExecObject is a tag used with the \c Transport class to
|
||||
/// transport objects that work directly in the execution environment.
|
||||
///
|
||||
struct TransportTagExecObject { };
|
||||
|
||||
template<typename ContObjectType, typename Device>
|
||||
struct Transport<vtkm::cont::arg::TransportTagExecObject,ContObjectType,Device>
|
||||
{
|
||||
// If you get a compile error here, it means you tried to use an object that
|
||||
// is not an execution object as an argument that is expected to be one. All
|
||||
// execution objects are expected to inherit from
|
||||
// vtkm::exec::ExecutionObjectBase.
|
||||
BOOST_MPL_ASSERT(( boost::is_base_of<vtkm::exec::ExecutionObjectBase, ContObjectType> ));
|
||||
|
||||
typedef ContObjectType ExecObjectType;
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
ExecObjectType operator()(const ContObjectType &object, vtkm::Id) const
|
||||
{
|
||||
return object;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::cont::arg
|
||||
|
||||
#endif //vtk_m_cont_arg_TransportTagExecObject_h
|
27
vtkm/cont/arg/testing/CMakeLists.txt
Normal file
27
vtkm/cont/arg/testing/CMakeLists.txt
Normal file
@ -0,0 +1,27 @@
|
||||
##============================================================================
|
||||
## 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 2014 Sandia Corporation.
|
||||
## Copyright 2014 UT-Battelle, LLC.
|
||||
## Copyright 2014. Los Alamos National Security
|
||||
##
|
||||
## Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
## 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.
|
||||
##============================================================================
|
||||
|
||||
set(unit_tests
|
||||
UnitTestTransportArrayIn.cxx
|
||||
UnitTestTransportArrayOut.cxx
|
||||
UnitTestTransportExecObject.cxx
|
||||
)
|
||||
|
||||
vtkm_unit_tests(SOURCES ${unit_tests})
|
96
vtkm/cont/arg/testing/UnitTestTransportArrayIn.cxx
Normal file
96
vtkm/cont/arg/testing/UnitTestTransportArrayIn.cxx
Normal file
@ -0,0 +1,96 @@
|
||||
//============================================================================
|
||||
// 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 2014 Sandia Corporation.
|
||||
// Copyright 2014 UT-Battelle, LLC.
|
||||
// Copyright 2014. Los Alamos National Security
|
||||
//
|
||||
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
// 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.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/cont/arg/TransportTagArrayIn.h>
|
||||
|
||||
#include <vtkm/exec/FunctorBase.h>
|
||||
|
||||
#include <vtkm/cont/ArrayHandle.h>
|
||||
#include <vtkm/cont/DeviceAdapterSerial.h>
|
||||
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
namespace {
|
||||
|
||||
static const vtkm::Id ARRAY_SIZE = 10;
|
||||
|
||||
template<typename PortalType>
|
||||
struct TestKernel : public vtkm::exec::FunctorBase
|
||||
{
|
||||
PortalType Portal;
|
||||
|
||||
VTKM_EXEC_EXPORT
|
||||
void operator()(vtkm::Id index) const
|
||||
{
|
||||
typedef typename PortalType::ValueType ValueType;
|
||||
if (this->Portal.Get(index) != TestValue(index, ValueType()))
|
||||
{
|
||||
this->RaiseError("Got bad execution object.");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Device>
|
||||
struct TryArrayInType
|
||||
{
|
||||
template<typename T>
|
||||
void operator()(T) const
|
||||
{
|
||||
T array[ARRAY_SIZE];
|
||||
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
|
||||
{
|
||||
array[index] = TestValue(index, T());
|
||||
}
|
||||
|
||||
typedef vtkm::cont::ArrayHandle<T> ArrayHandleType;
|
||||
ArrayHandleType handle = vtkm::cont::make_ArrayHandle(array, ARRAY_SIZE);
|
||||
|
||||
typedef typename ArrayHandleType::
|
||||
template ExecutionTypes<Device>::PortalConst PortalType;
|
||||
|
||||
vtkm::cont::arg::Transport<
|
||||
vtkm::cont::arg::TransportTagArrayIn, ArrayHandleType, Device>
|
||||
transport;
|
||||
|
||||
TestKernel<PortalType> kernel;
|
||||
kernel.Portal = transport(handle, ARRAY_SIZE);
|
||||
|
||||
vtkm::cont::DeviceAdapterAlgorithm<Device>::Schedule(kernel, ARRAY_SIZE);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Device>
|
||||
void TryArrayInTransport(Device)
|
||||
{
|
||||
vtkm::testing::Testing::TryAllTypes(TryArrayInType<Device>());
|
||||
}
|
||||
|
||||
void TestArrayInTransport()
|
||||
{
|
||||
std::cout << "Trying ArrayIn transport with serial device." << std::endl;
|
||||
TryArrayInTransport(vtkm::cont::DeviceAdapterTagSerial());
|
||||
}
|
||||
|
||||
} // Anonymous namespace
|
||||
|
||||
int UnitTestTransportArrayIn(int, char *[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(TestArrayInTransport);
|
||||
}
|
92
vtkm/cont/arg/testing/UnitTestTransportArrayOut.cxx
Normal file
92
vtkm/cont/arg/testing/UnitTestTransportArrayOut.cxx
Normal file
@ -0,0 +1,92 @@
|
||||
//============================================================================
|
||||
// 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 2014 Sandia Corporation.
|
||||
// Copyright 2014 UT-Battelle, LLC.
|
||||
// Copyright 2014. Los Alamos National Security
|
||||
//
|
||||
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
// 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.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/cont/arg/TransportTagArrayOut.h>
|
||||
|
||||
#include <vtkm/exec/FunctorBase.h>
|
||||
|
||||
#include <vtkm/cont/ArrayHandle.h>
|
||||
#include <vtkm/cont/DeviceAdapterSerial.h>
|
||||
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
namespace {
|
||||
|
||||
static const vtkm::Id ARRAY_SIZE = 10;
|
||||
|
||||
template<typename PortalType>
|
||||
struct TestKernel : public vtkm::exec::FunctorBase
|
||||
{
|
||||
PortalType Portal;
|
||||
|
||||
VTKM_EXEC_EXPORT
|
||||
void operator()(vtkm::Id index) const
|
||||
{
|
||||
typedef typename PortalType::ValueType ValueType;
|
||||
this->Portal.Set(index, TestValue(index, ValueType()));
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Device>
|
||||
struct TryArrayOutType
|
||||
{
|
||||
template<typename T>
|
||||
void operator()(T) const
|
||||
{
|
||||
typedef vtkm::cont::ArrayHandle<T> ArrayHandleType;
|
||||
ArrayHandleType handle;
|
||||
|
||||
typedef typename ArrayHandleType::
|
||||
template ExecutionTypes<Device>::Portal PortalType;
|
||||
|
||||
vtkm::cont::arg::Transport<
|
||||
vtkm::cont::arg::TransportTagArrayOut, ArrayHandleType, Device>
|
||||
transport;
|
||||
|
||||
TestKernel<PortalType> kernel;
|
||||
kernel.Portal = transport(handle, ARRAY_SIZE);
|
||||
|
||||
VTKM_TEST_ASSERT(handle.GetNumberOfValues() == ARRAY_SIZE,
|
||||
"ArrayOut transport did not allocate array correctly.");
|
||||
|
||||
vtkm::cont::DeviceAdapterAlgorithm<Device>::Schedule(kernel, ARRAY_SIZE);
|
||||
|
||||
CheckPortal(handle.GetPortalConstControl());
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Device>
|
||||
void TryArrayOutTransport(Device)
|
||||
{
|
||||
vtkm::testing::Testing::TryAllTypes(TryArrayOutType<Device>());
|
||||
}
|
||||
|
||||
void TestArrayOutTransport()
|
||||
{
|
||||
std::cout << "Trying ArrayOut transport with serial device." << std::endl;
|
||||
TryArrayOutTransport(vtkm::cont::DeviceAdapterTagSerial());
|
||||
}
|
||||
|
||||
} // Anonymous namespace
|
||||
|
||||
int UnitTestTransportArrayOut(int, char *[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(TestArrayOutTransport);
|
||||
}
|
80
vtkm/cont/arg/testing/UnitTestTransportExecObject.cxx
Normal file
80
vtkm/cont/arg/testing/UnitTestTransportExecObject.cxx
Normal file
@ -0,0 +1,80 @@
|
||||
//============================================================================
|
||||
// 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 2014 Sandia Corporation.
|
||||
// Copyright 2014 UT-Battelle, LLC.
|
||||
// Copyright 2014. Los Alamos National Security
|
||||
//
|
||||
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
// 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.
|
||||
//============================================================================
|
||||
|
||||
#include <vtkm/cont/arg/TransportTagExecObject.h>
|
||||
|
||||
#include <vtkm/exec/ExecutionObjectBase.h>
|
||||
#include <vtkm/exec/FunctorBase.h>
|
||||
|
||||
#include <vtkm/cont/DeviceAdapterSerial.h>
|
||||
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
#define EXPECTED_NUMBER 42
|
||||
|
||||
namespace {
|
||||
|
||||
struct TestExecutionObject : public vtkm::exec::ExecutionObjectBase
|
||||
{
|
||||
vtkm::Int32 Number;
|
||||
};
|
||||
|
||||
struct TestKernel : public vtkm::exec::FunctorBase
|
||||
{
|
||||
TestExecutionObject Object;
|
||||
|
||||
VTKM_EXEC_EXPORT
|
||||
void operator()(vtkm::Id) const
|
||||
{
|
||||
if (this->Object.Number != EXPECTED_NUMBER)
|
||||
{
|
||||
this->RaiseError("Got bad execution object.");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Device>
|
||||
void TryExecObjectTransport(Device)
|
||||
{
|
||||
TestExecutionObject contObject;
|
||||
contObject.Number = EXPECTED_NUMBER;
|
||||
|
||||
vtkm::cont::arg::Transport<
|
||||
vtkm::cont::arg::TransportTagExecObject, TestExecutionObject, Device>
|
||||
transport;
|
||||
|
||||
TestKernel kernel;
|
||||
kernel.Object = transport(contObject, 1);
|
||||
|
||||
vtkm::cont::DeviceAdapterAlgorithm<Device>::Schedule(kernel, 1);
|
||||
}
|
||||
|
||||
void TestExecObjectTransport()
|
||||
{
|
||||
std::cout << "Trying ExecObject transport with serial device." << std::endl;
|
||||
TryExecObjectTransport(vtkm::cont::DeviceAdapterTagSerial());
|
||||
}
|
||||
|
||||
} // Anonymous namespace
|
||||
|
||||
int UnitTestTransportExecObject(int, char *[])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(TestExecObjectTransport);
|
||||
}
|
@ -19,6 +19,7 @@
|
||||
##============================================================================
|
||||
|
||||
set(headers
|
||||
ExecutionObjectBase.h
|
||||
FunctorBase.h
|
||||
)
|
||||
|
||||
|
39
vtkm/exec/ExecutionObjectBase.h
Normal file
39
vtkm/exec/ExecutionObjectBase.h
Normal file
@ -0,0 +1,39 @@
|
||||
//============================================================================
|
||||
// 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 2014 Sandia Corporation.
|
||||
// Copyright 2014 UT-Battelle, LLC.
|
||||
// Copyright 2014. Los Alamos National Security
|
||||
//
|
||||
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
// 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_exec_ExecutionObjectBase_h
|
||||
#define vtk_m_exec_ExecutionObjectBase_h
|
||||
|
||||
namespace vtkm {
|
||||
namespace exec {
|
||||
|
||||
/// Base \c ExecutionObjectBase for execution objects to inherit from so that
|
||||
/// you can use an arbitrary object as a parameter in an execution environment
|
||||
/// function. Any method you want to use on the execution side must have the
|
||||
/// VTKM_EXEC_EXPORT modifier.
|
||||
///
|
||||
class ExecutionObjectBase
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace vtkm::exec
|
||||
|
||||
#endif //vtk_m_exec_ExecutionObjectBase_h
|
Loading…
Reference in New Issue
Block a user