Commit cc497e6a authored by Kenneth Moreland's avatar Kenneth Moreland
Browse files

Remove cont/Assert.h and exec/Assert.h

These asserts are consolidated into the unified Assert.h. Also made some
minor edits to add asserts where appropriate and a little bit of
reconfiguring as found.
parent 2ddad8bc
......@@ -122,13 +122,13 @@ bool is_sorted(ForwardIt first, ForwardIt last){
// Get the value representing the `percent` percentile of the
// sorted samples using linear interpolation
vtkm::Float64 PercentileValue(const std::vector<vtkm::Float64> &samples, const vtkm::Float64 percent){
VTKM_ASSERT_CONT(!samples.empty());
VTKM_ASSERT(!samples.empty());
if (samples.size() == 1){
return samples.front();
}
VTKM_ASSERT_CONT(percent >= 0.0);
VTKM_ASSERT_CONT(percent <= 100.0);
VTKM_ASSERT_CONT(
VTKM_ASSERT(percent >= 0.0);
VTKM_ASSERT(percent <= 100.0);
VTKM_ASSERT(
vtkm::benchmarking::stats::is_sorted(samples.begin(), samples.end()));
if (percent == 100.0){
return samples.back();
......
......@@ -20,9 +20,9 @@
#ifndef vtk_m_cont_ArrayHandle_h
#define vtk_m_cont_ArrayHandle_h
#include <vtkm/Assert.h>
#include <vtkm/Types.h>
#include <vtkm/cont/Assert.h>
#include <vtkm/cont/ErrorControlBadValue.h>
#include <vtkm/cont/ErrorControlInternal.h>
#include <vtkm/cont/Storage.h>
......@@ -444,7 +444,7 @@ public:
"ArrayHandle::Shrink cannot be used to grow array.");
}
VTKM_ASSERT_CONT(this->GetNumberOfValues() == numberOfValues);
VTKM_ASSERT(this->GetNumberOfValues() == numberOfValues);
}
/// Releases any resources being used in the execution environment (that are
......@@ -640,8 +640,8 @@ public:
}
}
VTKM_ASSERT_CONT(this->Internals->ExecutionArray == NULL);
VTKM_ASSERT_CONT(!this->Internals->ExecutionArrayValid);
VTKM_ASSERT(this->Internals->ExecutionArray == NULL);
VTKM_ASSERT(!this->Internals->ExecutionArrayValid);
// Need to change some state that does not change the logical state from
// an external point of view.
InternalStruct *internals
......
......@@ -20,22 +20,21 @@
#ifndef vtk_m_cont_ArrayHandleCartesianProduct_h
#define vtk_m_cont_ArrayHandleCartesianProduct_h
#include <vtkm/Assert.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/Assert.h>
#include <vtkm/cont/ErrorControlBadAllocation.h>
namespace vtkm {
namespace exec {
namespace internal {
/// \brief An array portal that acts as a 3D cartesian product of 3 arrays.
/// for the execution environment
///
template<typename ValueType_,
typename PortalTypeFirst_,
typename PortalTypeSecond_,
typename PortalTypeThird_>
class ArrayPortalExecCartesianProduct
class ArrayPortalCartesianProduct
{
public:
typedef ValueType_ ValueType;
......@@ -46,78 +45,90 @@ public:
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC_CONT_EXPORT
ArrayPortalExecCartesianProduct()
ArrayPortalCartesianProduct()
: PortalFirst(), PortalSecond(), PortalThird()
{ } //needs to be host and device so that cuda can create lvalue of these
VTKM_CONT_EXPORT
ArrayPortalExecCartesianProduct(const PortalTypeFirst &portalfirst,
const PortalTypeSecond &portalsecond,
const PortalTypeThird &portalthird)
ArrayPortalCartesianProduct(const PortalTypeFirst &portalfirst,
const PortalTypeSecond &portalsecond,
const PortalTypeThird &portalthird)
: PortalFirst(portalfirst), PortalSecond(portalsecond), PortalThird(portalthird)
{ }
/// Copy constructor for any other ArrayPortalExecCartesianProduct with an iterator
/// Copy constructor for any other ArrayPortalCartesianProduct with an iterator
/// type that can be copied to this iterator type. This allows us to do any
/// type casting that the iterators do (like the non-const to const cast).
///
template<class OtherV, class OtherP1, class OtherP2, class OtherP3>
VTKM_CONT_EXPORT
ArrayPortalExecCartesianProduct(const ArrayPortalExecCartesianProduct<OtherV,OtherP1,OtherP2,OtherP3> &src)
ArrayPortalCartesianProduct(const ArrayPortalCartesianProduct<OtherV,OtherP1,OtherP2,OtherP3> &src)
: PortalFirst(src.GetPortalFirst()),
PortalSecond(src.GetPortalSecond()),
PortalThird(src.GetPortalThird())
{ }
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC_CONT_EXPORT
vtkm::Id GetNumberOfValues() const
{
return this->PortalFirst.GetNumberOfValues() *
this->PortalSecond.GetNumberOfValues() *
this->PortalThird.GetNumberOfValues();
return this->PortalFirst.GetNumberOfValues() *
this->PortalSecond.GetNumberOfValues() *
this->PortalThird.GetNumberOfValues();
}
VTKM_EXEC_EXPORT
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC_CONT_EXPORT
ValueType Get(vtkm::Id index) const
{
vtkm::Id dim1 = this->PortalFirst.GetNumberOfValues();
vtkm::Id dim2 = this->PortalSecond.GetNumberOfValues();
vtkm::Id dim12 = dim1*dim2;
vtkm::Id idx12 = index % dim12;
vtkm::Id i1 = idx12 % dim1;
vtkm::Id i2 = idx12 / dim1;
vtkm::Id i3 = index / dim12;
return vtkm::make_Vec(this->PortalFirst.Get(i1),
this->PortalSecond.Get(i2),
this->PortalThird.Get(i3));
VTKM_ASSERT(index >= 0);
VTKM_ASSERT(index < this->GetNumberOfValues());
vtkm::Id dim1 = this->PortalFirst.GetNumberOfValues();
vtkm::Id dim2 = this->PortalSecond.GetNumberOfValues();
vtkm::Id dim12 = dim1*dim2;
vtkm::Id idx12 = index % dim12;
vtkm::Id i1 = idx12 % dim1;
vtkm::Id i2 = idx12 / dim1;
vtkm::Id i3 = index / dim12;
return vtkm::make_Vec(this->PortalFirst.Get(i1),
this->PortalSecond.Get(i2),
this->PortalThird.Get(i3));
}
VTKM_EXEC_EXPORT
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC_CONT_EXPORT
void Set(vtkm::Id index, const ValueType &value) const
{
vtkm::Id dim1 = this->PortalFirst.GetNumberOfValues();
vtkm::Id dim2 = this->PortalSecond.GetNumberOfValues();
vtkm::Id dim12 = dim1*dim2;
vtkm::Id idx12 = index % dim12;
vtkm::Id i1 = idx12 % dim1;
vtkm::Id i2 = idx12 / dim1;
vtkm::Id i3 = index / dim12;
this->PortalFirst.Set(i1, value[0]);
this->PortalSecond.Set(i2, value[1]);
this->PortalThird.Set(i3, value[2]);
VTKM_ASSERT(index >= 0);
VTKM_ASSERT(index < this->GetNumberOfValues());
vtkm::Id dim1 = this->PortalFirst.GetNumberOfValues();
vtkm::Id dim2 = this->PortalSecond.GetNumberOfValues();
vtkm::Id dim12 = dim1*dim2;
vtkm::Id idx12 = index % dim12;
vtkm::Id i1 = idx12 % dim1;
vtkm::Id i2 = idx12 / dim1;
vtkm::Id i3 = index / dim12;
this->PortalFirst.Set(i1, value[0]);
this->PortalSecond.Set(i2, value[1]);
this->PortalThird.Set(i3, value[2]);
}
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC_CONT_EXPORT
const PortalTypeFirst &GetFirstPortal() const { return this->PortalFirst; }
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC_CONT_EXPORT
const PortalTypeSecond &GetSecondPortal() const { return this->PortalSecond; }
VTKM_SUPPRESS_EXEC_WARNINGS
VTKM_EXEC_CONT_EXPORT
const PortalTypeThird &GetThirdPortal() const { return this->PortalThird; }
......@@ -129,8 +140,7 @@ private:
};
}
}
} // namespace vtkm::exec::internal
} // namespace vtkm::internal
namespace vtkm {
......@@ -138,94 +148,6 @@ namespace cont {
namespace internal {
/// \brief An array portal that zips two portals together into a single value
/// for the control environment
template<typename ValueType_,
typename PortalTypeFirst,
typename PortalTypeSecond,
typename PortalTypeThird>
class ArrayPortalContCartesianProduct
{
public:
typedef ValueType_ ValueType;
typedef ValueType_ IteratorType;
VTKM_CONT_EXPORT
ArrayPortalContCartesianProduct(const PortalTypeFirst &portalfirst = PortalTypeFirst(),
const PortalTypeSecond &portalsecond = PortalTypeSecond(),
const PortalTypeSecond &portalthird = PortalTypeThird())
: PortalFirst(portalfirst), PortalSecond(portalsecond), PortalThird(portalthird)
{ }
/// Copy constructor for any other ArrayPortalContCartesianProduct with an iterator
/// type that can be copied to this iterator type. This allows us to do any
/// type casting that the iterators do (like the non-const to const cast).
///
template<class OtherV, class OtherP1, class OtherP2, class OtherP3>
VTKM_CONT_EXPORT
ArrayPortalContCartesianProduct(const ArrayPortalContCartesianProduct<OtherV,
OtherP1,OtherP2,OtherP3> &src)
: PortalFirst(src.GetPortalFirst()),
PortalSecond(src.GetPortalSecond()),
PortalThird(src.GetPortalThird())
{ }
VTKM_CONT_EXPORT
vtkm::Id GetNumberOfValues() const
{
return this->PortalFirst.GetNumberOfValues() *
this->PortalSecond.GetNumberOfValues() *
this->PortalThird.GetNumberOfValues();
}
VTKM_CONT_EXPORT
ValueType Get(vtkm::Id index) const
{
vtkm::Id dim1 = this->PortalFirst.GetNumberOfValues();
vtkm::Id dim2 = this->PortalSecond.GetNumberOfValues();
vtkm::Id dim12 = dim1*dim2;
vtkm::Id idx12 = index % dim12;
vtkm::Id i1 = idx12 % dim1;
vtkm::Id i2 = idx12 / dim1;
vtkm::Id i3 = index / dim12;
return vtkm::make_Vec(this->PortalFirst.Get(i1),
this->PortalSecond.Get(i2),
this->PortalThird.Get(i3));
}
VTKM_CONT_EXPORT
void Set(vtkm::Id index, const ValueType &value) const
{
vtkm::Id dim1 = this->PortalFirst.GetNumberOfValues();
vtkm::Id dim2 = this->PortalSecond.GetNumberOfValues();
vtkm::Id dim12 = dim1*dim2;
vtkm::Id idx12 = index % dim12;
vtkm::Id i1 = idx12 % dim1;
vtkm::Id i2 = idx12 / dim1;
vtkm::Id i3 = index / dim12;
this->PortalFirst.Set(i1, value[0]);
this->PortalSecond.Set(i2, value[1]);
this->PortalThird.Set(i3, value[2]);
}
VTKM_CONT_EXPORT
const PortalTypeFirst &GetFirstPortal() const { return this->PortalFirst; }
VTKM_CONT_EXPORT
const PortalTypeSecond &GetSecondPortal() const { return this->PortalSecond; }
VTKM_CONT_EXPORT
const PortalTypeSecond &GetThirdPortal() const { return this->PortalThird; }
private:
PortalTypeFirst PortalFirst;
PortalTypeSecond PortalSecond;
PortalTypeThird PortalThird;
};
template<typename FirstHandleType, typename SecondHandleType, typename ThirdHandleType>
struct StorageTagCartesianProduct { };
......@@ -258,11 +180,11 @@ class Storage<T, StorageTagCartesianProduct<FirstHandleType, SecondHandleType, T
public:
typedef T ValueType;
typedef ArrayPortalContCartesianProduct< ValueType,
typedef vtkm::internal::ArrayPortalCartesianProduct< ValueType,
typename FirstHandleType::PortalControl,
typename SecondHandleType::PortalControl,
typename ThirdHandleType::PortalControl> PortalType;
typedef ArrayPortalContCartesianProduct< ValueType,
typedef vtkm::internal::ArrayPortalCartesianProduct< ValueType,
typename FirstHandleType::PortalConstControl,
typename SecondHandleType::PortalConstControl,
typename ThirdHandleType::PortalConstControl>
......@@ -362,14 +284,14 @@ public:
typedef typename StorageType::PortalType PortalControl;
typedef typename StorageType::PortalConstType PortalConstControl;
typedef vtkm::exec::internal::ArrayPortalExecCartesianProduct<
typedef vtkm::internal::ArrayPortalCartesianProduct<
ValueType,
typename FirstHandleType::template ExecutionTypes<Device>::Portal,
typename SecondHandleType::template ExecutionTypes<Device>::Portal,
typename ThirdHandleType::template ExecutionTypes<Device>::Portal
> PortalExecution;
typedef vtkm::exec::internal::ArrayPortalExecCartesianProduct<
typedef vtkm::internal::ArrayPortalCartesianProduct<
ValueType,
typename FirstHandleType::template ExecutionTypes<Device>::PortalConst,
typename SecondHandleType::template ExecutionTypes<Device>::PortalConst,
......
......@@ -324,13 +324,13 @@ public:
VTKM_CONT_EXPORT
const FunctionInterfaceWithArrays &GetArrays() const {
VTKM_ASSERT_CONT(this->Valid);
VTKM_ASSERT(this->Valid);
return this->Arrays;
}
VTKM_CONT_EXPORT
const ComponentMapType &GetSourceComponents() const {
VTKM_ASSERT_CONT(this->Valid);
VTKM_ASSERT(this->Valid);
return this->SourceComponents;
}
......
......@@ -22,7 +22,6 @@
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/ArrayPortal.h>
#include <vtkm/cont/Assert.h>
#include <vtkm/cont/ErrorControlBadValue.h>
VTKM_THIRDPARTY_PRE_INCLUDE
......@@ -142,21 +141,21 @@ public:
VTKM_CONT_EXPORT
PortalType GetPortal()
{
VTKM_ASSERT_CONT(this->Valid);
VTKM_ASSERT(this->Valid);
return PortalType(this->SourceArray.GetPortalControl());
}
VTKM_CONT_EXPORT
PortalConstType GetPortalConst() const
{
VTKM_ASSERT_CONT(this->Valid);
VTKM_ASSERT(this->Valid);
return PortalConstType(this->SourceArray.GetPortalConstControl());
}
VTKM_CONT_EXPORT
vtkm::Id GetNumberOfValues() const
{
VTKM_ASSERT_CONT(this->Valid);
VTKM_ASSERT(this->Valid);
vtkm::Id sourceSize = this->SourceArray.GetNumberOfValues();
if(sourceSize%NUM_COMPONENTS != 0)
{
......@@ -169,14 +168,14 @@ public:
VTKM_CONT_EXPORT
void Allocate(vtkm::Id numberOfValues)
{
VTKM_ASSERT_CONT(this->Valid);
VTKM_ASSERT(this->Valid);
this->SourceArray.Allocate(numberOfValues*NUM_COMPONENTS);
}
VTKM_CONT_EXPORT
void Shrink(vtkm::Id numberOfValues)
{
VTKM_ASSERT_CONT(this->Valid);
VTKM_ASSERT(this->Valid);
this->SourceArray.Shrink(numberOfValues*NUM_COMPONENTS);
}
......@@ -193,7 +192,7 @@ public:
VTKM_CONT_EXPORT
const SourceArrayHandleType &GetSourceArray() const
{
VTKM_ASSERT_CONT(this->Valid);
VTKM_ASSERT(this->Valid);
return this->SourceArray;
}
......
......@@ -23,7 +23,6 @@
#define vtk_m_ArrayHandlePermutation_h
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/Assert.h>
#include <vtkm/cont/ErrorControlBadType.h>
#include <vtkm/cont/ErrorControlBadValue.h>
......@@ -132,16 +131,16 @@ public:
VTKM_CONT_EXPORT
ValueType Get(vtkm::Id index) const {
vtkm::Id permutedIndex = this->IndexPortal.Get(index);
VTKM_ASSERT_CONT(permutedIndex >= 0);
VTKM_ASSERT_CONT(permutedIndex < this->ValuePortal.GetNumberOfValues());
VTKM_ASSERT(permutedIndex >= 0);
VTKM_ASSERT(permutedIndex < this->ValuePortal.GetNumberOfValues());
return this->ValuePortal.Get(permutedIndex);
}
VTKM_CONT_EXPORT
ValueType Set(vtkm::Id index, const ValueType &value) const {
vtkm::Id permutedIndex = this->IndexPortal.Get(index);
VTKM_ASSERT_CONT(permutedIndex >= 0);
VTKM_ASSERT_CONT(permutedIndex < this->ValuePortal.GetNumberOfValues());
VTKM_ASSERT(permutedIndex >= 0);
VTKM_ASSERT(permutedIndex < this->ValuePortal.GetNumberOfValues());
return this->ValuePortal.Set(permutedIndex, value);
}
......@@ -186,21 +185,21 @@ public:
VTKM_CONT_EXPORT
PortalType GetPortal() {
VTKM_ASSERT_CONT(this->Valid);
VTKM_ASSERT(this->Valid);
return PortalType(this->IndexArray.GetPortalConstControl(),
this->ValueArray.GetPortalControl());
}
VTKM_CONT_EXPORT
PortalConstType GetPortalConst() const {
VTKM_ASSERT_CONT(this->Valid);
VTKM_ASSERT(this->Valid);
return PortalConstType(this->IndexArray.GetPortalConstControl(),
this->ValueArray.GetPortalConstControl());
}
VTKM_CONT_EXPORT
vtkm::Id GetNumberOfValues() const {
VTKM_ASSERT_CONT(this->Valid);
VTKM_ASSERT(this->Valid);
return this->IndexArray.GetNumberOfValues();
}
......
......@@ -23,7 +23,6 @@
#define vtk_m_cont_ArrayHandleTransform_h
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/Assert.h>
#include <vtkm/cont/ErrorControlBadType.h>
#include <vtkm/cont/ErrorControlInternal.h>
......@@ -264,21 +263,21 @@ public:
VTKM_CONT_EXPORT
PortalType GetPortal() {
VTKM_ASSERT_CONT(this->Valid);
VTKM_ASSERT(this->Valid);
return PortalType(this->Array.GetPortalControl(),
this->Functor);
}
VTKM_CONT_EXPORT
PortalConstType GetPortalConst() const {
VTKM_ASSERT_CONT(this->Valid);
VTKM_ASSERT(this->Valid);
return PortalConstType(this->Array.GetPortalConstControl(),
this->Functor);
}
VTKM_CONT_EXPORT
vtkm::Id GetNumberOfValues() const {
VTKM_ASSERT_CONT(this->Valid);
VTKM_ASSERT(this->Valid);
return this->Array.GetNumberOfValues();
}
......@@ -303,7 +302,7 @@ public:
VTKM_CONT_EXPORT
const ArrayHandleType &GetArray() const {
VTKM_ASSERT_CONT(this->Valid);
VTKM_ASSERT(this->Valid);
return this->Array;
}
......@@ -344,7 +343,7 @@ public:
VTKM_CONT_EXPORT
PortalType GetPortal() {
VTKM_ASSERT_CONT(this->Valid);
VTKM_ASSERT(this->Valid);
return PortalType(this->Array.GetPortalControl(),
this->Functor,
this->InverseFunctor);
......@@ -352,7 +351,7 @@ public:
VTKM_CONT_EXPORT
PortalConstType GetPortalConst() const {
VTKM_ASSERT_CONT(this->Valid);
VTKM_ASSERT(this->Valid);
return PortalConstType(this->Array.GetPortalConstControl(),
this->Functor,
this->InverseFunctor);
......@@ -360,7 +359,7 @@ public:
VTKM_CONT_EXPORT
vtkm::Id GetNumberOfValues() const {
VTKM_ASSERT_CONT(this->Valid);
VTKM_ASSERT(this->Valid);
return this->Array.GetNumberOfValues();
}
......@@ -383,7 +382,7 @@ public:
VTKM_CONT_EXPORT
const ArrayHandleType &GetArray() const {
VTKM_ASSERT_CONT(this->Valid);
VTKM_ASSERT(this->Valid);
return this->Array;
}
......
......@@ -219,7 +219,7 @@ public:
VTKM_CONT_EXPORT
vtkm::Id GetNumberOfValues() const {
VTKM_ASSERT_CONT(this->FirstArray.GetNumberOfValues()
VTKM_ASSERT(this->FirstArray.GetNumberOfValues()
== this->SecondArray.GetNumberOfValues());
return this->FirstArray.GetNumberOfValues();
}
......@@ -295,7 +295,7 @@ public:
VTKM_CONT_EXPORT
vtkm::Id GetNumberOfValues() const
{
VTKM_ASSERT_CONT( this->FirstArray.GetNumberOfValues()
VTKM_ASSERT( this->FirstArray.GetNumberOfValues()
== this->SecondArray.GetNumberOfValues() );
return this->FirstArray.GetNumberOfValues();
}
......
//============================================================================
// 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_Assert_h
#define vtk_m_cont_Assert_h
#include <vtkm/cont/ErrorControlAssert.h>
// Stringify macros for VTKM_ASSERT_CONT
#define __VTKM_ASSERT_CONT_STRINGIFY_2ND(s) #s
#define __VTKM_ASSERT_CONT_STRINGIFY(s) __VTKM_ASSERT_CONT_STRINGIFY_2ND(s)
/// \def VTKM_ASSERT_CONT(condition)
///
/// Asserts that \a condition resolves to true. If \a condition is false,
/// then an error is raised. This macro is meant to work in the VTKm control
/// environment and throws an ErrorControlAssert object on failure.
///
/// Like the POSIX assert macro, the check will be removed when compiling
/// in non-debug mode (specifically when NDEBUG is defined), so be prepared
/// for the possibility that the condition is never evaluated.
///
/// VTKM_ASSERT_CONT will also be removed when compiling for CUDA devices.
/// Technically speaking, this macro should not be used in methods targeted for
/// CUDA devices since they run in the execution environment and this is for
/// the control environment. However, it is often convenient to have an assert
/// in a method that is to run in either control or execution environment, so
/// we go ahead and let you declare the assert there as well.
///
#if !defined(NDEBUG) && !defined(__CUDA_ARCH__)
#define VTKM_ASSERT_CONT(condition) \
if (!(condition)) \
::vtkm::cont::Assert(condition, __FILE__, __LINE__, #condition)
#else
#define VTKM_ASSERT_CONT(condition)
#endif