Commit c07301a9 authored by Robert Maynard's avatar Robert Maynard

Add in primitive types to vtkm (Id, Scalar, Tuple).

This includes the configure scripts to setup if you want a 32bit or
64bit build.
parent ad0bc833
//============================================================================
// 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 vtkm_TypeTraits_h
#define vtkm_TypeTraits_h
#include <vtkm/Types.h>
namespace vtkm {
/// Tag used to identify types that store real (floating-point) numbers. A
/// TypeTraits class will typedef this class to NumericTag if it stores real
/// numbers (or vectors of real numbers).
///
struct TypeTraitsRealTag {};
/// Tag used to identify types that store integer numbers. A TypeTraits class
/// will typedef this class to NumericTag if it stores integer numbers (or
/// vectors of integers).
///
struct TypeTraitsIntegerTag {};
/// Tag used to identify 0 dimensional types (scalars). Scalars can also be
/// treated like vectors when used with VectorTraits. A TypeTraits class will
/// typedef this class to DimensionalityTag.
///
struct TypeTraitsScalarTag {};
/// Tag used to identify 1 dimensional types (vectors). A TypeTraits class will
/// typedef this class to DimensionalityTag.
///
struct TypeTraitsVectorTag {};
template<typename T> struct TypeTraits;
#ifdef VTKM_DOXYGEN_ONLY
/// The TypeTraits class provides helpful compile-time information about the
/// basic types used in VTKm (and a few others for convienience). The majority
/// of TypeTraits contents are typedefs to tags that can be used to easily
/// override behavior of called functions.
///
template<typename T>
class TypeTraits {
typedef int tag_type; // Shut up, test compile.
public:
/// \brief A tag to determing whether the type is integer or real.
///
/// This tag is either TypeTraitsRealTag or TypeTraitsIntegerTag.
typedef tag_type NumericTag;
/// \brief A tag to determine whether the type has multiple components.
///
/// This tag is either TypeTraitsScalarTag or TypeTraitsVectorTag. Scalars can
/// also be treated as vectors.
typedef tag_type DimensionalityTag;
};
#endif //VTKM_DOXYGEN_ONLY
// Const types should have the same traits as their non-const counterparts.
//
template<typename T>
struct TypeTraits<const T> : TypeTraits<T>
{ };
#define VTKM_BASIC_REAL_TYPE(T) \
template<> struct TypeTraits<T> { \
typedef TypeTraitsRealTag NumericTag; \
typedef TypeTraitsScalarTag DimensionalityTag; \
}
#define VTKM_BASIC_INTEGER_TYPE(T) \
template<> struct TypeTraits<T> { \
typedef TypeTraitsIntegerTag NumericTag; \
typedef TypeTraitsScalarTag DimensionalityTag; \
}
/// Traits for basic C++ types.
///
VTKM_BASIC_REAL_TYPE(float);
VTKM_BASIC_REAL_TYPE(double);
VTKM_BASIC_INTEGER_TYPE(char);
VTKM_BASIC_INTEGER_TYPE(unsigned char);
VTKM_BASIC_INTEGER_TYPE(short);
VTKM_BASIC_INTEGER_TYPE(unsigned short);
VTKM_BASIC_INTEGER_TYPE(int);
VTKM_BASIC_INTEGER_TYPE(unsigned int);
#if VTKM_SIZE_LONG == 8
VTKM_BASIC_INTEGER_TYPE(long);
VTKM_BASIC_INTEGER_TYPE(unsigned long);
#elif VTKM_SIZE_LONG_LONG == 8
VTKM_BASIC_INTEGER_TYPE(long long);
VTKM_BASIC_INTEGER_TYPE(unsigned long long);
#else
#error No implementation for 64-bit integer traits.
#endif
#undef VTKM_BASIC_REAL_TYPE
#undef VTKM_BASIC_INTEGER_TYPE
#define VTKM_VECTOR_TYPE(T, NTag) \
template<> struct TypeTraits<T> { \
typedef NTag NumericTag; \
typedef TypeTraitsVectorTag DimensionalityTag; \
}
/// Traits for vector types.
///
VTKM_VECTOR_TYPE(vtkm::Id3, TypeTraitsIntegerTag);
VTKM_VECTOR_TYPE(vtkm::Vector2, TypeTraitsRealTag);
VTKM_VECTOR_TYPE(vtkm::Vector3, TypeTraitsRealTag);
VTKM_VECTOR_TYPE(vtkm::Vector4, TypeTraitsRealTag);
#undef VTKM_VECTOR_TYPE
/// Traits for tuples.
///
template<typename T, int Size> struct TypeTraits<vtkm::Tuple<T, Size> > {
typedef typename TypeTraits<T>::NumericTag NumericTag;
typedef TypeTraitsVectorTag DimensionalityTag;
};
} // namespace vtkm
#endif //vtkm_TypeTraits_h
This diff is collapsed.
//============================================================================
// 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 vtkm_VectorTraits_h
#define vtkm_VectorTraits_h
#include <vtkm/Types.h>
#include <boost/type_traits/remove_const.hpp>
namespace vtkm {
/// A tag for vectors that are "true" vectors (i.e. have more than one
/// component).
///
struct VectorTraitsTagMultipleComponents { };
/// A tag for vectors that a really just scalars (i.e. have only one component)
///
struct VectorTraitsTagSingleComponent { };
namespace internal {
template<int numComponents>
struct VectorTraitsMultipleComponentChooser {
typedef VectorTraitsTagMultipleComponents Type;
};
template<>
struct VectorTraitsMultipleComponentChooser<1> {
typedef VectorTraitsTagSingleComponent Type;
};
} // namespace detail
/// The VectorTraits class gives several static members that define how
/// to use a given type as a vector.
///
template<class VectorType>
struct VectorTraits
#ifdef VTKM_DOXYGEN_ONLY
{
/// Type of the components in the vector.
///
typedef typename VectorType::ComponentType ComponentType;
/// Number of components in the vector.
///
static const int NUM_COMPONENTS = VectorType::NUM_COMPONENTS;
/// A tag specifying whether this vector has multiple components (i.e. is a
/// "real" vector). This tag can be useful for creating specialized functions
/// when a vector is really just a scalar.
///
typedef typename internal::VectorTraitsMultipleComponentChooser<
NUM_COMPONENTS>::Type HasMultipleComponents;
/// Returns the value in a given component of the vector.
///
VTKM_EXEC_CONT_EXPORT static const ComponentType &GetComponent(
const typename boost::remove_const<VectorType>::type &vector,
int component);
VTKM_EXEC_CONT_EXPORT static ComponentType &GetComponent(
typename boost::remove_const<VectorType>::type &vector,
int component);
/// Changes the value in a given component of the vector.
///
VTKM_EXEC_CONT_EXPORT static void SetComponent(VectorType &vector,
int component,
ComponentType value);
/// Converts whatever type this vector is into the standard VTKm Tuple.
///
VTKM_EXEC_CONT_EXPORT
static vtkm::Tuple<ComponentType,NUM_COMPONENTS>
ToTuple(const VectorType &vector);
};
#else // VTKM_DOXYGEN_ONLY
;
#endif // VTKM_DOXYGEN_ONLY
// This partial specialization allows you to define a non-const version of
// VectorTraits and have it still work for const version.
//
template<typename T>
struct VectorTraits<const T> : VectorTraits<T>
{ };
template<typename T, int Size>
struct VectorTraits<vtkm::Tuple<T,Size> >
{
typedef vtkm::Tuple<T,Size> VectorType;
/// Type of the components in the vector.
///
typedef typename VectorType::ComponentType ComponentType;
/// Number of components in the vector.
///
static const int NUM_COMPONENTS = VectorType::NUM_COMPONENTS;
/// A tag specifying whether this vector has multiple components (i.e. is a
/// "real" vector). This tag can be useful for creating specialized functions
/// when a vector is really just a scalar.
///
typedef typename internal::VectorTraitsMultipleComponentChooser<
NUM_COMPONENTS>::Type HasMultipleComponents;
/// Returns the value in a given component of the vector.
///
VTKM_EXEC_CONT_EXPORT
static const ComponentType &GetComponent(const VectorType &vector,
int component)
{
return vector[component];
}
VTKM_EXEC_CONT_EXPORT
static ComponentType &GetComponent(VectorType &vector, int component) {
return vector[component];
}
/// Changes the value in a given component of the vector.
///
VTKM_EXEC_CONT_EXPORT static void SetComponent(VectorType &vector,
int component,
ComponentType value) {
vector[component] = value;
}
/// Converts whatever type this vector is into the standard VTKm Tuple.
///
VTKM_EXEC_CONT_EXPORT
static vtkm::Tuple<ComponentType,NUM_COMPONENTS>
ToTuple(const VectorType &vector)
{
return vector;
}
};
namespace internal {
/// Used for overriding VectorTraits for basic scalar types.
///
template<typename ScalarType>
struct VectorTraitsBasic {
typedef ScalarType ComponentType;
static const int NUM_COMPONENTS = 1;
typedef VectorTraitsTagSingleComponent HasMultipleComponents;
VTKM_EXEC_CONT_EXPORT static const ComponentType &GetComponent(
const ScalarType &vector,
int) {
return vector;
}
VTKM_EXEC_CONT_EXPORT
static ComponentType &GetComponent(ScalarType &vector, int) {
return vector;
}
VTKM_EXEC_CONT_EXPORT static void SetComponent(ScalarType &vector,
int,
ComponentType value) {
vector = value;
}
VTKM_EXEC_CONT_EXPORT
static vtkm::Tuple<ScalarType,1> ToTuple(const ScalarType &vector)
{
return vtkm::Tuple<ScalarType,1>(vector);
}
};
}
#define VTKM_BASIC_TYPE_VECTOR(type) \
template<> \
struct VectorTraits<type> \
: public vtkm::internal::VectorTraitsBasic<type> { };/* \
template<> \
struct VectorTraits<const type> \
: public vtkm::internal::VectorTraitsBasic<type> { }*/
/// Allows you to treat basic types as if they were vectors.
VTKM_BASIC_TYPE_VECTOR(float);
VTKM_BASIC_TYPE_VECTOR(double);
VTKM_BASIC_TYPE_VECTOR(char);
VTKM_BASIC_TYPE_VECTOR(unsigned char);
VTKM_BASIC_TYPE_VECTOR(short);
VTKM_BASIC_TYPE_VECTOR(unsigned short);
VTKM_BASIC_TYPE_VECTOR(int);
VTKM_BASIC_TYPE_VECTOR(unsigned int);
#if VTKM_SIZE_LONG == 8
VTKM_BASIC_TYPE_VECTOR(long);
VTKM_BASIC_TYPE_VECTOR(unsigned long);
#elif VTKM_SIZE_LONG_LONG == 8
VTKM_BASIC_TYPE_VECTOR(long long);
VTKM_BASIC_TYPE_VECTOR(unsigned long long);
#else
#error No implementation for 64-bit vector traits.
#endif
#undef VTKM_BASIC_TYPE_VECTOR
}
#endif //vtkm_VectorTraits_h
##============================================================================
## 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
ConfigureFor32.h
ConfigureFor64.h
ExportMacros.h
)
vtkm_declare_headers(${headers})
add_subdirectory(testing)
//============================================================================
// 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 vtkm_internal_Configure_h
#define vtkm_internal_Configure_h
#if !defined(VTKM_USE_DOUBLE_PRECISION) && !defined(VTKM_NO_DOUBLE_PRECISION)
#cmakedefine VTKM_USE_DOUBLE_PRECISION
#endif
#if defined(VTKM_USE_DOUBLE_PRECISION) && defined(VTKM_NO_DOUBLE_PRECISION)
# error Both VTKM_USE_DOUBLE_PRECISION and VTKM_NO_DOUBLE_PRECISION defined. Do not know what to do.
#endif
#if !defined(VTKM_USE_64BIT_IDS) && !defined(VTKM_NO_64BIT_IDS)
#cmakedefine VTKM_USE_64BIT_IDS
#endif
#if defined(VTKM_USE_64BIT_IDS) && defined(VTKM_NO_64BIT_IDS)
# error Both VTKM_USE_64BIT_IDS and VTKM_NO_64BIT_IDS defined. Do not know what to do.
#endif
#define VTKM_SIZE_FLOAT @VTKm_SIZE_FLOAT@
#define VTKM_SIZE_DOUBLE @VTKm_SIZE_DOUBLE@
#define VTKM_SIZE_INT @VTKm_SIZE_INT@
#define VTKM_SIZE_LONG @VTKm_SIZE_LONG@
#define VTKM_SIZE_LONG_LONG @VTKm_SIZE_LONG_LONG@
#ifdef VTKM_USE_DOUBLE_PRECISION
# ifndef VTKM_SIZE_SCALAR
# define VTKM_SIZE_SCALAR VTKM_SIZE_DOUBLE
# endif
# ifndef VTKM_ALIGNMENT_TWO_SCALAR
# define VTKM_ALIGNMENT_TWO_SCALAR 16
# endif
# ifndef VTKM_ALIGNMENT_FOUR_SCALAR
# define VTKM_ALIGNMENT_FOUR_SCALAR 8
# endif
#else
# ifndef VTKM_SIZE_SCALAR
# define VTKM_SIZE_SCALAR VTKM_SIZE_FLOAT
# define VTKM_ALIGNMENT_SCALAR VTKM_SIZE_SCALAR
# endif
# ifndef VTKM_ALIGNMENT_TWO_SCALAR
# define VTKM_ALIGNMENT_TWO_SCALAR 8
# endif
# ifndef VTKM_ALIGNMENT_FOUR_SCALAR
# define VTKM_ALIGNMENT_FOUR_SCALAR 16
# endif
#endif
#ifdef VTKM_USE_64BIT_IDS
# ifndef VTKM_SIZE_ID
# define VTKM_SIZE_ID 8
# endif
#else
# ifndef VTKM_SIZE_ID
# define VTKM_SIZE_ID 4
# endif
#endif
// Determine whether we will use variadic templates (a new feature in C++11).
// Currently have VARIADIC_TEMPLATE support off.
#cmakedefine VTKM_NO_VARIADIC_TEMPLATE
#if !defined(VTKM_USE_VARIADIC_TEMPLATE) && !defined(VTKM_NO_VARIADIC_TEMPLATE)
// Currently using Boost to determine support.
# include <boost/config.hpp>
# if defined(BOOST_HAS_VARIADIC_TMPL)
# define VTKM_USE_VARIADIC_TEMPLATE 1
# endif
#endif
#if defined(VTKM_USE_VARIADIC_TEMPLATE) && defined(VTKM_NO_VARIADIC_TEMPLATE)
# error Both VTKM_USE_VARIADIC_TEMPLATE and VTKM_NO_VARIADIC_TEMPLATE defined. Do not know what to do.
#endif
#endif //vtkm_internal_Configure_h
//============================================================================
// 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.
//============================================================================
//This header can be used by external application that are consuming VTKm
//to define if VTKm should be set to use 32bit data types. If you need to
//customize more of the vtkm type system, or what Device Adapters
//need to be included look at vtkm/internal/Configure.h for all defines that
//you can over-ride.
#ifdef vtkm_internal_Configure_h
# error Incorrect header order. Include this header before any other VTKm headers.
#endif
#ifndef vtkm_internal_Configure32_h
#define vtkm_internal_Configure32_h
#define VTKM_NO_DOUBLE_PRECISION
#define VTKM_NO_64BIT_IDS
#include <vtkm/internal/Configure.h>
#endif
//============================================================================
// 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.
//============================================================================
//This header can be used by external application that are consuming VTKm
//to define if VTKm should be set to use 64bit data types. If you need to
//customize more of the vtkm type system, or what Device Adapters
//need to be included look at vtkm/internal/Configure.h for all defines that
//you can over-ride.
#ifdef vtkm_internal_Configure_h
# error Incorrect header order. Include this header before any other VTKm headers.
#endif
#ifndef vtkm_internal_Configure32_h
#define vtkm_internal_Configure32_h
#define VTKM_USE_DOUBLE_PRECISION
#define VTKM_USE_64BIT_IDS
#include <vtkm/internal/Configure.h>
#endif
\ No newline at end of file
//============================================================================
// 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 vtkm_internal__ExportMacros_h
#define vtkm_internal__ExportMacros_h
/*!
* Export macros for various parts of the VTKm library.
*/
#ifdef __CUDACC__
#define VTKM_CUDA
#endif
#ifdef _OPENMP
#define VTKM_OPENMP
#endif
#ifdef VTKM_CUDA
#define VTKM_EXEC_EXPORT inline __device__
#define VTKM_EXEC_CONT_EXPORT inline __device__ __host__
#define VTKM_EXEC_CONSTANT_EXPORT __device__ __constant__
#else
#define VTKM_EXEC_EXPORT inline
#define VTKM_EXEC_CONT_EXPORT inline
#define VTKM_EXEC_CONSTANT_EXPORT
#endif
#define VTKM_CONT_EXPORT inline
/// Simple macro to identify a parameter as unused. This allows you to name a
/// parameter that is not used. There are several instances where you might
/// want to do this. For example, when using a parameter to overload or
/// template a function but do not actually use the parameter. Another example
/// is providing a specialization that does not need that parameter.
#define vtkmNotUsed(parameter_name)
// Check boost support under CUDA
#ifdef VTKM_CUDA
#if !defined(BOOST_SP_DISABLE_THREADS) && !defined(BOOST_SP_USE_SPINLOCK) && !defined(BOOST_SP_USE_PTHREADS)
#warning -------------------------------------------------------------------
#warning The CUDA compiler (nvcc) has trouble with some of the optimizations
#warning boost uses for thread saftey. To get around this, please define
#warning one of the following macros to specify the thread handling boost
#warning should use:
#warning
#warning BOOST_SP_DISABLE_THREADS
#warning BOOST_SP_USE_SPINLOCK
#warning BOOST_SP_USE_PTHREADS
#warning
#warning Failure to define one of these for a CUDA build will probably cause
#warning other annoying warnings and might even cause incorrect code. Note
#warning that specifying BOOST_SP_DISABLE_THREADS does not preclude using
#warning VTKm with a threaded device (like OpenMP). Specifying one of these
#warning modes for boost does not effect the scheduling in VTKm.
#warning -------------------------------------------------------------------
#endif
#endif
#endif //vtkm_internal__ExportMacros_h
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment