Merge branch 'exec-cmake'

This commit is contained in:
Kenneth Moreland 2014-06-10 11:36:40 -06:00
commit 5109cd40a3
9 changed files with 226 additions and 36 deletions

@ -39,3 +39,4 @@ add_subdirectory(internal)
#-----------------------------------------------------------------------------
#add the control and exec folders
add_subdirectory(cont)
add_subdirectory(exec)

@ -24,8 +24,9 @@
#include <vtkm/cont/ArrayHandleCounting.h>
#include <vtkm/cont/ArrayContainerControlBasic.h>
#include <vtkm/exec/FunctorBase.h>
#include <vtkm/exec/internal/ErrorMessageBuffer.h>
#include <vtkm/exec/internal/WorkletBase.h>
#include <algorithm>
@ -392,7 +393,7 @@ public:
// Scan Inclusive
private:
template<typename PortalType>
struct ScanKernel : vtkm::exec::internal::WorkletBase
struct ScanKernel : vtkm::exec::FunctorBase
{
PortalType Portal;
vtkm::Id Stride;
@ -465,7 +466,7 @@ public:
// Sort
private:
template<typename PortalType, typename CompareType>
struct BitonicSortMergeKernel : vtkm::exec::internal::WorkletBase
struct BitonicSortMergeKernel : vtkm::exec::FunctorBase
{
PortalType Portal;
CompareType Compare;
@ -503,7 +504,7 @@ private:
};
template<typename PortalType, typename CompareType>
struct BitonicSortCrossoverKernel : vtkm::exec::internal::WorkletBase
struct BitonicSortCrossoverKernel : vtkm::exec::FunctorBase
{
PortalType Portal;
CompareType Compare;

32
vtkm/exec/CMakeLists.txt Normal file

@ -0,0 +1,32 @@
##============================================================================
## 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(headers
FunctorBase.h
)
#-----------------------------------------------------------------------------
add_subdirectory(internal)
vtkm_declare_headers(${impl_headers} ${headers})
#-----------------------------------------------------------------------------
# add_subdirectory(testing)

67
vtkm/exec/FunctorBase.h Normal file

@ -0,0 +1,67 @@
//============================================================================
// 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_FunctorBase_h
#define vtk_m_exec_FunctorBase_h
#include <vtkm/Types.h>
#include <vtkm/exec/internal/ErrorMessageBuffer.h>
namespace vtkm {
namespace exec {
/// Base class for all functors invoked in the execution environment from a
/// call to vtkm::cont::DeviceAdapterAlgorithm::Schedule. Subclasses must
/// implement operator() const with an index argument.
///
/// This class contains a public method named RaiseError that can be called in
/// the execution environment to signal a problem.
///
class FunctorBase
{
public:
VTKM_EXEC_CONT_EXPORT
FunctorBase() { }
VTKM_EXEC_EXPORT
void RaiseError(const char *message) const
{
this->ErrorMessage.RaiseError(message);
}
/// Set the error message buffer so that running algorithms can report
/// errors. This is supposed to be set by the dispatcher. This method may be
/// replaced as the execution semantics change.
///
VTKM_CONT_EXPORT
void SetErrorMessageBuffer(
const vtkm::exec::internal::ErrorMessageBuffer &buffer)
{
this->ErrorMessage = buffer;
}
private:
vtkm::exec::internal::ErrorMessageBuffer ErrorMessage;
};
}
} // namespace vtkm::exec
#endif //vtk_m_exec_FunctorBase_h

@ -0,0 +1,28 @@
##============================================================================
## 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(headers
ErrorMessageBuffer.h
WorkletBase.h
)
vtkm_declare_headers(${headers})
add_subdirectory(testing)

@ -17,8 +17,8 @@
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#ifndef vtkm_exec_internal_ErrorMessageBuffer_h
#define vtkm_exec_internal_ErrorMessageBuffer_h
#ifndef vtk_m_exec_internal_ErrorMessageBuffer_h
#define vtk_m_exec_internal_ErrorMessageBuffer_h
#include <vtkm/Types.h>
@ -91,4 +91,4 @@ private:
}
} // namespace vtkm::exec::internal
#endif // vtkm_exec_internal_ErrorMessageBuffer_h
#endif // vtk_m_exec_internal_ErrorMessageBuffer_h

@ -17,48 +17,25 @@
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#ifndef vtkm_exec_WorkletBase_h
#define vtkm_exec_WorkletBase_h
#ifndef vtk_m_exec_internal_WorkletBase_h
#define vtk_m_exec_internal_WorkletBase_h
#include <vtkm/Types.h>
#include <vtkm/exec/internal/ErrorMessageBuffer.h>
#include <vtkm/exec/FunctorBase.h>
namespace vtkm {
namespace exec {
namespace internal {
/// Base class for all worklet classes. Worklet classes are subclasses and a
/// operator() const is added to implement an algorithm in Dax. Different
/// operator() const is added to implement an algorithm in VTK-m. Different
/// worklets have different calling semantics.
///
class WorkletBase
class WorkletBase : public FunctorBase
{
public:
VTKM_EXEC_CONT_EXPORT WorkletBase() { }
VTKM_EXEC_EXPORT void RaiseError(const char *message) const
{
this->ErrorMessage.RaiseError(message);
}
/// Set the error message buffer so that running algorithms can report
/// errors. This is supposed to be set by the dispatcher. This method may be
/// replaced as the execution semantics change.
///
VTKM_CONT_EXPORT void SetErrorMessageBuffer(
const vtkm::exec::internal::ErrorMessageBuffer &buffer)
{
this->ErrorMessage = buffer;
}
private:
vtkm::exec::internal::ErrorMessageBuffer ErrorMessage;
};
}
}
} // namespace vtkm::exec::internal
#endif //vtkm_exec_WorkletBase_h
#endif //vtk_m_exec_internal_WorkletBase_h

@ -0,0 +1,26 @@
##=============================================================================
##
## 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
UnitTestErrorMessageBuffer.cxx
)
vtkm_unit_tests(SOURCES ${unit_tests})

@ -0,0 +1,58 @@
//============================================================================
// 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/exec/internal/ErrorMessageBuffer.h>
#include <vtkm/testing/Testing.h>
#include <cstring>
namespace {
void TestErrorMessageBuffer()
{
char messageBuffer[100];
std::cout << "Testing buffer large enough for message." << std::endl;
messageBuffer[0] = '\0';
vtkm::exec::internal::ErrorMessageBuffer largeBuffer(messageBuffer, 100);
VTKM_TEST_ASSERT(!largeBuffer.IsErrorRaised(), "Message created with error.");
largeBuffer.RaiseError("Hello World");
VTKM_TEST_ASSERT(largeBuffer.IsErrorRaised(), "Error not reported.");
VTKM_TEST_ASSERT(strcmp(messageBuffer, "Hello World") == 0,
"Did not record error message.");
std::cout << "Testing truncated error message." << std::endl;
messageBuffer[0] = '\0';
vtkm::exec::internal::ErrorMessageBuffer smallBuffer(messageBuffer, 9);
VTKM_TEST_ASSERT(!smallBuffer.IsErrorRaised(), "Message created with error.");
smallBuffer.RaiseError("Hello World");
VTKM_TEST_ASSERT(smallBuffer.IsErrorRaised(), "Error not reported.");
VTKM_TEST_ASSERT(strcmp(messageBuffer, "Hello Wo") == 0,
"Did not record error message.");
}
} // anonymous namespace
int UnitTestErrorMessageBuffer(int, char *[])
{
return (vtkm::testing::Testing::Run(TestErrorMessageBuffer));
}