Fix int32 truncation of 64-bit ssd_row_addrs in unrolled forward path#5743
Open
EddyLXJ wants to merge 1 commit intopytorch:mainfrom
Open
Fix int32 truncation of 64-bit ssd_row_addrs in unrolled forward path#5743EddyLXJ wants to merge 1 commit intopytorch:mainfrom
EddyLXJ wants to merge 1 commit intopytorch:mainfrom
Conversation
Summary: X-link: facebookresearch/FBGEMM#2674 CONTEXT: KVZCH SSD TBE forward kernel deterministically page-faults on AMD MI350X with HSA Memory access faults at addresses showing a bimodal distribution: low (e.g., 0x4989000, 0x670ac000) AND sign-extended high (e.g., 0xfffff5295000, 0xffffe62d4000). Reproduced in 7+ MAST jobs. ROOT CAUSE: In the ROCm-only unrolled outer loop in embedding_forward_split_kernel_template.cu, the per-thread cache-index staging array was hardcoded as int32_t at lines 330 and 422. For SSD path, locs_or_addrs_type is int64_t (the array entries are raw 64-bit row pointers from ssd_row_addrs). SHFL_SYNC returns the full int64_t value, but writing it to int32_t silently truncates the upper 32 bits. On reload, sign-extension of the low 32 bits reconstructs a corrupted pointer: - Low-32 with bit 31 = 0 -> small positive value (matches low fault addresses) - Low-32 with bit 31 = 1 -> sign-extended 0xFFFF... (matches high fault addresses) The dereference at load_and_accumulate / load_weights macros (lines 78, 173) reads through this corrupted pointer -> HSA fault. The non-unrolled tail loop at line 482 already uses {{ locs_or_addrs_type }} correctly. CUDA path uses the non-unrolled path so never hits this bug. WHAT: Replace the hardcoded int32_t with the jinja {{ locs_or_addrs_type }} template variable at both sites (line 330 staging array and line 422 reload), matching the type used elsewhere in the same template. Add an explanatory comment at the staging array site. Differential Revision: D104181076
Contributor
|
@EddyLXJ has exported this pull request. If you are a Meta employee, you can view the originating Diff in D104181076. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary:
X-link: https://github.com/facebookresearch/FBGEMM/pull/2674
CONTEXT: KVZCH SSD TBE forward kernel deterministically page-faults on AMD MI350X with HSA Memory access faults at addresses showing a bimodal distribution: low (e.g., 0x4989000, 0x670ac000) AND sign-extended high (e.g., 0xfffff5295000, 0xffffe62d4000). Reproduced in 7+ MAST jobs.
ROOT CAUSE: In the ROCm-only unrolled outer loop in embedding_forward_split_kernel_template.cu, the per-thread cache-index staging array was hardcoded as int32_t at lines 330 and 422. For SSD path, locs_or_addrs_type is int64_t (the array entries are raw 64-bit row pointers from ssd_row_addrs). SHFL_SYNC returns the full int64_t value, but writing it to int32_t silently truncates the upper 32 bits. On reload, sign-extension of the low 32 bits reconstructs a corrupted pointer:
The dereference at load_and_accumulate / load_weights macros (lines 78, 173) reads through this corrupted pointer -> HSA fault.
The non-unrolled tail loop at line 482 already uses {{ locs_or_addrs_type }} correctly. CUDA path uses the non-unrolled path so never hits this bug.
WHAT:
Replace the hardcoded int32_t with the jinja {{ locs_or_addrs_type }} template variable at both sites (line 330 staging array and line 422 reload), matching the type used elsewhere in the same template. Add an explanatory comment at the staging array site.
Differential Revision: D104181076