2014-02-10 19:53:03 +00:00
|
|
|
//============================================================================
|
|
|
|
// 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.
|
|
|
|
//
|
2017-09-20 21:33:44 +00:00
|
|
|
// Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
2014-02-10 19:53:03 +00:00
|
|
|
// Copyright 2014 UT-Battelle, LLC.
|
2015-05-21 12:09:22 +00:00
|
|
|
// Copyright 2014 Los Alamos National Security.
|
2014-02-10 19:53:03 +00:00
|
|
|
//
|
2017-09-20 21:33:44 +00:00
|
|
|
// Under the terms of Contract DE-NA0003525 with NTESS,
|
2014-02-10 19:53:03 +00:00
|
|
|
// 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.
|
|
|
|
//============================================================================
|
2014-03-07 15:19:09 +00:00
|
|
|
#ifndef vtk_m_cont_internal_DeviceAdapterTag_h
|
|
|
|
#define vtk_m_cont_internal_DeviceAdapterTag_h
|
2014-02-10 19:53:03 +00:00
|
|
|
|
2015-09-17 19:45:35 +00:00
|
|
|
#include <vtkm/StaticAssert.h>
|
2017-05-18 14:51:24 +00:00
|
|
|
#include <vtkm/Types.h>
|
2014-02-10 19:53:03 +00:00
|
|
|
#include <vtkm/internal/Configure.h>
|
|
|
|
#include <vtkm/internal/ExportMacros.h>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
#define VTKM_DEVICE_ADAPTER_ERROR -2
|
2014-06-09 22:32:02 +00:00
|
|
|
#define VTKM_DEVICE_ADAPTER_UNDEFINED -1
|
2017-05-18 14:29:41 +00:00
|
|
|
#define VTKM_DEVICE_ADAPTER_SERIAL 1
|
|
|
|
#define VTKM_DEVICE_ADAPTER_CUDA 2
|
|
|
|
#define VTKM_DEVICE_ADAPTER_TBB 3
|
2018-03-01 21:20:31 +00:00
|
|
|
#define VTKM_DEVICE_ADAPTER_OPENMP 4
|
2018-07-25 15:11:05 +00:00
|
|
|
//VTKM_DEVICE_ADAPTER_TestAlgorithmGeneral 7
|
|
|
|
#define VTKM_MAX_DEVICE_ADAPTER_ID 8
|
|
|
|
#define VTKM_DEVICE_ADAPTER_ANY 127
|
2014-02-10 19:53:03 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace cont
|
|
|
|
{
|
2014-02-10 19:53:03 +00:00
|
|
|
|
2018-07-25 15:11:05 +00:00
|
|
|
struct DeviceAdapterId
|
|
|
|
{
|
|
|
|
constexpr bool operator==(DeviceAdapterId other) const { return this->Value == other.Value; }
|
|
|
|
constexpr bool operator!=(DeviceAdapterId other) const { return this->Value != other.Value; }
|
|
|
|
constexpr bool operator<(DeviceAdapterId other) const { return this->Value < other.Value; }
|
|
|
|
|
|
|
|
constexpr bool IsValueValid() const
|
|
|
|
{
|
|
|
|
return this->Value > 0 && this->Value < VTKM_MAX_DEVICE_ADAPTER_ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
constexpr vtkm::Int8 GetValue() const { return this->Value; }
|
|
|
|
|
2018-08-24 20:38:08 +00:00
|
|
|
protected:
|
|
|
|
constexpr explicit DeviceAdapterId(vtkm::Int8 id)
|
|
|
|
: Value(id)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-07-25 15:11:05 +00:00
|
|
|
private:
|
|
|
|
vtkm::Int8 Value;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Represents when using TryExecute that the functor
|
|
|
|
// can be executed on any device instead of a specific
|
|
|
|
// one
|
|
|
|
struct DeviceAdapterIdAny : DeviceAdapterId
|
|
|
|
{
|
|
|
|
constexpr DeviceAdapterIdAny()
|
|
|
|
: DeviceAdapterId(127)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DeviceAdapterIdUndefined : DeviceAdapterId
|
|
|
|
{
|
|
|
|
constexpr DeviceAdapterIdUndefined()
|
|
|
|
: DeviceAdapterId(VTKM_DEVICE_ADAPTER_UNDEFINED)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-06-23 18:50:34 +00:00
|
|
|
using DeviceAdapterNameType = std::string;
|
2014-02-10 19:53:03 +00:00
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename DeviceAdapter>
|
2014-02-10 19:53:03 +00:00
|
|
|
struct DeviceAdapterTraits;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Creates a tag named vtkm::cont::DeviceAdapterTagName and associated MPL
|
|
|
|
/// structures to use this tag. Always use this macro (in the base namespace)
|
|
|
|
/// when creating a device adapter.
|
2017-05-18 14:29:41 +00:00
|
|
|
#define VTKM_VALID_DEVICE_ADAPTER(Name, Id) \
|
|
|
|
namespace vtkm \
|
|
|
|
{ \
|
|
|
|
namespace cont \
|
|
|
|
{ \
|
2018-07-25 15:11:05 +00:00
|
|
|
struct VTKM_ALWAYS_EXPORT DeviceAdapterTag##Name : DeviceAdapterId \
|
2017-05-18 14:29:41 +00:00
|
|
|
{ \
|
2018-07-25 15:11:05 +00:00
|
|
|
constexpr DeviceAdapterTag##Name() \
|
|
|
|
: DeviceAdapterId(Id) \
|
|
|
|
{ \
|
|
|
|
} \
|
|
|
|
static constexpr bool IsEnabled = true; \
|
2017-05-18 14:29:41 +00:00
|
|
|
}; \
|
|
|
|
template <> \
|
|
|
|
struct DeviceAdapterTraits<vtkm::cont::DeviceAdapterTag##Name> \
|
|
|
|
{ \
|
|
|
|
static DeviceAdapterNameType GetName() { return DeviceAdapterNameType(#Name); } \
|
|
|
|
}; \
|
|
|
|
} \
|
2014-02-10 19:53:03 +00:00
|
|
|
}
|
|
|
|
|
2015-09-16 20:59:28 +00:00
|
|
|
/// Marks the tag named vtkm::cont::DeviceAdapterTagName and associated
|
2015-12-16 16:18:52 +00:00
|
|
|
/// structures as invalid to use. Always use this macro (in the base namespace)
|
2015-09-16 20:59:28 +00:00
|
|
|
/// when creating a device adapter.
|
2017-05-18 14:29:41 +00:00
|
|
|
#define VTKM_INVALID_DEVICE_ADAPTER(Name, Id) \
|
|
|
|
namespace vtkm \
|
|
|
|
{ \
|
|
|
|
namespace cont \
|
|
|
|
{ \
|
2018-07-25 15:11:05 +00:00
|
|
|
struct VTKM_ALWAYS_EXPORT DeviceAdapterTag##Name : DeviceAdapterId \
|
2017-05-18 14:29:41 +00:00
|
|
|
{ \
|
2018-07-25 15:11:05 +00:00
|
|
|
constexpr DeviceAdapterTag##Name() \
|
|
|
|
: DeviceAdapterId(Id) \
|
|
|
|
{ \
|
|
|
|
} \
|
|
|
|
static constexpr bool IsEnabled = false; \
|
2017-05-18 14:29:41 +00:00
|
|
|
}; \
|
|
|
|
template <> \
|
|
|
|
struct DeviceAdapterTraits<vtkm::cont::DeviceAdapterTag##Name> \
|
|
|
|
{ \
|
|
|
|
static DeviceAdapterNameType GetName() { return DeviceAdapterNameType(#Name); } \
|
|
|
|
}; \
|
|
|
|
} \
|
2015-09-16 20:59:28 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 19:53:03 +00:00
|
|
|
/// Checks that the argument is a proper device adapter tag. This is a handy
|
|
|
|
/// concept check for functions and classes to make sure that a template
|
|
|
|
/// argument is actually a device adapter tag. (You can get weird errors
|
|
|
|
/// elsewhere in the code when a mistake is made.)
|
2014-10-22 13:24:04 +00:00
|
|
|
///
|
2017-05-18 14:29:41 +00:00
|
|
|
#define VTKM_IS_DEVICE_ADAPTER_TAG(tag) \
|
2018-07-25 15:11:05 +00:00
|
|
|
static_assert(std::is_base_of<vtkm::cont::DeviceAdapterId, tag>::value && \
|
|
|
|
!std::is_same<vtkm::cont::DeviceAdapterId, tag>::value, \
|
|
|
|
"Provided type is not a valid VTK-m device adapter tag.")
|
2014-02-10 19:53:03 +00:00
|
|
|
|
2014-06-11 16:43:36 +00:00
|
|
|
#endif //vtk_m_cont_internal_DeviceAdapterTag_h
|