diff --git a/vtkm/CMakeLists.txt b/vtkm/CMakeLists.txt index 6542c7e65..1409a771c 100644 --- a/vtkm/CMakeLists.txt +++ b/vtkm/CMakeLists.txt @@ -39,3 +39,4 @@ add_subdirectory(internal) #----------------------------------------------------------------------------- #add the control and exec folders add_subdirectory(cont) +add_subdirectory(exec) diff --git a/vtkm/cont/internal/DeviceAdapterAlgorithmGeneral.h b/vtkm/cont/internal/DeviceAdapterAlgorithmGeneral.h index d44d3c621..7e3ded845 100644 --- a/vtkm/cont/internal/DeviceAdapterAlgorithmGeneral.h +++ b/vtkm/cont/internal/DeviceAdapterAlgorithmGeneral.h @@ -24,8 +24,9 @@ #include #include +#include + #include -#include #include @@ -392,7 +393,7 @@ public: // Scan Inclusive private: template - struct ScanKernel : vtkm::exec::internal::WorkletBase + struct ScanKernel : vtkm::exec::FunctorBase { PortalType Portal; vtkm::Id Stride; @@ -465,7 +466,7 @@ public: // Sort private: template - struct BitonicSortMergeKernel : vtkm::exec::internal::WorkletBase + struct BitonicSortMergeKernel : vtkm::exec::FunctorBase { PortalType Portal; CompareType Compare; @@ -503,7 +504,7 @@ private: }; template - struct BitonicSortCrossoverKernel : vtkm::exec::internal::WorkletBase + struct BitonicSortCrossoverKernel : vtkm::exec::FunctorBase { PortalType Portal; CompareType Compare; diff --git a/vtkm/exec/CMakeLists.txt b/vtkm/exec/CMakeLists.txt new file mode 100644 index 000000000..436ca3eb3 --- /dev/null +++ b/vtkm/exec/CMakeLists.txt @@ -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) diff --git a/vtkm/exec/FunctorBase.h b/vtkm/exec/FunctorBase.h new file mode 100644 index 000000000..b458d2e96 --- /dev/null +++ b/vtkm/exec/FunctorBase.h @@ -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 + +#include + +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 diff --git a/vtkm/exec/internal/CMakeLists.txt b/vtkm/exec/internal/CMakeLists.txt new file mode 100644 index 000000000..9636472b4 --- /dev/null +++ b/vtkm/exec/internal/CMakeLists.txt @@ -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) diff --git a/vtkm/exec/internal/ErrorMessageBuffer.h b/vtkm/exec/internal/ErrorMessageBuffer.h index 4b87e28c9..02bb2ae3e 100644 --- a/vtkm/exec/internal/ErrorMessageBuffer.h +++ b/vtkm/exec/internal/ErrorMessageBuffer.h @@ -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 @@ -91,4 +91,4 @@ private: } } // namespace vtkm::exec::internal -#endif // vtkm_exec_internal_ErrorMessageBuffer_h +#endif // vtk_m_exec_internal_ErrorMessageBuffer_h diff --git a/vtkm/exec/internal/WorkletBase.h b/vtkm/exec/internal/WorkletBase.h index ab1a89c14..2b519dace 100644 --- a/vtkm/exec/internal/WorkletBase.h +++ b/vtkm/exec/internal/WorkletBase.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 - -#include +#include 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 diff --git a/vtkm/exec/internal/testing/CMakeLists.txt b/vtkm/exec/internal/testing/CMakeLists.txt new file mode 100644 index 000000000..90d268e13 --- /dev/null +++ b/vtkm/exec/internal/testing/CMakeLists.txt @@ -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}) diff --git a/vtkm/exec/internal/testing/UnitTestErrorMessageBuffer.cxx b/vtkm/exec/internal/testing/UnitTestErrorMessageBuffer.cxx new file mode 100644 index 000000000..9aca56a8b --- /dev/null +++ b/vtkm/exec/internal/testing/UnitTestErrorMessageBuffer.cxx @@ -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 + +#include +#include + +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)); +}