| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
import yaml |
| 26 |
from pprint import pformat |
| 27 |
|
| 28 |
from Tensile.Common.Architectures import SUPPORTED_ISA |
| 29 |
from Tensile.Common.Capabilities import makeIsaInfoMap |
| 30 |
from Tensile.Common.Types import IsaVersion |
| 31 |
from Tensile.Common.GlobalParameters import defaultSolution |
| 32 |
from Tensile.Toolchain.Validators import validateToolchain |
| 33 |
from Tensile.SolutionStructs.Validators.MatrixInstruction import matrixInstructionToMIParameters, validateMIParameters |
| 34 |
from Tensile.SolutionStructs.Validators.WorkGroup import validateWorkGroup |
| 35 |
|
| 36 |
cxxCompiler = validateToolchain("amdclang++") |
| 37 |
isaInfoMap = makeIsaInfoMap(SUPPORTED_ISA, cxxCompiler) |
| 38 |
|
| 39 |
def test_convert_9_item_custom_kernel_config(): |
| 40 |
input_conf = yaml.load( |
| 41 |
""" |
| 42 |
ProblemType: |
| 43 |
OperationType: GEMM |
| 44 |
DataTypeA: f8n |
| 45 |
DataTypeB: h |
| 46 |
UseScaleAB: "Scalar" |
| 47 |
DataType: h |
| 48 |
DestDataType: s |
| 49 |
ComputeDataType: s |
| 50 |
HighPrecisionAccumulate: True |
| 51 |
TransposeA: False |
| 52 |
TransposeB: False |
| 53 |
UseBias: 1 |
| 54 |
Activation: True |
| 55 |
UseScaleAlphaVec: 1 |
| 56 |
UseBeta: True |
| 57 |
Batched: True |
| 58 |
GroupedGemm: True |
| 59 |
SupportUserArgs: True |
| 60 |
MatrixInstruction: [32, 32, 8, 1, 1, 31, 16, 4, 2] |
| 61 |
WavefrontSize: 48 |
| 62 |
WorkGroup: [16, 16, 1] |
| 63 |
""", yaml.SafeLoader) |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
mi = input_conf["MatrixInstruction"] |
| 68 |
wavefrontSize = input_conf["WavefrontSize"] |
| 69 |
workgroup = input_conf["WorkGroup"] |
| 70 |
ptype = input_conf["ProblemType"] |
| 71 |
isa = IsaVersion(9, 0, 10) |
| 72 |
|
| 73 |
outputConf = matrixInstructionToMIParameters( |
| 74 |
mi, |
| 75 |
isa, |
| 76 |
wavefrontSize, |
| 77 |
ptype, |
| 78 |
workgroup, |
| 79 |
isaInfoMap, |
| 80 |
) |
| 81 |
|
| 82 |
input = { |
| 83 |
"MatrixInstruction": input_conf["MatrixInstruction"], |
| 84 |
} |
| 85 |
|
| 86 |
print("inputConf: ", pformat(input)) |
| 87 |
print("outputConf: ", pformat(outputConf)) |
| 88 |
|
| 89 |
assert outputConf["MatrixInstruction"] == [32, 32, 8, 1] |
| 90 |
assert outputConf["EnableMatrixInstruction"] == True |
| 91 |
assert outputConf["MIBlock"] == [32, 32, 8, 1, 1, 1] |
| 92 |
assert outputConf["MIWaveGroup"] == [4, 2] |
| 93 |
assert outputConf["MIWaveTile"] == [31, 16] |
| 94 |
assert outputConf["MatrixInstBM"] == 1 |
| 95 |
assert outputConf["MatrixInstBN"] == 1 |
| 96 |
assert outputConf["MIInputPerThread"] == 5 |
| 97 |
assert outputConf["MIInputPerThreadA"] == 5 |
| 98 |
assert outputConf["MIInputPerThreadB"] == 5 |
| 99 |
assert outputConf["MIInputPerThreadMetadata"] == 5 |
| 100 |
assert outputConf["ThreadTile"] == [1, 1] |
| 101 |
assert outputConf["Sparse"] == 0 |
| 102 |
assert outputConf["WorkGroup"] == [128, 3, 1] |
| 103 |
assert outputConf["WavefrontSize"] == 48 |
| 104 |
assert outputConf["ISA"] == isa |
| 105 |
assert outputConf["EnableF32XdlMathOp"] == False |
| 106 |
assert outputConf["MFMA_BF16_1K"] == False |
| 107 |
|
| 108 |
solution = defaultSolution |
| 109 |
solution.update(input_conf) |
| 110 |
solution.update(outputConf) |
| 111 |
|
| 112 |
assert validateMIParameters(solution, isaInfoMap, True) |
| 113 |
assert validateWorkGroup(solution) |
| 114 |
|
| 115 |
mi4 = solution["MatrixInstruction"] |
| 116 |
bm = solution["MatrixInstBM"] |
| 117 |
tt0 = solution["MIWaveTile"][0] |
| 118 |
tt1 = solution["MIWaveTile"][1] |
| 119 |
wg0 = solution["MIWaveGroup"][0] |
| 120 |
wg1 = solution["MIWaveGroup"][1] |
| 121 |
format9 = [mi4[0], mi4[1], mi4[2], mi4[3], bm, tt0, tt1, wg0, wg1] |
| 122 |
|
| 123 |
assert format9 == mi |
| 124 |
|
| 125 |
|
| 126 |
def testConvert9ItemCustomKernelConfig(): |
| 127 |
|
| 128 |
inputConf = yaml.load( |
| 129 |
""" |
| 130 |
custom.config: |
| 131 |
ProblemType: |
| 132 |
OperationType: GEMM |
| 133 |
DataTypeA: f8n |
| 134 |
DataTypeB: h |
| 135 |
UseScaleAB: "Scalar" |
| 136 |
DataType: h |
| 137 |
DestDataType: s |
| 138 |
ComputeDataType: s |
| 139 |
HighPrecisionAccumulate: True |
| 140 |
TransposeA: False |
| 141 |
TransposeB: False |
| 142 |
UseBias: 1 |
| 143 |
Activation: True |
| 144 |
UseScaleAlphaVec: 1 |
| 145 |
UseBeta: True |
| 146 |
Batched: True |
| 147 |
GroupedGemm: True |
| 148 |
SupportUserArgs: True |
| 149 |
MatrixInstruction: [32, 32, 8, 1, 5, 6, 7, 8, 9] |
| 150 |
1LDSBuffer: 1 |
| 151 |
ScheduleIterAlg: 3 |
| 152 |
DepthU: 32 |
| 153 |
StaggerU: 0 |
| 154 |
WorkGroupMapping: 8 |
| 155 |
WaveSeparateGlobalReadA: 1 |
| 156 |
WaveSeparateGlobalReadB: 1 |
| 157 |
GlobalReadVectorWidthA: 4 |
| 158 |
GlobalReadVectorWidthB: 2 |
| 159 |
AssertFree0ElementMultiple: 4 |
| 160 |
AssertSummationElementMultiple: 1 |
| 161 |
NoReject: 1 |
| 162 |
InternalSupportParams: |
| 163 |
KernArgsVersion: 0 |
| 164 |
SupportUserGSU: False |
| 165 |
SupportCustomWGM: False |
| 166 |
SupportCustomStaggerU: False |
| 167 |
UseUniversalArgs: False |
| 168 |
""", yaml.SafeLoader) |
| 169 |
|
| 170 |
inputConf = inputConf["custom.config"] |
| 171 |
|
| 172 |
isa = IsaVersion(9, 4, 2) |
| 173 |
wavefrontSize = 48 |
| 174 |
workGroup = [4, 5, 6] |
| 175 |
|
| 176 |
outputConf = matrixInstructionToMIParameters( |
| 177 |
inputConf["MatrixInstruction"], |
| 178 |
isa, |
| 179 |
wavefrontSize, |
| 180 |
inputConf["ProblemType"], |
| 181 |
workGroup, |
| 182 |
isaInfoMap, |
| 183 |
) |
| 184 |
|
| 185 |
input = { |
| 186 |
"MatrixInstruction": inputConf["MatrixInstruction"], |
| 187 |
} |
| 188 |
|
| 189 |
print("inputConf: ", pformat(input)) |
| 190 |
print("outputConf: ", pformat(outputConf)) |
| 191 |
|
| 192 |
assert outputConf["MatrixInstruction"] == [32, 32, 8, 1] |
| 193 |
assert outputConf["EnableMatrixInstruction"] == True |
| 194 |
assert outputConf["MIBlock"] == [32, 32, 8, 1, 1, 1] |
| 195 |
assert outputConf["MIWaveGroup"] == [40, 1] |
| 196 |
assert outputConf["MIWaveTile"] == [6, 7] |
| 197 |
assert outputConf["MatrixInstBM"] == 1 |
| 198 |
assert outputConf["MatrixInstBN"] == 1 |
| 199 |
assert outputConf["MIInputPerThread"] == 5 |
| 200 |
assert outputConf["MIInputPerThreadA"] == 5 |
| 201 |
assert outputConf["MIInputPerThreadB"] == 5 |
| 202 |
assert outputConf["MIInputPerThreadMetadata"] == 5 |
| 203 |
assert outputConf["ThreadTile"] == [1, 1] |
| 204 |
assert outputConf["Sparse"] == 0 |
| 205 |
assert outputConf["WorkGroup"] == [1280, 2, 6] |
| 206 |
assert outputConf["WavefrontSize"] == 48 |
| 207 |
assert outputConf["ISA"] == isa |
| 208 |
assert outputConf["EnableF32XdlMathOp"] == False |
| 209 |
assert outputConf["MFMA_BF16_1K"] == False |
| 210 |
|
| 211 |
solution = defaultSolution |
| 212 |
solution.update(inputConf) |
| 213 |
solution.update(outputConf) |
| 214 |
|
| 215 |
assert validateMIParameters(solution, isaInfoMap, True) == True |