-
Notifications
You must be signed in to change notification settings - Fork 6
aiscp: Handle files > 2,147,479,552 bytes #157
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -10,9 +10,14 @@ | |||||||||
| * This _very_basic_ program copies SOURCE to DEST via GPU memory. | ||||||||||
| */ | ||||||||||
|
|
||||||||||
| #ifndef AISCP_CHUNK_SIZE | ||||||||||
| #define AISCP_CHUNK_SIZE 0x7ffff000lu | ||||||||||
| #endif | ||||||||||
|
|
||||||||||
| #include <hipfile.h> | ||||||||||
| #include <hip/hip_runtime_api.h> | ||||||||||
|
|
||||||||||
| #include <algorithm> | ||||||||||
| #include <cerrno> | ||||||||||
| #include <cstdio> | ||||||||||
| #include <cstdlib> | ||||||||||
|
|
@@ -70,6 +75,16 @@ close_file(const char *path, int fd, hipFileHandle_t handle) | |||||||||
| return 0; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /// @brief Round value to the next multiple of align. Align _must_ be a power of 2. | ||||||||||
| /// @param value The value to round up. | ||||||||||
| /// @param align Value will be round up to a multiple of align | ||||||||||
|
||||||||||
| /// @param align Value will be round up to a multiple of align | |
| /// @param align Value will be rounded up to a multiple of align |
Copilot
AI
Jan 16, 2026
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.
The hipFileRead call always reads buffer_size bytes, even on the last chunk where fewer bytes may remain. While hipFileRead likely handles this correctly by returning the actual bytes read, it would be more explicit and safer to limit the read size to the remaining bytes: std::min(buffer_size, file_size - static_cast<size_t>(ncopy)). This also makes the code's intent clearer.
| nread = hipFileRead(src_handle, devbuf, buffer_size, ncopy, 0); | |
| const size_t remaining = file_size - static_cast<size_t>(ncopy); | |
| const size_t read_size = std::min(buffer_size, remaining); | |
| nread = hipFileRead(src_handle, devbuf, read_size, ncopy, 0); |
Copilot
AI
Jan 16, 2026
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.
The error message incorrectly references src_path instead of dst_path. When hipFileWrite fails, the error should indicate the destination file, not the source file.
| fprintf(stderr, "Could not write to %s (%zd) (%s)\n", src_path, nbytes, | |
| fprintf(stderr, "Could not write to %s (%zd) (%s)\n", dst_path, nbytes, |
Copilot
AI
Jan 16, 2026
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.
The outer while loop continues until ncopy equals file_size, but there's no handling for the case when hipFileRead returns 0 (EOF) before reaching file_size. If hipFileRead returns 0 prematurely, this will result in an infinite loop since ncopy will never reach file_size. Consider adding a check: if nread is 0, break from the loop or handle it as an error.
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.
The AISCP_CHUNK_SIZE constant (0x7ffff000lu = 2,147,479,552 bytes) should have a comment explaining why this specific value was chosen and how it relates to the Linux maximum I/O size mentioned in the PR description. This would help future maintainers understand the rationale behind this magic number.