Skip to content

Add gpu_name as a parameter in roofline estimate utils #2657

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 1 commit into from
Aug 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions torchao/testing/training/roofline_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@
}


def get_specs():
gpu_name = torch.cuda.get_device_name(0)
def get_specs(gpu_name: Optional[str] = None):
if gpu_name is None:
gpu_name = torch.cuda.get_device_name(0)
return gpu_name_to_specs[gpu_name]


Expand Down Expand Up @@ -214,10 +215,15 @@ def get_tensor_memory_traffic_ovhd_s(


def get_individual_gemm_time_sympy(
M: sympy.Symbol, K: sympy.Symbol, N: sympy.Symbol, dtype, mx_recipe_name
M: sympy.Symbol,
K: sympy.Symbol,
N: sympy.Symbol,
dtype,
mx_recipe_name,
gpu_name: Optional[str] = None,
) -> sympy.Symbol:
# compute bound
specs = get_specs()
specs = get_specs(gpu_name)
gemm_ops = 2 * M * K * N
if dtype is torch.bfloat16:
peak_tops = specs["bf16_peak_tops"]
Expand Down Expand Up @@ -265,6 +271,7 @@ def get_gemm_time_sympy(
dtype,
float8_recipe_name: Optional[str],
mx_recipe_name: Optional[str],
gpu_name: Optional[str],
):
# next: add rowwise_with_gw_hp here
# note: this function is currently not super accurate for small shapes:
Expand All @@ -279,13 +286,13 @@ def get_gemm_time_sympy(
gemm_dtype_grad_weight = torch.bfloat16

gemm_output_time_s = get_individual_gemm_time_sympy(
M, K, N, gemm_dtype_input, mx_recipe_name
M, K, N, gemm_dtype_input, mx_recipe_name, gpu_name
)
gemm_grad_input_time_s = get_individual_gemm_time_sympy(
M, N, K, gemm_dtype_grad_input, mx_recipe_name
M, N, K, gemm_dtype_grad_input, mx_recipe_name, gpu_name
)
gemm_grad_weight_time_s = get_individual_gemm_time_sympy(
K, M, N, gemm_dtype_grad_weight, mx_recipe_name
K, M, N, gemm_dtype_grad_weight, mx_recipe_name, gpu_name
)
total = gemm_output_time_s + gemm_grad_input_time_s + gemm_grad_weight_time_s
return total
Expand All @@ -298,8 +305,9 @@ def get_float8_mem_sympy(
float8_recipe_name: Optional[str],
mx_recipe_name: Optional[str],
enable_fusion_modeling: bool,
gpu_name: Optional[str] = None,
):
specs = get_specs()
specs = get_specs(gpu_name)

# there are three gemms in the fwd/bwd of a linear:
#
Expand Down
Loading