Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the handling of gibbon runtime args and usage help #228

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 39 additions & 27 deletions gibbon-rts/rts-c/gibbon_rts.c
Original file line number Diff line number Diff line change
Expand Up @@ -1796,13 +1796,20 @@ 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 timing iterations to perform (default 1).\n");
// TODO: Rectify the definition of size-param
printf(" --size-param <int> A parameter for size available as a language primitive which allows user to specify the size at runtime (default 1).\n");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't say I understand this line, but maybe I just need to read more...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not 100% sure how to phrase this.
I see that SizeParam in a primitve in the gibbon std-lib. The compiler generates code to create a call to get this variable which is set as a runtime arg.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you have a suggestion to better phrase this?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not at this point, I'm afraid. I'll have to dive deeper... For now, if no one objects, you could probably merge it as is.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good to me. I can add a TODO here to recheck this later.

return;
}

Expand Down Expand Up @@ -1864,6 +1871,14 @@ int dbgprintf(const char *format, ...)
return code;
}

void check_args(int i, int argc, char **argv, char *parameter){
if (i+1 >= argc) {
fprintf(stderr, "Not enough arguments after %s, expected <int>.\n", parameter);
gib_show_usage(argv);
exit(1);
}
}


/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* RTS initialization and clean up
Expand Down Expand Up @@ -1914,7 +1929,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,57 +1938,54 @@ 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) {
check_args(i, argc, argv, "--biginf-buffer-size");
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) {
check_args(i, argc, argv, "--inf-buffer-size");
gib_global_inf_init_chunk_size = atoll(argv[i + 1]);
i++;
}
else if ((strcmp(argv[i], "--bench-input") == 0)) {
if (i+1 >= argc) {
fprintf(stderr, "Not enough arguments after --bench-input, expected <file>.\n");
gib_show_usage(argv);
exit(1);
}
check_args(i, argc, argv, "--bench-input");
gib_global_benchfile_param = argv[i+1];
i++;
}
else if ((strcmp(argv[i], "--array-input") == 0)) {
if (i+1 >= argc) {
fprintf(stderr, "Not enough arguments after --array-input, expected <file>.\n");
gib_show_usage(argv);
exit(1);
}
check_args(i, argc, argv, "--array-input");
gib_global_arrayfile_param = argv[i+1];
i++;
}
else if (strcmp(argv[i], "--array-input-length") == 0 && i < argc - 1) {
check_args(i, argc, argv, "--array-input-length");
gib_global_arrayfile_length_param = atoll(argv[i+1]);
i++;
}
else if (strcmp(argv[i], "--bench-prog") == 0 && i < argc - 1) {
check_args(i, argc, argv, "--bench-prog");
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)) {
check_args(i, argc, argv, "--iterate");
gib_global_iters_param = atoll(argv[i+1]);
i++;
}
else if ((strcmp(argv[i], "--size-param") == 0)) {
check_args(i, argc, argv, "--size-param");
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
Loading