update vtkm initialize flags to have 'vtkm' prefix and deprecate old flags

This commit is contained in:
nadavi 2021-03-31 23:18:33 +00:00
parent 8d7edb4615
commit 5fa8734bbc
6 changed files with 119 additions and 46 deletions

@ -133,23 +133,23 @@ function(vtkm_unit_tests)
set(enable_all_backends ${VTKm_UT_ALL_BACKENDS})
if(enable_all_backends)
set(per_device_command_line_arguments --device=serial)
set(per_device_command_line_arguments --vtkm-device=serial)
set(per_device_suffix "SERIAL")
if (VTKm_ENABLE_CUDA)
list(APPEND per_device_command_line_arguments --device=cuda)
list(APPEND per_device_command_line_arguments --vtkm-device=cuda)
list(APPEND per_device_suffix "CUDA")
#CUDA tests generally require more time because of kernel generation.
list(APPEND per_device_timeout 1500)
list(APPEND per_device_serial FALSE)
endif()
if (VTKm_ENABLE_TBB)
list(APPEND per_device_command_line_arguments --device=tbb)
list(APPEND per_device_command_line_arguments --vtkm-device=tbb)
list(APPEND per_device_suffix "TBB")
list(APPEND per_device_timeout 180)
list(APPEND per_device_serial FALSE)
endif()
if (VTKm_ENABLE_OPENMP)
list(APPEND per_device_command_line_arguments --device=openmp)
list(APPEND per_device_command_line_arguments --vtkm-device=openmp)
list(APPEND per_device_suffix "OPENMP")
list(APPEND per_device_timeout 180)
#We need to have all OpenMP tests run serially as they
@ -159,7 +159,7 @@ function(vtkm_unit_tests)
list(APPEND per_device_serial TRUE)
endif()
if (VTKm_ENABLE_KOKKOS)
list(APPEND per_device_command_line_arguments --device=kokkos)
list(APPEND per_device_command_line_arguments --vtkm-device=kokkos)
list(APPEND per_device_suffix "KOKKOS")
#may require more time because of kernel generation.
list(APPEND per_device_timeout 1500)
@ -176,7 +176,7 @@ function(vtkm_unit_tests)
endif()
# For Testing Purposes, we will set the default logging level to INFO
list(APPEND vtkm_default_test_log_level "-v" "INFO")
list(APPEND vtkm_default_test_log_level "--vtkm-log-level" "INFO")
# Add the path to the data directory so tests can find and use data files for testing
list(APPEND VTKm_UT_TEST_ARGS "--data-dir=${VTKm_SOURCE_DIR}/data/data")

@ -31,7 +31,9 @@ enum OptionIndex
UNKNOWN,
DEVICE,
LOGLEVEL, // not parsed by this parser, but by loguru
HELP
HELP,
DEPRECATED_DEVICE,
DEPRECATED_LOGLEVEL
};
struct VtkmArg : public opt::Arg
@ -170,6 +172,10 @@ VTKM_CONT
InitializeResult Initialize(int& argc, char* argv[], InitializeOptions opts)
{
InitializeResult config;
const std::string loggingFlagName = "vtkm-log-level";
const std::string loggingFlag = "--" + loggingFlagName;
const std::string loggingHelp = " " + loggingFlag +
" <#|INFO|WARNING|ERROR|FATAL|OFF> \tSpecify a log level (when logging is enabled).";
// initialize logging first -- it'll pop off the options it consumes:
if (argc == 0 || argv == nullptr)
@ -178,7 +184,7 @@ InitializeResult Initialize(int& argc, char* argv[], InitializeOptions opts)
}
else
{
vtkm::cont::InitLogging(argc, argv);
vtkm::cont::InitLogging(argc, argv, loggingFlag);
}
#ifdef VTKM_ENABLE_KOKKOS
@ -194,21 +200,33 @@ InitializeResult Initialize(int& argc, char* argv[], InitializeOptions opts)
usage.push_back(
{ DEVICE,
0,
"d",
"device",
VtkmArg::IsDevice,
" --device, -d <dev> \tForce device to dev. Omit device to list available devices." });
usage.push_back(
{ LOGLEVEL,
0,
"v",
"",
VtkmArg::Required,
" -v <#|INFO|WARNING|ERROR|FATAL|OFF> \tSpecify a log level (when logging is enabled)." });
"vtkm-device",
VtkmArg::IsDevice,
" --vtkm-device <dev> \tForce device to dev. Omit device to list available devices." });
usage.push_back({ DEPRECATED_DEVICE,
0,
"d",
"device",
VtkmArg::IsDevice,
" --device, -d <dev> \tDEPRECATED: use --vtkm-device to set the device" });
usage.push_back(
{ LOGLEVEL, 0, "", loggingFlagName.c_str(), VtkmArg::Required, loggingHelp.c_str() });
usage.push_back({ DEPRECATED_LOGLEVEL,
0,
"v",
"",
VtkmArg::Required,
" -v <#|INFO|WARNING|ERROR|FATAL|OFF> \tDEPRECATED: use --vtkm-log-level to "
"set the log level" });
if ((opts & InitializeOptions::AddHelp) != InitializeOptions::None)
{
usage.push_back(
{ HELP, 0, "h", "help", opt::Arg::None, " --help, -h \tPrint usage information." });
usage.push_back({ HELP,
0,
"h",
"vtkm-help",
opt::Arg::None,
" --vtkm-help, -h \tPrint usage information." });
}
// Required to collect unknown arguments when help is off.
usage.push_back({ UNKNOWN, 0, "", "", VtkmArg::UnknownOption, "" });
@ -243,9 +261,34 @@ InitializeResult Initialize(int& argc, char* argv[], InitializeOptions opts)
exit(0);
}
if (options[DEVICE])
if (options[DEPRECATED_LOGLEVEL])
{
auto id = vtkm::cont::make_DeviceAdapterId(options[DEVICE].arg);
VTKM_LOG_S(vtkm::cont::LogLevel::Error,
"Supplied Deprecated log level flag: "
<< std::string{ options[DEPRECATED_LOGLEVEL].name } << ", use " << loggingFlag
<< " instead.");
#ifdef VTKM_ENABLE_LOGGING
loguru::g_stderr_verbosity =
loguru::get_verbosity_from_name(options[DEPRECATED_LOGLEVEL].arg);
#endif // VTKM_ENABLE_LOGGING
}
if (options[DEVICE] || options[DEPRECATED_DEVICE])
{
const char* arg = nullptr;
if (options[DEPRECATED_DEVICE])
{
VTKM_LOG_S(vtkm::cont::LogLevel::Error,
"Supplied Deprecated device flag "
<< std::string{ options[DEPRECATED_DEVICE].name }
<< ", use --vtkm-device instead");
arg = options[DEPRECATED_DEVICE].arg;
}
if (options[DEVICE])
{
arg = options[DEVICE].arg;
}
auto id = vtkm::cont::make_DeviceAdapterId(arg);
if (id != vtkm::cont::DeviceAdapterTagAny{})
{
vtkm::cont::GetRuntimeDeviceTracker().ForceDevice(id);

@ -25,7 +25,7 @@ namespace cont
struct InitializeResult
{
/// Device passed into -d, or undefined
/// Device passed into --vtkm-device, or undefined
DeviceAdapterId Device = DeviceAdapterTagUndefined{};
/// Usage statement for arguments parsed by VTK-m
@ -39,11 +39,11 @@ enum class InitializeOptions
/// Issue an error if the device argument is not specified.
RequireDevice = 0x01,
/// If no device is specified, treat it as if the user gave --device=Any. This means that
/// If no device is specified, treat it as if the user gave --vtkm-device=Any. This means that
/// DeviceAdapterTagUndefined will never be return in the result.
DefaultAnyDevice = 0x02,
/// Add a help argument. If -h or --help is provided, prints a usage statement. Of course,
/// 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.
AddHelp = 0x04,
@ -79,14 +79,14 @@ inline InitializeOptions operator&(const InitializeOptions& lhs, const Initializ
* 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.
* - Sets the default log level to the argument provided to -v.
* - Forces usage of the device name passed to -d or --device.
* - Prints usage when -h is passed.
* - 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.
*
* The parameterless version only sets up log level names.
*
* Additional options may be supplied via the @a opts argument, such as
* requiring the -d option.
* requiring the --vtkm-device option.
*
* Results are available in the returned InitializeResult.
*

@ -104,7 +104,7 @@ namespace cont
{
VTKM_CONT
void InitLogging(int& argc, char* argv[])
void InitLogging(int& argc, char* argv[], const std::string& loggingFlag)
{
SetLogLevelName(vtkm::cont::LogLevel::Off, "Off");
SetLogLevelName(vtkm::cont::LogLevel::Fatal, "FATL");
@ -126,11 +126,12 @@ void InitLogging(int& argc, char* argv[])
// Set the default log level to warning
SetStderrLogLevel(vtkm::cont::LogLevel::Warn);
loguru::init(argc, argv);
loguru::init(argc, argv, loggingFlag.c_str());
#else // VTKM_ENABLE_LOGGING
(void)argc;
(void)argv;
(void)loggingFlag;
#endif // VTKM_ENABLE_LOGGING
// Prevent LogLevelNames from being modified (makes thread safety easier)

@ -60,7 +60,7 @@
/// (or preferably, vtkm::cont::Initialize) in an executable. This will:
/// - Set human-readable names for the log levels in the output.
/// - Allow the stderr logging level to be set at runtime by passing a
/// '-v [level]' argument to the executable.
/// '--vtkm-log-level [level]' argument to the executable.
/// - Name the main thread.
/// - Print a preamble with details of the program's startup (args, etc).
/// - Install signal handlers to automatically print stacktraces and error
@ -84,12 +84,12 @@
/// per-thread messages can be easily tracked.
///
/// By default, only Warn, Error, and Fatal messages are printed to
/// stderr. This can be changed at runtime by passing the '-v' flag to an
/// stderr. This can be changed at runtime by passing the '--vtkm-log-level' flag to an
/// executable that calls vtkm::cont::InitLogging. Alternatively, the
/// application can explicitly call vtkm::cont::SetStderrLogLevel to change the
/// verbosity. When specifying a verbosity, all log levels with enum values
/// less-than-or-equal-to the requested level are printed.
/// vtkm::cont::LogLevel::Off (or "-v Off") may be used to silence the log
/// vtkm::cont::LogLevel::Off (or "--vtkm-log-level Off") may be used to silence the log
/// completely.
///
/// The helper functions vtkm::cont::GetHumanReadableSize and
@ -356,11 +356,11 @@ enum class LogLevel
* which takes care of logging as well as other initializations.
*
* Initializes logging. Sets up custom log level and thread names. Parses any
* "-v [LogLevel]" arguments to set the stderr log level. This argument may
* "--vtkm-log-level [LogLevel]" arguments to set the stderr log level. This argument may
* be either numeric, or the 4-character string printed in the output. Note that
* loguru will consume the "-v [LogLevel]" argument and shrink the arg list.
* loguru will consume the "--vtkm-log-level [LogLevel]" argument and shrink the arg list.
*
* If the parameterless overload is used, the `-v` parsing is not used, but
* If the parameterless overload is used, the `--vtkm-log-level` parsing is not used, but
* other functionality should still work.
*
* @note This function is not threadsafe and should only be called from a single
@ -369,7 +369,7 @@ enum class LogLevel
*/
VTKM_CONT_EXPORT
VTKM_CONT
void InitLogging(int& argc, char* argv[]);
void InitLogging(int& argc, char* argv[], const std::string& loggingFlag = "--vtkm-log-level");
VTKM_CONT_EXPORT
VTKM_CONT
void InitLogging();

@ -108,7 +108,7 @@ void InitializeStandardOptions()
int argc;
char** argv;
MakeArgs(argc, argv, "--device", "Any");
MakeArgs(argc, argv, "--vtkm-device", "Any");
vtkm::cont::Initialize(argc, argv, vtkm::cont::InitializeOptions::Strict);
CheckArgs(argc, argv);
}
@ -134,15 +134,16 @@ void InitializeMixedOptions()
int argc;
char** argv;
MakeArgs(argc, argv, "--foo", "--device", "Any", "--bar", "baz");
MakeArgs(argc, argv, "--foo", "--vtkm-device", "Any", "--bar", "baz");
vtkm::cont::Initialize(argc, argv, vtkm::cont::InitializeOptions::AddHelp);
CheckArgs(argc, argv, "--foo", "--bar", "baz");
MakeArgs(argc, argv, "--foo", "-v", "OFF", "--", "--device", "Any", "--bar", "baz");
MakeArgs(
argc, argv, "--foo", "--vtkm-log-level", "OFF", "--", "--vtkm-device", "Any", "--bar", "baz");
vtkm::cont::Initialize(argc, argv);
CheckArgs(argc, argv, "--foo", "--", "--device", "Any", "--bar", "baz");
CheckArgs(argc, argv, "--foo", "--", "--vtkm-device", "Any", "--bar", "baz");
MakeArgs(argc, argv, "--device", "Any", "foo");
MakeArgs(argc, argv, "--vtkm-device", "Any", "foo");
vtkm::cont::Initialize(argc, argv);
CheckArgs(argc, argv, "foo");
}
@ -151,6 +152,29 @@ void InitializeCustomOptionsWithArgs()
{
std::cout << "Calling program has option --foo that takes arg bar." << std::endl;
int argc;
char** argv;
MakeArgs(argc, argv, "--vtkm-device", "Any", "--foo=bar", "--baz");
vtkm::cont::Initialize(argc, argv);
CheckArgs(argc, argv, "--foo=bar", "--baz");
MakeArgs(argc, argv, "--foo=bar", "--baz", "--vtkm-device", "Any");
vtkm::cont::Initialize(argc, argv);
CheckArgs(argc, argv, "--foo=bar", "--baz");
MakeArgs(argc, argv, "--vtkm-device", "Any", "--foo", "bar", "--baz");
vtkm::cont::Initialize(argc, argv);
CheckArgs(argc, argv, "--foo", "bar", "--baz");
MakeArgs(argc, argv, "--foo", "bar", "--baz", "--vtkm-device", "Any");
vtkm::cont::Initialize(argc, argv);
CheckArgs(argc, argv, "--foo", "bar", "--baz");
}
void InitializeDeprecatedOptionsWithArgs()
{
std::cout << "Calling program has option --foo that takes arg bar." << std::endl;
int argc;
char** argv;
MakeArgs(argc, argv, "--device", "Any", "--foo=bar", "--baz");
@ -161,13 +185,17 @@ void InitializeCustomOptionsWithArgs()
vtkm::cont::Initialize(argc, argv);
CheckArgs(argc, argv, "--foo=bar", "--baz");
MakeArgs(argc, argv, "--device", "Any", "--foo", "bar", "--baz");
MakeArgs(argc, argv, "-d", "Any", "--foo", "bar", "--baz");
vtkm::cont::Initialize(argc, argv);
CheckArgs(argc, argv, "--foo", "bar", "--baz");
MakeArgs(argc, argv, "--foo", "bar", "--baz", "--device", "Any");
MakeArgs(argc, argv, "--foo", "bar", "--baz", "-d", "Any");
vtkm::cont::Initialize(argc, argv);
CheckArgs(argc, argv, "--foo", "bar", "--baz");
MakeArgs(argc, argv, "--foo", "-v", "OFF", "--", "--device", "Any", "--bar", "baz");
vtkm::cont::Initialize(argc, argv);
CheckArgs(argc, argv, "--foo", "--", "--device", "Any", "--bar", "baz");
}
void InitializeWithHelp()
@ -176,7 +204,7 @@ void InitializeWithHelp()
int argc;
char** argv;
MakeArgs(argc, argv, "--help");
MakeArgs(argc, argv, "--vtkm-help");
vtkm::cont::Initialize(argc, argv, vtkm::cont::InitializeOptions::AddHelp);
VTKM_TEST_FAIL("Help argument did not exit as expected.");
@ -195,6 +223,7 @@ void DoInitializeTests()
InitializeCustomOptions();
InitializeMixedOptions();
InitializeCustomOptionsWithArgs();
InitializeDeprecatedOptionsWithArgs();
// This should be the last function called as it should exit with a zero status.
InitializeWithHelp();