forked from Dao-AILab/flash-attention
-
Notifications
You must be signed in to change notification settings - Fork 79
[CK_TILE] Update CK and add RDNA build support #178
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
10 commits
Select commit
Hold shift + click to select a range
917fae5
update composable_kernel to e5683e2
hyoon1 cc6bd05
add ROCm gfx11/gfx12 build support
hyoon1 ad381ed
skip CK deterministic backward on gfx1x
hyoon1 e4078aa
default CK_TILE_FLOAT_TO_BFLOAT16_DEFAULT to 0 for gfx11 targets
hyoon1 4a318f7
add gfx1x bwd guards
hyoon1 0d230fe
keep CK submodule branch config unchanged
hyoon1 4ab9a5e
Update README file
hyoon1 3f99c2a
Replace FA-local head-grouping helper with CK helper
hyoon1 5e37371
skip unsupported CK backward cases on gfx11
hyoon1 d16038e
refine gfx1x test guards and share head-grouped fwd dispatch
hyoon1 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
Submodule composable_kernel
updated
38 files
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
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 |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| /****************************************************************************** | ||
| * Copyright (c) 2024, Tri Dao. | ||
| ******************************************************************************/ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "flash_common.hpp" | ||
|
|
||
| #include "fmha_fwd.hpp" | ||
| #include "fmha_fwd_head_grouping.hpp" | ||
|
|
||
| #include <iostream> | ||
|
|
||
| namespace flash { | ||
|
|
||
| template <typename FmhaFwdTraits, typename FmhaFwdArgs, typename FmhaFwdFn> | ||
| inline float maybe_dispatch_head_grouped_fwd(const ck_tile::stream_config& stream_config, | ||
| const FmhaFwdTraits& traits, | ||
| const FmhaFwdArgs& args, | ||
| int num_heads, | ||
| int num_heads_k, | ||
| int batch_size, | ||
| int seqlen_k, | ||
| int head_size_q, | ||
| int head_size_v, | ||
| size_t elem_bytes_k, | ||
| size_t elem_bytes_v, | ||
| at::ScalarType q_dtype, | ||
| FmhaFwdFn&& fmha_fwd_fn) | ||
| { | ||
| namespace head_grouping = fmha_fwd_head_grouping; | ||
|
|
||
| if (head_grouping::disabled_by_env()) { | ||
| if (head_grouping::log_enabled()) { | ||
| std::cout << "[LLC Head Grouping] disabled by env" << std::endl; | ||
| } | ||
| return -1.0f; | ||
| } | ||
|
|
||
| const auto group_size_opt = head_grouping::get_head_group_size(num_heads, | ||
| num_heads_k, | ||
| batch_size, | ||
| seqlen_k, | ||
| head_size_q, | ||
| head_size_v, | ||
| elem_bytes_k, | ||
| elem_bytes_v); | ||
| if (!group_size_opt.has_value() || group_size_opt.value() >= num_heads) { | ||
| if (head_grouping::log_enabled()) { | ||
| std::cout << "[LLC Head Grouping] skipped (group_size not set or >= nhead)" | ||
| << std::endl; | ||
| } | ||
| return -1.0f; | ||
| } | ||
|
|
||
| if (head_grouping::log_enabled()) { | ||
| const std::string arch = ck_tile::get_device_name(); | ||
| const size_t llc_bytes = head_grouping::get_llc_cache_bytes(arch); | ||
| const ck_tile::index_t gqa_ratio = (num_heads_k > 0 ? (num_heads / num_heads_k) : 1); | ||
| const ck_tile::index_t group_sz = group_size_opt.value(); | ||
| const ck_tile::index_t n_groups = ck_tile::integer_divide_ceil(num_heads, group_sz); | ||
| std::cout << "[LLC Head Grouping] enabled" | ||
| << " arch=" << (arch.empty() ? "unknown" : arch) | ||
| << " llc_mb=" << (llc_bytes / (1024ull * 1024ull)) | ||
| << " nhead_q=" << num_heads << " nhead_k=" << num_heads_k | ||
| << " gqa_ratio=" << gqa_ratio << " group_size=" << group_sz | ||
| << " groups=" << n_groups << std::endl; | ||
| } | ||
|
|
||
| const bool use_blockscale_qscale = traits.qscale_type == quant_scale_enum::blockscale; | ||
| auto dispatch_grouped_fwd = [&](auto type_config_tag) { | ||
| using TypeConfig = decltype(type_config_tag); | ||
| return head_grouping::run_fwd_head_grouped<typename TypeConfig::QDataType, | ||
| typename TypeConfig::KDataType, | ||
| typename TypeConfig::VDataType, | ||
| typename TypeConfig::ODataType, | ||
| float, | ||
| typename TypeConfig::LSEDataType, | ||
| typename TypeConfig::RandValOutputDataType>( | ||
| stream_config, | ||
| traits, | ||
| args, | ||
| num_heads, | ||
| num_heads_k, | ||
| group_size_opt.value(), | ||
| use_blockscale_qscale, | ||
| [&](const auto& grouped_traits, auto& grouped_args, const auto& grouped_sc) { | ||
| return fmha_fwd_fn(grouped_traits, grouped_args, grouped_sc); | ||
| }); | ||
| }; | ||
|
|
||
| if (q_dtype == torch::kFloat16) { | ||
| return dispatch_grouped_fwd(FmhaFwdTypeConfig<FmhaFwdFp16>{}); | ||
| } | ||
| if (q_dtype == torch::kBFloat16) { | ||
| return dispatch_grouped_fwd(FmhaFwdTypeConfig<FmhaFwdBf16>{}); | ||
| } | ||
| return -1.0f; | ||
| } | ||
|
|
||
| } // namespace flash |
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
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.