2014-02-10 19:53:03 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2014-02-10 19:53:03 +00:00
|
|
|
// 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.
|
|
|
|
//============================================================================
|
2019-04-03 20:28:31 +00:00
|
|
|
#ifndef vtk_m_cont_DeviceAdapterTag_h
|
|
|
|
#define vtk_m_cont_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>
|
|
|
|
|
2018-08-28 21:14:49 +00:00
|
|
|
#include <vtkm/cont/vtkm_cont_export.h>
|
|
|
|
|
2014-02-10 19:53:03 +00:00
|
|
|
#include <string>
|
|
|
|
|
2019-04-09 13:52:53 +00:00
|
|
|
#ifdef VTKM_DEVICE_ADAPTER
|
|
|
|
// Rather than use defines to specify the default device adapter
|
|
|
|
// VTK-m now builds for all device adapters and uses runtime controls
|
|
|
|
// to determine where execution occurs
|
|
|
|
#error The VTKM_DEVICE_ADAPTER define is no longer obeyed and needs to be removed
|
|
|
|
#endif
|
|
|
|
#ifdef VTKM_DEFAULT_DEVICE_ADAPTER_TAG
|
|
|
|
// Rather than use device adapter tag that had no shared parent
|
|
|
|
// VTK-m now uses a runtime device adapter implementation that
|
|
|
|
// allows for runtime execution selection of what device to execute on
|
|
|
|
#error The VTKM_DEFAULT_DEVICE_ADAPTER_TAG define is no longer required and needs to be removed
|
|
|
|
#endif
|
|
|
|
|
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
|
2020-06-16 12:54:01 +00:00
|
|
|
#define VTKM_DEVICE_ADAPTER_KOKKOS 5
|
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-08-28 21:14:49 +00:00
|
|
|
using DeviceAdapterNameType = std::string;
|
|
|
|
|
2023-07-27 20:07:19 +00:00
|
|
|
/// @brief An object used to specify a device.
|
|
|
|
///
|
|
|
|
/// `vtkm::cont::DeviceAdapterId` can be used to specify a device to use when
|
|
|
|
/// executing some code. Each `DeviceAdapterTag` object inherits from
|
|
|
|
/// `vtkm::cont::DeviceAdapterId`. Functions can accept a `vtkm::cont::DeviceAdapterId`
|
|
|
|
/// object rather than a templated tag to select a device adapter at runtime.
|
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; }
|
|
|
|
|
2023-07-27 20:07:19 +00:00
|
|
|
/// @brief Return whether this object represents a valid type of device.
|
|
|
|
///
|
|
|
|
/// This method will return true if the id represents a specific, valid device.
|
|
|
|
/// It will return true even if the device is disabled in by the runtime tracker
|
|
|
|
/// or if the device is not supported by the VTK-m build configuration.
|
|
|
|
///
|
|
|
|
/// It should be noted that this method return false for tags that are not specific
|
|
|
|
/// devices. This includes `vtkm::cont::DeviceAdapterTagAny` and
|
|
|
|
/// `vtkm::cont::DeviceAdapterTagUndefined`.
|
2018-07-25 15:11:05 +00:00
|
|
|
constexpr bool IsValueValid() const
|
|
|
|
{
|
|
|
|
return this->Value > 0 && this->Value < VTKM_MAX_DEVICE_ADAPTER_ID;
|
|
|
|
}
|
|
|
|
|
2023-07-27 20:07:19 +00:00
|
|
|
/// @brief Returns the numeric value of the index.
|
2018-07-25 15:11:05 +00:00
|
|
|
constexpr vtkm::Int8 GetValue() const { return this->Value; }
|
|
|
|
|
2023-07-27 20:07:19 +00:00
|
|
|
/// @brief Return a name representing the device.
|
|
|
|
///
|
|
|
|
/// The string returned from this method is stored in a type named
|
|
|
|
/// `vtkm::cont::DeviceAdapterNameType`, which is currently aliased to
|
|
|
|
/// `std::string`. The device adapter name is useful for printing information
|
|
|
|
/// about a device being used.
|
2018-08-28 21:14:49 +00:00
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
DeviceAdapterNameType GetName() const;
|
|
|
|
|
2018-08-24 20:38:08 +00:00
|
|
|
protected:
|
2018-10-03 17:42:34 +00:00
|
|
|
friend DeviceAdapterId make_DeviceAdapterId(vtkm::Int8 id);
|
|
|
|
|
2018-08-24 20:38:08 +00:00
|
|
|
constexpr explicit DeviceAdapterId(vtkm::Int8 id)
|
|
|
|
: Value(id)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-07-25 15:11:05 +00:00
|
|
|
private:
|
|
|
|
vtkm::Int8 Value;
|
|
|
|
};
|
|
|
|
|
2019-01-02 16:01:00 +00:00
|
|
|
/// Construct a device adapter id from a runtime string
|
|
|
|
/// The string is case-insensitive. So CUDA will be selected with 'cuda', 'Cuda', or 'CUDA'.
|
2018-12-06 18:33:31 +00:00
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
DeviceAdapterId make_DeviceAdapterId(const DeviceAdapterNameType& name);
|
2018-10-17 19:17:29 +00:00
|
|
|
|
2019-01-02 16:01:00 +00:00
|
|
|
/// Construct a device adapter id a vtkm::Int8.
|
|
|
|
/// The mapping of integer value to devices are:
|
|
|
|
///
|
|
|
|
/// DeviceAdapterTagSerial == 1
|
|
|
|
/// DeviceAdapterTagCuda == 2
|
|
|
|
/// DeviceAdapterTagTBB == 3
|
|
|
|
/// DeviceAdapterTagOpenMP == 4
|
2020-06-16 12:54:01 +00:00
|
|
|
/// DeviceAdapterTagKokkos == 5
|
2019-01-02 16:01:00 +00:00
|
|
|
///
|
2018-10-04 12:42:29 +00:00
|
|
|
inline DeviceAdapterId make_DeviceAdapterId(vtkm::Int8 id)
|
2018-10-03 17:42:34 +00:00
|
|
|
{
|
|
|
|
return DeviceAdapterId(id);
|
|
|
|
}
|
|
|
|
|
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.
|
2020-08-17 14:18:24 +00:00
|
|
|
#define VTKM_VALID_DEVICE_ADAPTER(Name, Id) \
|
|
|
|
namespace vtkm \
|
|
|
|
{ \
|
|
|
|
namespace cont \
|
|
|
|
{ \
|
|
|
|
struct VTKM_ALWAYS_EXPORT DeviceAdapterTag##Name : DeviceAdapterId \
|
|
|
|
{ \
|
|
|
|
constexpr DeviceAdapterTag##Name() \
|
|
|
|
: DeviceAdapterId(Id) \
|
|
|
|
{ \
|
|
|
|
} \
|
|
|
|
static constexpr bool IsEnabled = true; \
|
|
|
|
}; \
|
|
|
|
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.
|
2020-08-17 14:18:24 +00:00
|
|
|
#define VTKM_INVALID_DEVICE_ADAPTER(Name, Id) \
|
|
|
|
namespace vtkm \
|
|
|
|
{ \
|
|
|
|
namespace cont \
|
|
|
|
{ \
|
|
|
|
struct VTKM_ALWAYS_EXPORT DeviceAdapterTag##Name : DeviceAdapterId \
|
|
|
|
{ \
|
|
|
|
constexpr DeviceAdapterTag##Name() \
|
|
|
|
: DeviceAdapterId(Id) \
|
|
|
|
{ \
|
|
|
|
} \
|
|
|
|
static constexpr bool IsEnabled = false; \
|
|
|
|
}; \
|
|
|
|
template <> \
|
|
|
|
struct DeviceAdapterTraits<vtkm::cont::DeviceAdapterTag##Name> \
|
|
|
|
{ \
|
|
|
|
static DeviceAdapterNameType GetName() { return DeviceAdapterNameType(#Name); } \
|
|
|
|
}; \
|
|
|
|
} \
|
2015-09-16 20:59:28 +00:00
|
|
|
}
|
|
|
|
|
2023-07-27 20:07:19 +00:00
|
|
|
/// @struct vtkm::cont::DeviceAdapterTagAny
|
|
|
|
/// @brief Tag for a device adapter used to specify that any device may be used
|
|
|
|
/// for an operation.
|
|
|
|
///
|
|
|
|
/// In practice this is limited to devices that are currently available.
|
|
|
|
|
2018-08-28 21:52:35 +00:00
|
|
|
VTKM_VALID_DEVICE_ADAPTER(Any, VTKM_DEVICE_ADAPTER_ANY)
|
|
|
|
|
2023-07-27 20:07:19 +00:00
|
|
|
/// @struct vtkm::cont::DeviceAdapterTagUndefined
|
|
|
|
/// @brief Tag for a device adapter used to avoid specifying a device.
|
|
|
|
///
|
|
|
|
/// Useful as a placeholder when a device can be specified but none is given.
|
|
|
|
|
2018-08-28 21:52:35 +00:00
|
|
|
VTKM_INVALID_DEVICE_ADAPTER(Undefined, VTKM_DEVICE_ADAPTER_UNDEFINED)
|
|
|
|
|
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
|
|
|
///
|
2020-08-17 14:18:24 +00:00
|
|
|
#define VTKM_IS_DEVICE_ADAPTER_TAG(tag) \
|
|
|
|
static_assert(std::is_base_of<vtkm::cont::DeviceAdapterId, tag>::value && \
|
|
|
|
!std::is_same<vtkm::cont::DeviceAdapterId, tag>::value, \
|
2018-07-25 15:11:05 +00:00
|
|
|
"Provided type is not a valid VTK-m device adapter tag.")
|
2014-02-10 19:53:03 +00:00
|
|
|
|
2019-04-03 20:28:31 +00:00
|
|
|
#endif //vtk_m_cont_DeviceAdapterTag_h
|