NVIDIA / nvbench

CUDA Kernel Benchmarking Library
Apache License 2.0
474 stars 63 forks source link

Allow easier customization of NVBENCH_MAIN. #162

Closed alliepiper closed 5 months ago

alliepiper commented 5 months ago

Moves as much of the guts of main into actual functions as possible.

The macros are now easier to reuse and redefine for users who want to customize main. Existing macro usage should continue to work.

alliepiper commented 5 months ago

Need to add tests for the customization points I see people using on github

alliepiper commented 5 months ago

Might pursue later, but this would break existing usecases, eg cudf currently does:


#include <nvbench/main.cuh>

#undef NVBENCH_MAIN_PARSE
#define NVBENCH_MAIN_PARSE(argc, argv)                                                             \
  nvbench::option_parser parser;                                                                   \
  std::vector<std::string> m_args;                                                                 \
  for (int i = 0; i < argc; ++i)                                                                   \
  {                                                                                                \
    std::string arg = argv[i];                                                                     \
    if (arg == "foo")                                                                              \
    {                                                                                              \
      i += 2;                                                                                      \
    }                                                                                              \
    else if (arg == "bar")                                                                         \
    {                                                                                              \
      i += 2;                                                                                      \
    }                                                                                              \
    else                                                                                           \
    {                                                                                              \
      m_args.push_back(arg);                                                                       \
    }                                                                                              \
  }                                                                                                \
  parser.parse(m_args)

NVBENCH_MAIN

Since NVBENCH_MAIN now just calls a function, the custom PARSE(...) macro is no longer used.