Skip to content

Commit

Permalink
Parameterized test/3 drivers via command line args. (#667)
Browse files Browse the repository at this point in the history
Details:
- Rewrote the drivers in test/3, the Makefile, and the runme.sh script
  so that most of the important parameters, including parameter combo,
  datatype, storage combo, induced method, problem size range, dimension
  bindings, number of repeats, and alpha/beta values can be passed in
  via command line arguments. (Previously, most of these parameters were
  hard-coded into the driver source, except a few that were hard-coded
  into the Makefile.) If no argument is given for any particular option,
  it will be assigned a sane default. Either way, the values employed at
  runtime will be printed to stdout before the performance data in a
  section that is commented out with '%' characters (which is used by
  matlab and octave for comments), unless the -q option is given, in
  which case the driver will proceed quietly and output only performance
  data. Each driver also provides extensive help via the -h option, with 
  the help text tailored for the operation in question (e.g. gemm, hemm, 
  herk, etc.). In this help text, the driver reminds the user which 
  implementation it was linked to (e.g. blis, openblas, vendor, eigen).
  Thanks to Jeff Diamond for suggesting this CLI-based reimagining of
  the test/3 drivers.
- In the test/3 drivers: converted cpp macro string constants, as well
  as two string literals (for the opname and pc_str) used in each test
  driver, to global (or static) const char* strings, and replaced the
  use of strncpy() for storing the results of the command line argument
  parsing with pointer copies from the corresponding strings in argv.
  This works because the argv array is guaranteed by the C99 standard
  to persist throughout the life of the program. This new approach uses
  less storage and executes faster. Thanks to Minh Quan Ho for
  recommending this change.
- Renamed the IMP_STR cpp macro that gets defined on the command line,
  via the test/3/Makefile, to IMPL_STR.
- Updated runme.sh to set the problem size ranges for single-threaded
  and multithreaded execution independently from one another, as well as
  on a per-system basis.
- Added a 'quiet' variable to runme.sh that can easily toggle quiet mode
  for the test drivers' output.
- Very minor typecast fix in call to bli_getopt() in bli_utils.c.
- In bli_getopt(), changed the nextchar variable from being a local
  static variable to a field of the getopt_t state struct. (Not sure why
  it was ever declared static to begin with.)
- Other minor changes to bli_getopt() to accommodate the rewritten test
  drivers' command line parsing needs.
  • Loading branch information
fgvanzee authored Sep 23, 2022
1 parent 036a4f9 commit ee81efc
Show file tree
Hide file tree
Showing 12 changed files with 1,993 additions and 792 deletions.
54 changes: 36 additions & 18 deletions frame/base/bli_getopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,19 @@

static const char OPT_MARKER = '-';

//bool bli_char_is_in_str( char ch, const char* str );

void bli_getopt_init_state( int opterr, getopt_t* state )
{
state->optarg = NULL;
state->optind = 1;
state->opterr = opterr;
state->optopt = 0;
state->nextchar = NULL;
state->optarg = NULL;
state->optind = 1;
state->opterr = opterr;
state->optopt = 0;
}

int bli_getopt( int argc, const char* const * argv, const char* optstring, getopt_t* state )
{
static const char* nextchar = NULL;

const char* elem_str;
const char* optstr_char;

Expand All @@ -60,7 +61,7 @@ int bli_getopt( int argc, const char* const * argv, const char* optstring, getop
// an element of argv with more than one option character, in which
// case we need to pick up where we left off (which is the address
// contained in nextchar).
if ( nextchar == NULL )
if ( state->nextchar == NULL )
{
elem_str = argv[ state->optind ];

Expand All @@ -87,10 +88,10 @@ int bli_getopt( int argc, const char* const * argv, const char* optstring, getop
// character.

// Use the nextchar pointer as our element string.
elem_str = nextchar;
elem_str = state->nextchar;

// Reset nextchar to NULL.
nextchar = NULL;
state->nextchar = NULL;
}

// Find the first occurrence of elem_str[0] in optstring.
Expand Down Expand Up @@ -130,17 +131,24 @@ int bli_getopt( int argc, const char* const * argv, const char* optstring, getop
state->optind += 1;
return '?';
}
// If there are still more elements in argv yet to process AND
// the next one is an option, then the argument was omitted.
// If there are still more elements in argv yet to process AND the
// next one is an option marker, then the argument was omitted
// (unless the option marker is actually part of the argument,
// such as with negative numbers, e.g. -1, which is very likely
// if the char *after* the option marker is missing from optstring).
else if ( argv[ state->optind + 1 ][0] == OPT_MARKER )
{
if ( state->opterr == 1 ) fprintf( stderr, "bli_getopt(): **error**: option character '%c' is missing an argument (next element of argv is option '%c')\n", elem_str[0], argv[ state->optind + 1 ][1] );

state->optopt = *optstr_char;
state->optind += 1;
return '?';
// If the char after the option marker is present in optstring,
// then the first option argument is missing.
if ( strchr( optstring, argv[ state->optind + 1 ][1] ) != NULL )
{
if ( state->opterr == 1 ) fprintf( stderr, "bli_getopt(): **error**: option character '%c' is missing an argument (next element of argv is option '%c')\n", elem_str[0], argv[ state->optind + 1 ][1] );

state->optopt = *optstr_char;
state->optind += 1;
return '?';
}
}

// If no error was deteced above, we can safely assign optarg
// to be the next element in argv and increment optind by two.
state->optarg = argv[ state->optind + 1 ];
Expand All @@ -166,7 +174,7 @@ int bli_getopt( int argc, const char* const * argv, const char* optstring, getop
{
if ( strchr( optstring, elem_str[1] ) != NULL )
{
nextchar = &elem_str[1];
state->nextchar = &elem_str[1];
return *optstr_char;
}
}
Expand All @@ -176,3 +184,13 @@ int bli_getopt( int argc, const char* const * argv, const char* optstring, getop
return *optstr_char;
}

#if 0
bool bli_char_is_in_str( char ch, const char* str )
{
int chi = ( int )ch;

if ( strchr( str, chi ) == NULL ) return FALSE;

return TRUE;
}
#endif
1 change: 1 addition & 0 deletions frame/base/bli_getopt.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

typedef struct getopt_s
{
const char* nextchar;
const char* optarg;
int optind;
int opterr;
Expand Down
Loading

0 comments on commit ee81efc

Please sign in to comment.