| 1 |
# Copyright Advanced Micro Devices, Inc., or its affiliates. |
| 2 |
# SPDX-License-Identifier: MIT |
| 3 |
|
| 4 |
#!/usr/bin/env python3 |
| 5 |
|
| 6 |
# Copyright © Advanced Micro Devices, Inc., or its affiliates. |
| 7 |
# SPDX-License-Identifier: MIT |
| 8 |
|
| 9 |
import argparse |
| 10 |
import origami |
| 11 |
import math |
| 12 |
|
| 13 |
def parseArguments(): |
| 14 |
parser = argparse.ArgumentParser(description="Test StreamK Grid Selection.") |
| 15 |
parser.add_argument("-m", type=int, default=8192, help="Problem M dimension") |
| 16 |
parser.add_argument("-n", type=int, default=8192, help="Problem N dimension") |
| 17 |
parser.add_argument("-k", type=int, default=8192, help="Problem K dimension") |
| 18 |
parser.add_argument( |
| 19 |
"--trans_a", type=bool, default=True, help="Whether to transpose A" |
| 20 |
) |
| 21 |
parser.add_argument( |
| 22 |
"--trans_b", type=bool, default=False, help="Whether to transpose B" |
| 23 |
) |
| 24 |
parser.add_argument("--device", type=int, default=0, help="Device ID") |
| 25 |
parser.add_argument("--batch", type=int, default=1, help="Batch size") |
| 26 |
parser.add_argument( |
| 27 |
"--type_a", type=str, default="f16", help="Size of each element in A in bits" |
| 28 |
) |
| 29 |
parser.add_argument( |
| 30 |
"--type_b", type=str, default="f16", help="Size of each element in B in bits" |
| 31 |
) |
| 32 |
parser.add_argument( |
| 33 |
"--type_acc", type=str, default="f32", help="Size of each element in partial tile in bits" |
| 34 |
) |
| 35 |
parser.add_argument( |
| 36 |
"--type_d", type=str, default="f16", help="Size of each element in the output in bits" |
| 37 |
) |
| 38 |
parser.add_argument("--type_compute", type=str, default=None, help="Instruction input type") |
| 39 |
parser.add_argument("--workspace_size", type=int, default=0, help="Amount of workspace available in bytes") |
| 40 |
parser.add_argument("--debug", action="store_true", help="Enable debug mode") |
| 41 |
parser.add_argument("--print", action="store_true", help="Print hardware info") |
| 42 |
parser.add_argument( |
| 43 |
"--wgm", type=int, default=6, help="Wave granularity multiplier" |
| 44 |
) |
| 45 |
# New macro-tile size arguments: |
| 46 |
parser.add_argument("--mt_m", type=int, default=32, help="Macro-tile dimension M") |
| 47 |
parser.add_argument("--mt_n", type=int, default=32, help="Macro-tile dimension N") |
| 48 |
parser.add_argument("--mt_k", type=int, default=256, help="Macro-tile dimension K") |
| 49 |
parser.add_argument("--mi_m", type=int, default=16, help="Machine Instruction dimension M") |
| 50 |
parser.add_argument("--mi_n", type=int, default=16, help="Machine Instruction dimension N") |
| 51 |
parser.add_argument("--mi_k", type=int, default=16, help="Machine Instruction dimension K") |
| 52 |
parser.add_argument("--occupancy", type=int, default=1, help="Occupancy of kernel") |
| 53 |
|
| 54 |
parser.add_argument("--dynamic_grid_version", type=int, default=5, help="Version of Dynamic Grid Selection to use") |
| 55 |
|
| 56 |
args = parser.parse_args() |
| 57 |
|
| 58 |
if args.type_compute is None: |
| 59 |
if origami.datatype_to_bits(origami.string_to_datatype(args.type_a)) > origami.datatype_to_bits(origami.string_to_datatype(args.type_b)): |
| 60 |
args.type_compute = args.type_a |
| 61 |
else: |
| 62 |
args.type_compute = args.type_b |
| 63 |
|
| 64 |
return args |
| 65 |
|
| 66 |
|
| 67 |
def main(): |
| 68 |
args = parseArguments() |
| 69 |
|
| 70 |
hardware = origami.get_hardware_for_device(args.device) |
| 71 |
|
| 72 |
if args.print: |
| 73 |
hardware.print() |
| 74 |
|
| 75 |
reduction = origami.select_reduction( |
| 76 |
args.m, |
| 77 |
args.n, |
| 78 |
args.k, |
| 79 |
args.batch, |
| 80 |
args.mt_m, |
| 81 |
args.mt_n, |
| 82 |
args.mt_k, |
| 83 |
hardware, |
| 84 |
args.dynamic_grid_version |
| 85 |
) |
| 86 |
|
| 87 |
winner_grid = origami.select_grid( |
| 88 |
args.m, |
| 89 |
args.n, |
| 90 |
args.k, |
| 91 |
args.batch, |
| 92 |
args.trans_a, |
| 93 |
args.trans_b, |
| 94 |
origami.datatype_to_bits(origami.string_to_datatype(args.type_a)), |
| 95 |
origami.datatype_to_bits(origami.string_to_datatype(args.type_b)), |
| 96 |
origami.datatype_to_bits(origami.string_to_datatype(args.type_d)), |
| 97 |
origami.string_to_datatype(args.type_compute), |
| 98 |
args.workspace_size, |
| 99 |
args.mt_m, |
| 100 |
args.mt_n, |
| 101 |
args.mt_k, |
| 102 |
args.mi_m, # MI_M |
| 103 |
args.mi_n, # MI_N |
| 104 |
args.mi_k, # MI_K |
| 105 |
args.wgm, |
| 106 |
origami.datatype_to_bits(origami.string_to_datatype(args.type_acc)) // 8, |
| 107 |
args.occupancy, |
| 108 |
hardware, |
| 109 |
args.dynamic_grid_version, |
| 110 |
reduction |
| 111 |
) |
| 112 |
|
| 113 |
print(f"Best reduction algo : {reduction}") |
| 114 |
print(f"Best grid : {winner_grid}") |
| 115 |
|
| 116 |
return 0 |
| 117 |
|
| 118 |
|
| 119 |
if __name__ == "__main__": |
| 120 |
exit(main()) |