Skip to content

Commit

Permalink
add SmUtilization check for Reduce Region
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanghonggeng committed Dec 27, 2024
1 parent 84ed69f commit a009014
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions paddle/cinn/ir/group_schedule/config/group_tile_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,16 @@ TileConfigMap BuildVectorizeConfig(
};

bool is_sm_fully_utilized = true;
auto CheckSmUtilization = [sm_count, max_threads_per_sm, max_blocks_per_sm](
int total_threads, int block_size) -> bool {
int blocks_needed = CeilDiv(total_threads, block_size);
// Only proceed with vectorization if SM utilization exceeds 100%
auto CheckSmUtilization =
[&](int input_size, int block_size, std::string last_dim) -> bool {
if (last_dim != "S" && last_dim != "R") {
VLOG(5) << "Invalid last_dim in SmUtilization Check: " << last_dim;
return false;
}

int blocks_needed =
(last_dim == "S") ? CeilDiv(input_size, block_size) : input_size;
int sms_needed = CeilDiv(blocks_needed, max_blocks_per_sm);
float sm_utilization = static_cast<float>(sms_needed) / sm_count;

Expand All @@ -239,6 +246,8 @@ TileConfigMap BuildVectorizeConfig(
if (warp_nums > 1 || spatial_numel < warp_nums * 64) {
rd_thread_num = warp_nums * kWarpSize;
if (CheckVectorize(reduce_numel, rd_thread_num, vectorize_factor)) {
is_sm_fully_utilized =
CheckSmUtilization(spatial_numel, rd_thread_num, "R");
break;
}
reduce_method = BlockReduceMethod();
Expand All @@ -257,7 +266,8 @@ TileConfigMap BuildVectorizeConfig(
// warp_nums = Trim(warp_nums, 1, 32);
sp_thread_num = kWarpSize * warp_nums;
if (CheckVectorize(spatial_numel, sp_thread_num, vectorize_factor)) {
is_sm_fully_utilized = CheckSmUtilization(spatial_numel, sp_thread_num);
is_sm_fully_utilized = CheckSmUtilization(
spatial_numel / vectorize_factor, sp_thread_num, "S");
break;
}
}
Expand Down

0 comments on commit a009014

Please sign in to comment.