Skip to content

Commit

Permalink
fix the handling of gibbon runtime args and usage help
Browse files Browse the repository at this point in the history
  • Loading branch information
vidsinghal committed Oct 8, 2023
1 parent 209a90d commit b1a5c10
Showing 1 changed file with 52 additions and 17 deletions.
69 changes: 52 additions & 17 deletions gibbon-rts/rts-c/gibbon_rts.c
Original file line number Diff line number Diff line change
Expand Up @@ -1796,13 +1796,19 @@ void gib_show_usage(char** argv)
printf("\n");
printf("This binary was generated by the Gibbon compiler.\n");
printf("\n");
printf("Usage: %s [OPTS] [size] [iters]\n", argv[0]);
printf("Usage: %s [OPTIONS...]\n", argv[0]);

printf("\n");
printf("Options:\n");
printf(" --buffer-size <bytes> Set the buffer size (default %" PRId64 ").\n", gib_global_biginf_init_chunk_size);
printf(" --bench-input <path> Set the input file read for benchmarking. Applies only\n");
printf(" IF the program was *compiled* with --bench-fun. \n");
printf(" --biginf-buffer-size <bytes> Set the buffer size (default %" PRId64 ").\n", gib_global_biginf_init_chunk_size);
printf(" --inf-buffer-size <bytes> Set the buffer size (default %" PRId64 ").\n", gib_global_inf_init_chunk_size);
printf(" --bench-input <path> Set the input file read for benchmarking. Applies only\n");
printf(" IF the program was *compiled* with --bench-fun. \n");
printf("\n");
printf(" --array-input <path> Set the file from which to read the array input.\n");
printf(" --array-input-length <int> Set the size of the array input file.\n");
printf(" --iterate <int> Set the number of iterations to perform (default 1).\n");
printf(" --size-param <int> Set the size param (default 1).\n");
return;
}

Expand Down Expand Up @@ -1914,7 +1920,7 @@ int gib_init(int argc, char **argv)
}
#endif

int got_numargs = 0; // How many numeric arguments have we got.
int got_numargs = argc; // How many numeric arguments have we got.

int i;
for (i = 1; i < argc; ++i)
Expand All @@ -1923,13 +1929,21 @@ int gib_init(int argc, char **argv)
gib_show_usage(argv);
exit(0);
}
else if (strcmp(argv[i], "--biginf-buffer-size") == 0 && i < argc - 1)
{
else if (strcmp(argv[i], "--biginf-buffer-size") == 0 && i < argc - 1){
if (i+1 >= argc) {
fprintf(stderr, "Not enough arguments after --biginf-buffer-size, expected <int>.\n");
gib_show_usage(argv);
exit(1);
}
gib_global_biginf_init_chunk_size = atoll(argv[i + 1]);
i++;
}
else if (strcmp(argv[i], "--inf-buffer-size") == 0 && i < argc - 1)
{
else if (strcmp(argv[i], "--inf-buffer-size") == 0 && i < argc - 1){
if (i+1 >= argc) {
fprintf(stderr, "Not enough arguments after --inf-buffer-size, expected <int>.\n");
gib_show_usage(argv);
exit(1);
}
gib_global_inf_init_chunk_size = atoll(argv[i + 1]);
i++;
}
Expand All @@ -1952,28 +1966,49 @@ int gib_init(int argc, char **argv)
i++;
}
else if (strcmp(argv[i], "--array-input-length") == 0 && i < argc - 1) {
if (i+1 >= argc) {
fprintf(stderr, "Not enough arguments after --array-input-length, expected <int>.\n");
gib_show_usage(argv);
exit(1);
}
gib_global_arrayfile_length_param = atoll(argv[i+1]);
i++;
}
else if (strcmp(argv[i], "--bench-prog") == 0 && i < argc - 1) {
if (i+1 >= argc) {
fprintf(stderr, "Not enough arguments after --bench-prog, expected <int>.\n");
gib_show_usage(argv);
exit(1);
}
int len = strlen(argv[i+1]);
gib_global_bench_prog_param = (char*) gib_alloc((len+1)*sizeof(char));
strncpy(gib_global_bench_prog_param,argv[i+1],len);
i++;
}
else if ((strcmp(argv[i], "--iterate") == 0)) {
if (i+1 >= argc) {
fprintf(stderr, "Not enough arguments after --iterate, expected <int>.\n");
gib_show_usage(argv);
exit(1);
}
gib_global_iters_param = atoll(argv[i+1]);
i++;
}
else if ((strcmp(argv[i], "--size-param") == 0)) {
if (i+1 >= argc) {
fprintf(stderr, "Not enough arguments after --size-param, expected <int>.\n");
gib_show_usage(argv);
exit(1);
}
gib_global_size_param = atoll(argv[i+1]);
i++;
}
// If present, we expect the two arguments to be <size> <iters>
else if (got_numargs >= 2) {
else{
fprintf(stderr, "Extra arguments left over: ");
for(; i < argc; i++) fprintf(stderr, "%s ", argv[i]);
gib_show_usage(argv);
exit(1);
} else {
if (got_numargs == 0) {
gib_global_size_param = atoll(argv[i]);
got_numargs ++;
} else {
gib_global_iters_param = atoll(argv[i]);
}
}
}

Expand Down

0 comments on commit b1a5c10

Please sign in to comment.