Debian Codegraph @

tensilelite/Tensile/TensileLogic/ValidMatrixInstruction.py

raw symbols SCIP
1 ################################################################################
2 #
3 # Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved.
4 #
5 # Permission is hereby granted, free of charge, to any person obtaining a copy
6 # of this software and associated documentation files (the "Software"), to deal
7 # in the Software without restriction, including without limitation the rights
8 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 # copies of the Software, and to permit persons to whom the Software is
10 # furnished to do so, subject to the following conditions:
11 #
12 # The above copyright notice and this permission notice shall be included in
13 # all copies or substantial portions of the Software.
14 #
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 # SOFTWARE.
22 #
23 ################################################################################
24
25 """
26 ValidMatrixInstruction
27 ---
28 Format: (M x N x K x B)
29 XDLOPS tile definition, only valid for gfx908, gfx90a
30 MxNxKxB specifies matrix instruction variants
31 MxNxB determines the shape of the C tile each instruction worked on
32 K determines the unroll depth
33
34 Alternative format: (M x N x K x B x MIBlockM x WaveTileM x WaveTileN x WaveM x WaveN)
35 (Note: MxN means M-by-N in the following comments)
36 MIBlockM determines how many blocks along M dimension for multi-block MI variants. Concrete examples:
37 - MI 16x16x1x4 (4-block variant) with MIBlockM=4 -> (16x16)*(4x1)=64x16 tile per instruction executed
38 - MI 32x32x1x2 (2-block variant) with MIBlockM=1 -> (32x32)*(1x2)=32x64 tile per instruction executed
39 WaveTileM/N are dimensions of the C tile each wave works on, and is close to the concept of ThreadTile in classic VALU kernels
40 - WT 4x1 -> each wave executes 4x1 matrix instructions on the C tile of total area (4*MITileM)x(1*MITileN)
41 WaveM/N are dimensions of waves spawned for one workgroup where each wave consists of 64 threads
42 - Wave2x2 -> a total of 4 waves in one workgroup of shape 2x2
43 Putting it all together:
44 - [32, 32, 1, 2, 1, 4, 1, 2, 2]
45 ^^^^^^^^^^^^ ^ ^^^^ ^^^^
46 MatrixInst BlkM WT Wave
47 - means (32x64) per MI * (4x1) per wave * (2x2) per workgroup = (32*4*2)x(64*1*2) = 256x128 macro tile
48 Tensile will ignore the parameters ThreadTile and WorkGroup when the alternative format is used
49
50 Notes:
51 - If empty, do not use these instructions
52 """
53
54 from typing import Dict
55 from pathlib import Path
56
57 from Tensile.Common import IsaVersion, IsaInfo, elineno
58 from Tensile.SolutionStructs.Validators.MatrixInstruction import validateMIParameters
59
60
61 def _validateMatrixInstruction(
62 solution: dict, isaInfoMap: Dict[IsaVersion, IsaInfo], filepath: Path
63 ) -> bool:
64 try:
65 validateMIParameters(solution, isaInfoMap)
66 assert solution["Valid"], f"Solution was rejected: {elineno()}"
67 return True
68 except AssertionError as e:
69 print(
70 f"Error: Validation failed: {e} (file: {filepath}, index: {solution['SolutionIndex']})"
71 )
72 return False