-
Notifications
You must be signed in to change notification settings - Fork 267
[CK_TILE][FMHA] Enable wholek_prefetch #3026
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
Closed
+60
−6
Closed
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
496c693
enable wholek_prefetch
LJ-underdog 4da3fe1
Merge branch 'develop' into lj/wholek
LJ-underdog 8799f16
Update fmha_fwd.py
LJ-underdog b47650c
Update block_fmha_pipeline_enum.hpp
LJ-underdog eae516c
Merge branch 'develop' into lj/wholek
asleepzzz cfee37f
Merge branch 'develop' into lj/wholek
asleepzzz dbd9727
Merge branch 'develop' into lj/wholek
LJ-underdog 6c7e463
Update fmha_fwd.py
LJ-underdog f8de278
Merge branch 'develop' into lj/wholek
LJ-underdog e41098e
replace squant to qscale
LJ-underdog d43ea4a
Update fmha_fwd.py
LJ-underdog 7c44495
Update example/ck_tile/01_fmha/codegen/ops/fmha_fwd.py
LJ-underdog 8ec3ca3
Update include/ck_tile/ops/fmha/pipeline/block_fmha_pipeline_qr_ks_vs…
LJ-underdog ecc0d6e
Update example/ck_tile/01_fmha/codegen/ops/fmha_fwd.py
LJ-underdog 19a3ab1
Improve readability of seqtune method
LJ-underdog 20cc3f3
Merge branch 'develop' into lj/wholek
illsilin 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
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 |
|---|---|---|
|
|
@@ -306,7 +306,7 @@ def scheck(self) -> str: | |
| return "true" # always support | ||
| else: | ||
| return "true" | ||
| elif self.pipeline_tag in ["qr", "qs"]: | ||
| elif self.pipeline_tag in ["qr", "qs", "qr_wholek_prefetch"]: | ||
| if self.spad == "t": | ||
| return f"true /*a.seqlen_q % {self.bm0} != 0*/" # TODO: order of get_pipelines() matters! (ugly) | ||
| else: | ||
|
|
@@ -315,7 +315,9 @@ def scheck(self) -> str: | |
| assert False | ||
|
|
||
| def seqtune(self, max_bm0: int) -> str: | ||
| if self.bm0 == max_bm0: | ||
| if ( | ||
| self.bm0 == max_bm0 or self.bm0 == 64 | ||
| ): # 64 is the smallest bm0 tile (used e.g. by wholek_prefetch) and serves as a generic fallback | ||
| return "true/*fall back to largest tile*/" | ||
| else: | ||
| return f"a.seqlen_q <= {self.bm0}" | ||
|
|
@@ -329,7 +331,7 @@ def skcheck(self) -> str: | |
| return f"(a.cu_seqlen_k_ptr != nullptr) || (a.seqlen_k == 0 || a.seqlen_k % {self.bn0} != 0)" | ||
| else: | ||
| return f"(a.cu_seqlen_k_ptr == nullptr) && (a.seqlen_k != 0 && a.seqlen_k % {self.bn0} == 0)" | ||
| elif self.pipeline_tag in ["qr", "qs"]: | ||
| elif self.pipeline_tag in ["qr", "qs", "qr_wholek_prefetch"]: | ||
| if self.skpad == "t": | ||
| return f"true /*a.seqlen_k % {self.bn0} != 0*/" # TODO: order of get_pipelines() matters! (ugly) | ||
| else: | ||
|
|
@@ -350,7 +352,13 @@ def dcheck(self) -> str: | |
| return f"a.hdim_q % {vec} == 0" | ||
| else: | ||
| assert False | ||
| elif self.pipeline_tag in ["qr", "qs", "qr_async_trload", "qr_async_trload_v3"]: | ||
| elif self.pipeline_tag in [ | ||
| "qr", | ||
| "qs", | ||
| "qr_async_trload", | ||
| "qr_async_trload_v3", | ||
| "qr_wholek_prefetch", | ||
| ]: | ||
| bk0submax = K0_MAX_SUBMAX_MAP[self.bk0max] | ||
| if self.dpad == "t": | ||
| return f"true /*a.hdim_q % {bk0submax} != 0*/" # TODO: order of get_pipelines() matters! (ugly) | ||
|
|
@@ -367,7 +375,13 @@ def dvcheck(self) -> str: | |
| return f"a.hdim_v % {vec} == 0" | ||
| else: | ||
| assert False | ||
| elif self.pipeline_tag in ["qr", "qs", "qr_async_trload", "qr_async_trload_v3"]: | ||
| elif self.pipeline_tag in [ | ||
| "qr", | ||
| "qs", | ||
| "qr_async_trload", | ||
| "qr_async_trload_v3", | ||
| "qr_wholek_prefetch", | ||
| ]: | ||
| bk0submax = K0_MAX_SUBMAX_MAP[self.bk0max] | ||
| if self.dvpad == "t": | ||
| return f"true /*a.hdim_v % {bk0submax} != 0*/" # TODO: order of get_pipelines() matters! (ugly) | ||
|
|
@@ -942,6 +956,7 @@ def get_hdim_tile_size_dict(cls, dtype: str) -> Optional[dict]: | |
| ( 96, 128) : [FmhaFwdTileSize(128, 128, 32, 128, 32, 96, 4, 1, 1, 4, 1, 1, 32, 32, 16, 32, 32, 16, -1)], | ||
| (128, 128) : [FmhaFwdTileSize( 16, 32, 64, 128, 32, 128, 1, 1, 1, 1, 1, 1, 16, 16, 32, 16, 16, 32, -1), | ||
| FmhaFwdTileSize( 32, 32, 128, 128, 32, 128, 1, 1, 1, 1, 1, 1, 32, 32, 16, 32, 32, 16, -1), | ||
| FmhaFwdTileSize(64, 128, 32, 128, 32, 128, 4, 1, 1, 4, 1, 1, 16, 16, 32, 16, 16, 16, -1, CppConstraint('get_num_blocks(128) < num_cus * min_cu_util_rate')), | ||
| FmhaFwdTileSize(128, 64, 32, 128, 16, 128, 4, 1, 1, 4, 1, 1, 32, 32, 16, 32, 32, 16, -1), | ||
| FmhaFwdTileSize(128, 128, 32, 128, 32, 128, 4, 1, 1, 4, 1, 1, 32, 32, 16, 32, 32, 16, -1)], | ||
| # (160, 160) : [FmhaFwdTileSize(128, 128 , 32, 160, 32, 160, 4, 1, 1, 4, 1, 1, 32, 32, 16, 32, 32, 16, 1)], | ||
|
|
@@ -1012,6 +1027,32 @@ def get_pipelines( | |
| else: | ||
| pipelines.append(FmhaFwdPipeline("qr_async", "row", "t", "f", "t", "t", logits, bias, lse, dropout, qscale, mask, skip, "f", sink)) # fmt: skip | ||
| pipelines.append(FmhaFwdPipeline("qr_async", "row", "t", "t", "t", "t", logits, bias, lse, dropout, qscale, mask, skip, "f", sink)) # fmt: skip | ||
| if ( | ||
| (hdim, hdim_v) == (128, 128) | ||
| and logits == "f" | ||
| and bias == "no" | ||
| and dropout == "f" | ||
| and sink == "f" | ||
| ): | ||
| pipelines.append( | ||
| FmhaFwdPipeline( | ||
| "qr_wholek_prefetch", | ||
| "row", | ||
| "f", | ||
| "f", | ||
| "f", | ||
| "f", | ||
| logits, | ||
| bias, | ||
| lse, | ||
| dropout, | ||
| qscale, | ||
| mask, | ||
| skip, | ||
| "f", | ||
| sink, | ||
| ) | ||
| ) | ||
| if receipt == 1 and bias != "bias": | ||
| pipelines.append(FmhaFwdPipeline("qr", "row", "t", "t", "t", "t", logits, bias, lse, dropout, qscale, mask, skip, "f", sink)) # fmt: skip # TODO: cover arbitraty hdim# fmt: skip | ||
| elif dtype in cls._DT_FP8BF16 or dtype in cls._DT_FP8FP32: | ||
|
|
@@ -1320,6 +1361,10 @@ def get_fwd_blobs( | |
| for tile, pipeline in itertools.product( | ||
| tiles, factory.get_pipelines(dtype, hdim, hdim_v, receipt, mask_impl) | ||
| ): | ||
| if pipeline.tag == "qr_wholek_prefetch" and ( | ||
|
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 move the check to the |
||
| (hdim, hdim_v) == (128, 128) and tile.F_bm0 == 128 | ||
| ): | ||
| continue | ||
| problem_ctx = ProblemContext( | ||
| dtype=dtype, mode=mode, hdim=hdim, hdim_v=hdim_v | ||
| ) | ||
|
|
||
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
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.
Why don't add padding for both of the
seqlen_q&seqlen_kdimensions?