-
Notifications
You must be signed in to change notification settings - Fork 145
[AdvancedCompiler]Optimize mean #979
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
AdvancedCompiler
wants to merge
5
commits into
FlagOpen:master
Choose a base branch
from
AdvancedCompiler:optimize_mean
base: master
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
aab7106
optimize_mean
zhoubo567 d64c24e
Merge branch 'FlagOpen:master' into optimize_mean
AdvancedCompiler c554fe5
merge local changes with remote
henghengxiedaima 3c257cd
Merge branch 'FlagOpen:master' into optimize_mean
AdvancedCompiler 0db3c65
Merge branch 'FlagOpen:master' into optimize_mean
AdvancedCompiler 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 | ||||
---|---|---|---|---|---|---|
|
@@ -2,6 +2,11 @@ | |||||
import triton | ||||||
|
||||||
|
||||||
_MIN_TILE_N = 64 | ||||||
_MAX_TILE_N_PER_ROW = 4096 | ||||||
_MAX_ONE_TILE_N = 2048 | ||||||
|
||||||
|
||||||
def simple_elementwise_blocksize_heur(args): | ||||||
return 1024 | ||||||
|
||||||
|
@@ -232,6 +237,42 @@ def vdot_heur_block_size(args): | |||||
return 1024 | ||||||
|
||||||
|
||||||
def mean_heur_tile_k(args): | ||||||
MAX_TILE_K = 512 | ||||||
NUM_SMS = torch.cuda.get_device_properties( | ||||||
torch.cuda.current_device() | ||||||
).multi_processor_count | ||||||
tile_k = 1 | ||||||
upper_bound = min(args["K"], MAX_TILE_K) | ||||||
max_tile_k_allowed_by_tile_n = max(1, _MAX_TILE_N_PER_ROW // _MIN_TILE_N) | ||||||
upper_bound = min(upper_bound, max_tile_k_allowed_by_tile_n) | ||||||
while tile_k <= upper_bound: | ||||||
num_blocks = args["M"] * triton.cdiv(args["K"], tile_k) | ||||||
num_waves = num_blocks / NUM_SMS | ||||||
if (num_waves > 1) and (tile_k * 2 <= upper_bound): | ||||||
tile_k *= 2 | ||||||
else: | ||||||
break | ||||||
return tile_k | ||||||
|
||||||
|
||||||
def mean_heur_tile_n_non_inner(args): | ||||||
tile_k = args.get("TILE_K", 1) | ||||||
limit_by_k = max(1, _MAX_TILE_N_PER_ROW // tile_k) | ||||||
N = args.get("N", 1) | ||||||
desired = min(max(N, _MIN_TILE_N), limit_by_k) | ||||||
desired = min(desired, _MAX_ONE_TILE_N, limit_by_k) | ||||||
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
Suggested change
|
||||||
tile_n = triton.next_power_of_2(desired) | ||||||
if tile_n > limit_by_k: | ||||||
tile_n = limit_by_k | ||||||
tile_n = max(tile_n, _MIN_TILE_N) | ||||||
return tile_n | ||||||
|
||||||
|
||||||
def mean_heur_one_tile_per_cta(args): | ||||||
return args["TILE_N"] >= args["N"] | ||||||
|
||||||
|
||||||
HEURISTICS_CONFIGS = { | ||||||
"argmax": { | ||||||
"BLOCK_M": argmax_heur_block_m, | ||||||
|
@@ -279,6 +320,12 @@ def vdot_heur_block_size(args): | |||||
"ONE_TILE_PER_CTA": softmax_heur_one_tile_per_cta, | ||||||
"num_warps": softmax_heur_num_warps_non_inner, | ||||||
}, | ||||||
"mean_non_inner": { | ||||||
"TILE_K": mean_heur_tile_k, | ||||||
"TILE_N": mean_heur_tile_n_non_inner, | ||||||
"ONE_TILE_PER_CTA": mean_heur_one_tile_per_cta, | ||||||
"num_warps": softmax_heur_num_warps_non_inner, | ||||||
}, | ||||||
"softmax_inner": { | ||||||
"TILE_N": softmax_heur_tile_n_inner, | ||||||
"ONE_TILE_PER_CTA": softmax_heur_one_tile_per_cta, | ||||||
|
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.
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.
For simplicity and clarity, consider combining
mean_dim_comm
and themean_dim
wrapper into a singlemean_dim
function. The current implementation with a simple wrapper adds an unnecessary layer of indirection. Exposing theout
parameter in the publicmean_dim
function is also consistent with the PyTorch API.