2018-12-06 18:33:31 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2018-12-06 18:33:31 +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.
|
|
|
|
//============================================================================
|
|
|
|
#ifndef vtk_m_cont_Initialize_h
|
|
|
|
#define vtk_m_cont_Initialize_h
|
|
|
|
|
2019-04-03 20:28:31 +00:00
|
|
|
#include <vtkm/cont/DeviceAdapterTag.h>
|
2018-12-06 18:33:31 +00:00
|
|
|
#include <vtkm/cont/vtkm_cont_export.h>
|
|
|
|
#include <vtkm/internal/ExportMacros.h>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <type_traits>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace cont
|
|
|
|
{
|
|
|
|
|
|
|
|
struct InitializeResult
|
|
|
|
{
|
2023-07-27 20:07:19 +00:00
|
|
|
/// The device passed into `--vtkm-device` argument. If no device was specified, then
|
|
|
|
/// this value is set to `DeviceAdapterTagUndefined`. Note that if the user specifies
|
|
|
|
/// "any" device, then this value can be set to `DeviceAdapterTagAny`, which is a
|
|
|
|
/// pseudo-tag that allows any supported device.
|
2018-12-06 18:33:31 +00:00
|
|
|
DeviceAdapterId Device = DeviceAdapterTagUndefined{};
|
|
|
|
|
2023-07-27 20:07:19 +00:00
|
|
|
/// A usage statement for arguments parsed by VTK-m. If the calling code wants to print
|
|
|
|
/// a usage statement documenting the options that can be provided on the command line,
|
|
|
|
/// then this string can be added to document the options supported by VTK-m.
|
2019-03-20 15:02:56 +00:00
|
|
|
std::string Usage;
|
2018-12-06 18:33:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum class InitializeOptions
|
|
|
|
{
|
2023-07-27 20:07:19 +00:00
|
|
|
/// Placeholder used when no options are enabled. This is the value used when the third argument
|
|
|
|
/// to `vtkm::cont::Initialize` is not provided.
|
2019-03-20 15:02:56 +00:00
|
|
|
None = 0x00,
|
|
|
|
|
|
|
|
/// Issue an error if the device argument is not specified.
|
|
|
|
RequireDevice = 0x01,
|
|
|
|
|
2023-07-27 20:07:19 +00:00
|
|
|
/// If no device is specified, treat it as if the user gave `--vtkm-device=Any`. This means that
|
|
|
|
/// `DeviceAdapterTagUndefined` will never be returned in the result.
|
2019-03-20 15:02:56 +00:00
|
|
|
DefaultAnyDevice = 0x02,
|
|
|
|
|
2023-07-27 20:07:19 +00:00
|
|
|
/// Add a help argument. If `-h` or `--vtkm-help` is provided, prints a usage statement. Of course,
|
|
|
|
/// the usage statement will only print out arguments processed by VTK-m, which is why help is not
|
|
|
|
/// given by default. Alternatively, a string with usage help is returned from `vtkm::cont::Initialize`
|
|
|
|
/// so that the calling program can provide VTK-m's help in its own usage statement.
|
2019-03-20 15:02:56 +00:00
|
|
|
AddHelp = 0x04,
|
|
|
|
|
|
|
|
/// If an unknown option is encountered, the program terminates with an error and a usage
|
|
|
|
/// statement is printed. If this option is not provided, any unknown options are returned
|
2023-07-27 20:07:19 +00:00
|
|
|
/// in `argv`. If this option is used, it is a good idea to use AddHelp as well.
|
2019-03-20 15:02:56 +00:00
|
|
|
ErrorOnBadOption = 0x08,
|
|
|
|
|
|
|
|
/// If an extra argument is encountered, the program terminates with an error and a usage
|
|
|
|
/// statement is printed. If this option is not provided, any unknown arguments are returned
|
2023-07-27 20:07:19 +00:00
|
|
|
/// in `argv`.
|
2019-03-20 15:02:56 +00:00
|
|
|
ErrorOnBadArgument = 0x10,
|
|
|
|
|
|
|
|
/// If supplied, Initialize treats its own arguments as the only ones supported by the
|
|
|
|
/// application and provides an error if not followed exactly. This is a convenience
|
2023-07-27 20:07:19 +00:00
|
|
|
/// option that is a combination of `ErrorOnBadOption`, `ErrorOnBadArgument`, and `AddHelp`.
|
2019-03-20 15:02:56 +00:00
|
|
|
Strict = ErrorOnBadOption | ErrorOnBadArgument | AddHelp
|
2018-12-06 18:33:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Allow options to be used as a bitfield
|
|
|
|
inline InitializeOptions operator|(const InitializeOptions& lhs, const InitializeOptions& rhs)
|
|
|
|
{
|
|
|
|
using T = std::underlying_type<InitializeOptions>::type;
|
|
|
|
return static_cast<InitializeOptions>(static_cast<T>(lhs) | static_cast<T>(rhs));
|
|
|
|
}
|
|
|
|
inline InitializeOptions operator&(const InitializeOptions& lhs, const InitializeOptions& rhs)
|
|
|
|
{
|
|
|
|
using T = std::underlying_type<InitializeOptions>::type;
|
|
|
|
return static_cast<InitializeOptions>(static_cast<T>(lhs) & static_cast<T>(rhs));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the VTKm library, parsing arguments when provided:
|
|
|
|
* - Sets log level names when logging is configured.
|
|
|
|
* - Sets the calling thread as the main thread for logging purposes.
|
2023-07-27 20:07:19 +00:00
|
|
|
* - Sets the default log level to the argument provided to `--vtkm-log-level`.
|
|
|
|
* - Forces usage of the device name passed to `--vtkm-device`.
|
|
|
|
* - Prints usage when `-h` or `--vtkm-help` is passed.
|
2018-12-06 18:33:31 +00:00
|
|
|
*
|
|
|
|
* The parameterless version only sets up log level names.
|
|
|
|
*
|
|
|
|
* Additional options may be supplied via the @a opts argument, such as
|
2023-07-27 20:07:19 +00:00
|
|
|
* requiring the `--vtkm-device` option.
|
2018-12-06 18:33:31 +00:00
|
|
|
*
|
|
|
|
* Results are available in the returned InitializeResult.
|
|
|
|
*
|
|
|
|
* @note This method may call exit() on parse error.
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
VTKM_CONT
|
|
|
|
InitializeResult Initialize(int& argc,
|
|
|
|
char* argv[],
|
|
|
|
InitializeOptions opts = InitializeOptions::None);
|
|
|
|
VTKM_CONT_EXPORT
|
|
|
|
VTKM_CONT
|
|
|
|
InitializeResult Initialize();
|
|
|
|
/**@}*/
|
|
|
|
}
|
|
|
|
} // end namespace vtkm::cont
|
|
|
|
|
|
|
|
|
|
|
|
#endif // vtk_m_cont_Initialize_h
|