Skip to content

Commit

Permalink
Make tuning file loader more robust.
Browse files Browse the repository at this point in the history
  • Loading branch information
athas committed Aug 31, 2024
1 parent ee9b7e6 commit 8bd1871
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
* `auto output` didn't work if the `.fut` file did not have any path
components.

* Improved detection of malformed tuning files.

## [0.25.20]

### Added
Expand Down
8 changes: 7 additions & 1 deletion rts/c/tuning.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ static char* load_tuning_file(const char *fname,
char *eql = strstr(line, "=");
if (eql) {
*eql = 0;
int value = atoi(eql+1);
char *endptr;
int value = strtol(eql+1, &endptr, 10);
if (*endptr) {
snprintf(line, max_line_len, "Invalid line %d (must be of form 'name=int').",
lineno);
return line;
}
if (set_tuning_param(cfg, line, (size_t)value) != 0) {
char* err = (char*) malloc(max_line_len + 50);
snprintf(err, max_line_len + 50, "Unknown name '%s' on line %d.", line, lineno);
Expand Down
2 changes: 1 addition & 1 deletion src/Futhark/CodeGen/Backends/GenericC/CLI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ genericOptions =
char *ret = load_tuning_file(optarg, cfg, (int(*)(void*, const char*, size_t))
futhark_context_config_set_tuning_param);
if (ret != NULL) {
futhark_panic(1, "When loading tuning from '%s': %s\n", optarg, ret);
futhark_panic(1, "When loading tuning file '%s': %s\n", optarg, ret);
}}|]
},
Option
Expand Down
2 changes: 1 addition & 1 deletion src/Futhark/CodeGen/Backends/GenericC/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ genericOptions =
char *ret = load_tuning_file(optarg, cfg, (int(*)(void*, const char*, size_t))
futhark_context_config_set_tuning_param);
if (ret != NULL) {
futhark_panic(1, "When loading tuning from '%s': %s\n", optarg, ret);
futhark_panic(1, "When loading tuning file '%s': %s\n", optarg, ret);
}}|]
},
Option
Expand Down

0 comments on commit 8bd1871

Please sign in to comment.