-
Notifications
You must be signed in to change notification settings - Fork 751
Implement asynchronous LDS loads for MI350 #5348
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
Open
avbokovoy
wants to merge
5
commits into
pytorch:main
Choose a base branch
from
ROCm:abokovoi/async-lds-inference-opt
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
856f1af
Implement asynchronous LDS loads for MI350
avbokovoy dc3b15b
Hardcode size value in __builtin_amdgcn_global_load_lds intrinsic
avbokovoy 2c739ab
Fix ROCm version and arch guards
avbokovoy e6c0de4
Restore unfused row load+store for synchronous-fallback architectures
aryaman-gupta 50d6822
embedding_forward_quantized_split_nbit_kernel_template: shortens comm…
aryaman-gupta 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 |
|---|---|---|
|
|
@@ -165,46 +165,80 @@ __global__ void {{ emb_weight_type.enum_name }}_split_embedding{{ "_nobag" if no | |
|
|
||
| #pragma unroll | ||
| for (uint32_t outer_i = 0; outer_i < OutputRowsPerThread - OutputRowsPerThread % kRowUnroll; outer_i += kRowUnroll) { | ||
| uint4 row_data_v[kRowUnroll]; | ||
| const uint4* row_v[kRowUnroll]; | ||
| int32_t idx_v[kRowUnroll]; | ||
| int32_t cache_idx_v[kRowUnroll]; | ||
| bool row_valid_v[kRowUnroll]; | ||
| #pragma unroll | ||
| for (uint32_t inner_i = 0; inner_i < kRowUnroll; ++inner_i) { | ||
| uint32_t i = outer_i + inner_i; | ||
| bool valid = load_idx_valid && L_start + input_row_idx < Ls[i]; | ||
| bool cache_valid = !DeviceOnly && (placement == PlacementType::MANAGED_CACHING && valid); | ||
| idx_v[inner_i] = valid ? indices_[indices_starts[i] + L_start + input_row_idx] : -1; | ||
| cache_idx_v[inner_i] = (!DeviceOnly && cache_valid) ? lxu_cache_locations[indices_starts[i] + L_start + input_row_idx] : -1; | ||
| row_valid_v[inner_i] = valid; | ||
| } | ||
|
|
||
|
|
||
| #pragma unroll | ||
| for (uint32_t inner_i = 0; inner_i < kRowUnroll; ++inner_i) { | ||
| uint32_t i = outer_i + inner_i; | ||
| bool valid = load_idx_valid && L_start + input_row_idx < Ls[i]; | ||
| bool cache_valid = !DeviceOnly && (placement == PlacementType::MANAGED_CACHING && valid); | ||
| valid = valid && (idx_v[inner_i] != -1); | ||
| bool cache_valid = !DeviceOnly && (placement == PlacementType::MANAGED_CACHING && row_valid_v[inner_i]); | ||
| bool final_valid = row_valid_v[inner_i] && (idx_v[inner_i] != -1); | ||
| if (!DeviceOnly && cache_valid && cache_idx_v[inner_i] != kCacheLocationMissing) { | ||
| row_v[inner_i] = reinterpret_cast<const uint4*>(&lxu_cache_weights[static_cast<int64_t>(cache_idx_v[inner_i])][0]); | ||
| } else | ||
| if (valid) { | ||
| } else if (final_valid) { | ||
| row_v[inner_i] = reinterpret_cast<const uint4*>(&weights[static_cast<int64_t>(idx_v[inner_i]) * D_bytes]); | ||
| } else { | ||
| row_v[inner_i] = reinterpret_cast<const uint4*>(&weights[0]); | ||
| } | ||
| row_valid_v[inner_i] = final_valid; | ||
| } | ||
| #if (defined(__CUDA_ARCH__) && __CUDA_ARCH__ >= 800) || (defined(USE_ROCM) && defined(__gfx950__)) | ||
| #pragma unroll | ||
| for (uint32_t inner_i = 0; inner_i < kRowUnroll; inner_i++) { | ||
| uint32_t i = outer_i + inner_i; | ||
| bool final_valid = row_valid_v[inner_i]; | ||
| if constexpr (PackedMode) { | ||
| // Store row data with uint4_loads_per_row offset | ||
| cp_async_zfill_cg<sizeof(uint4)>( | ||
| &buffers[warp_idx][i][input_row_idx][row_load_idx + uint4_loads_per_row * packed_bag_load_idx], | ||
| &row_v[inner_i][row_load_idx], | ||
| final_valid); | ||
| } else { | ||
| cp_async_zfill_cg<sizeof(uint4)>( | ||
| &buffers[warp_idx][i][input_row_idx][row_load_idx], | ||
| &row_v[inner_i][row_load_idx], | ||
| final_valid); | ||
| } | ||
| } | ||
| {% if weighted %} | ||
| #pragma unroll | ||
| for (uint32_t inner_i = 0; inner_i < kRowUnroll; inner_i++) { | ||
|
Contributor
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. Please guard the changes to be ROCM only? We see small regression in NVIDIA.
Contributor
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. The whole block (lines 162-228) is under |
||
| uint32_t i = outer_i + inner_i; | ||
| bool final_valid = row_valid_v[inner_i] && (idx_v[inner_i] != -1); | ||
| if (row_load_idx == 0) { | ||
| // Use only one thread to load the index weight to prevent a race | ||
| // condition when writing to the shared memory | ||
| buffers_indice_weights[warp_idx][i][input_row_idx][packed_bag_load_idx] = | ||
| final_valid ? indice_weights[indices_starts[i] + L_start + input_row_idx] : 0.0; | ||
| } | ||
| } | ||
| {% endif %} | ||
| #else | ||
| // Maintain pipelining of load and store operations when async shared memory/lds | ||
| // loads are not available. | ||
| uint4 row_data_v[kRowUnroll]; | ||
| #pragma unroll | ||
| for (uint32_t inner_i = 0; inner_i < kRowUnroll; inner_i++) { | ||
| row_data_v[inner_i] = row_v[inner_i][row_load_idx]; | ||
| } | ||
| uint4 zeros = {0, 0, 0, 0}; | ||
| #pragma unroll | ||
| for (uint32_t inner_i = 0; inner_i < kRowUnroll; inner_i++) { | ||
| uint32_t i = outer_i + inner_i; | ||
| bool valid = load_idx_valid && (L_start + input_row_idx < Ls[i]) && (idx_v[inner_i] != -1); | ||
| uint4 data = valid ? row_data_v[inner_i] : zeros; | ||
| bool final_valid = row_valid_v[inner_i]; | ||
| uint4 data = final_valid ? row_data_v[inner_i] : zeros; | ||
| if constexpr (PackedMode) { | ||
| // Store row data with uint4_loads_per_row offset | ||
| buffers[warp_idx][i][input_row_idx][row_load_idx + uint4_loads_per_row * packed_bag_load_idx] = data; | ||
|
|
@@ -216,10 +250,11 @@ __global__ void {{ emb_weight_type.enum_name }}_split_embedding{{ "_nobag" if no | |
| // Use only one thread to load the index weight to prevent a race | ||
| // condition when writing to the shared memory | ||
| buffers_indice_weights[warp_idx][i][input_row_idx][packed_bag_load_idx] = | ||
| valid ? indice_weights[indices_starts[i] + L_start + input_row_idx] : 0.0; | ||
| final_valid ? indice_weights[indices_starts[i] + L_start + input_row_idx] : 0.0; | ||
| } | ||
| {% endif %} | ||
| } | ||
| #endif | ||
| } | ||
| {%- endif %} | ||
|
|
||
|
|
||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
could you ensure all the changes only affect rocm?
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 whole block (lines 162-228) is under
if is_rocmjinja guard