-
Notifications
You must be signed in to change notification settings - Fork 106
Fix device name validation in "modelstore" command #884
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,24 @@ | ||
| #include <stdlib.h> | ||
| #include <errno.h> | ||
| #include "backends/util.h" | ||
|
|
||
| int parseDeviceStr(const char *devicestr, RAI_Device *device, int64_t *deviceid) { | ||
| // if (strcasecmp(devicestr, "CPU") == 0) { | ||
| if (strncasecmp(devicestr, "CPU", 3) == 0) { | ||
| int parseDeviceStr(const char *device_str, RAI_Device *device, int64_t *device_id) { | ||
| if (strncasecmp(device_str, "CPU", 3) == 0) { | ||
| *device = RAI_DEVICE_CPU; | ||
| *deviceid = -1; | ||
| } else if (strcasecmp(devicestr, "GPU") == 0) { | ||
| *device_id = -1; | ||
| } else if (strcasecmp(device_str, "GPU") == 0) { | ||
| *device = RAI_DEVICE_GPU; | ||
| *deviceid = -1; | ||
| } else if (strncasecmp(devicestr, "GPU:", 4) == 0) { | ||
| *device_id = -1; | ||
| } else if (strncasecmp(device_str, "GPU:", 4) == 0) { | ||
| *device = RAI_DEVICE_GPU; | ||
| long long id; | ||
| sscanf(devicestr, "GPU:%lld", &id); | ||
| *deviceid = id; | ||
| // Convert the id string into a number, returns zero if no valid conversion could be | ||
| // preformed, and sets errno in case of overflow. | ||
| long long id = strtoll(device_str + 4, NULL, 0); | ||
| if (errno == ERANGE) | ||
| return 0; | ||
| *device_id = id; | ||
| } else { | ||
| return 0; | ||
| } | ||
|
|
||
| return 1; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,13 +19,22 @@ def test_modelstore_errors(env): | |
| con = get_connection(env, '{1}') | ||
| model_pb = load_file_content('pt-minimal.pt') | ||
|
|
||
| # Check that the basic arguments are valid (model's key, device, backend, blob) | ||
| # Check the validity of backend name and number of arguments | ||
| check_error_message(env, con, "wrong number of arguments for 'AI.MODELSTORE' command", | ||
| 'AI.MODELSTORE', 'm{1}', 'TORCH', 'BLOB', model_pb) | ||
| check_error_message(env, con, "unsupported backend", | ||
| 'AI.MODELSTORE', 'm{1}', 'PORCH', DEVICE, 'BLOB', model_pb) | ||
|
|
||
| # Check for valid device argument (should only be "CPU:<n>" or "GPU:<n>, where <n> is a number | ||
| # (contains digits only, up to 5). | ||
| check_error_message(env, con, "Invalid DEVICE", | ||
| 'AI.MODELSTORE', 'm{1}', 'TORCH', 'bad_device', 'BLOB', model_pb) | ||
| check_error_message(env, con, "Invalid DEVICE", | ||
| 'AI.MODELSTORE', 'm{1}', 'TORCH', 'CPU::', 'BLOB', model_pb) | ||
| check_error_message(env, con, "Invalid DEVICE", | ||
| 'AI.MODELSTORE', 'm{1}', 'TORCH', 'CPU:1.8', 'BLOB', model_pb) | ||
| check_error_message(env, con, "Invalid DEVICE", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a comment explaining why this is invalid device
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a comment in lines 28-29 explaining it... |
||
| 'AI.MODELSTORE', 'm{1}', 'TORCH', 'CPU:123456', 'BLOB', model_pb) | ||
|
|
||
| # Check for validity of batching arguments. | ||
| check_error_message(env, con, "Invalid argument for BATCHSIZE", | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why the change from
<=to<?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No actual reason... I believe that 5 digits should be enough