diff --git a/samples/usm/999_bigusm/main.cpp b/samples/usm/999_bigusm/main.cpp index 86a040c..1066e5b 100644 --- a/samples/usm/999_bigusm/main.cpp +++ b/samples/usm/999_bigusm/main.cpp @@ -20,9 +20,9 @@ // SOFTWARE. */ -#include +#include -constexpr size_t BIG_ALLOC = 5ULL * 1024 * 1024 * 1024; // 5GB +#include #define CL_MEM_FLAGS_INTEL 0x10001 #define CL_MEM_ALLOW_UNRESTRICTED_SIZE_INTEL (1 << 23) @@ -36,49 +36,34 @@ int main( int argc, char** argv ) { - bool printUsage = false; int platformIndex = 0; int deviceIndex = 0; + float numGB = 5.0f; - if( argc < 1 ) - { - printUsage = true; - } - else { - for( size_t i = 1; i < argc; i++ ) - { - if( !strcmp( argv[i], "-d" ) ) - { - if( ++i < argc ) - { - deviceIndex = strtol(argv[i], NULL, 10); - } - } - else if( !strcmp( argv[i], "-p" ) ) - { - if( ++i < argc ) - { - platformIndex = strtol(argv[i], NULL, 10); - } - } - else - { - printUsage = true; - } + popl::OptionParser op("Supported Options"); + op.add>("p", "platform", "Platform Index", platformIndex, &platformIndex); + op.add>("d", "device", "Device Index", deviceIndex, &deviceIndex); + op.add>("s", "size", "Size to Allocate (GB)", numGB, &numGB); + bool printUsage = false; + try { + op.parse(argc, argv); + } catch (std::exception& e) { + fprintf(stderr, "Error: %s\n\n", e.what()); + printUsage = true; + } + + if (printUsage || !op.unknown_options().empty() || !op.non_option_args().empty()) { + fprintf(stderr, + "Usage: bigusm [options]\n" + "%s", op.help().c_str()); + return -1; } } - if( printUsage ) - { - fprintf(stderr, - "Usage: bigusm [options]\n" - "Options:\n" - " -d: Device Index (default = 0)\n" - " -p: Platform Index (default = 0)\n" - ); - - return -1; - } + + printf("numGB = %f\n", numGB); + + size_t BIG_ALLOC = numGB * 1024 * 1024 * 1024; std::vector platforms; cl::Platform::get(&platforms);