Debian Codegraph @

tensilelite/Tensile/Components/NotLocalFullTileElements.py

raw symbols SCIP
1 ################################################################################
2 #
3 # Copyright (C) 2022-2024 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 from ..Component import NotLocalFullTileElements
26 from math import ceil
27
28 class NotLocalFullTileElementsVALU(NotLocalFullTileElements):
29 kernel = {"EnableMatrixInstruction": False}
30
31 """
32 Partition thread-tile into writeElements for store code
33 This function creates the writeElement mapping for full tiles
34 (ie non-edge cases)
35 """
36 def __call__(self, writer, kernel, edge):
37 elements = []
38 vectorwidth = 0
39
40 if edge:
41 vectorwidth = kernel["VectorWidthA"] if kernel["_VectorStore"] else 1
42 vectorwidth = min(vectorwidth, writer.maxGwvw(kernel), kernel["AssertFree0ElementMultiple"])
43 assert(kernel["VectorWidthA"] % vectorwidth == 0)
44 else:
45 vectorwidth = kernel["VectorWidthA"] if kernel["_VectorStore"] else 1
46 vectorwidth = min(vectorwidth, writer.maxGwvw(kernel))
47
48 # Full tile loop:
49 for tt1 in range(0, kernel["ThreadTile1"]//kernel["VectorWidthA"]):
50 for vc1 in range(0, kernel["VectorWidthA"]):
51 for tt0 in range(0, kernel["ThreadTile0"]//kernel["VectorWidthA"]):
52 for vc0 in range(0, kernel["VectorWidthA"], vectorwidth): # note step by fullVw
53 element = (tt1, tt0, vc1, vc0)
54 elements.append(element)
55
56 return (vectorwidth, elements, vectorwidth, elements)
57
58 class NotLocalFullTileElementsMFMA(NotLocalFullTileElements):
59 kernel = {"EnableMatrixInstruction": True}
60
61 def getElements(self, writer, kernel, edge):
62 # When singleBuffer/atomic is enabled. We will have 2 different type of store.
63 # One is GSU=1 normal store and another is GSU>1 atomic store.
64 # storeVectorWidth indicates the atomic store vectorWidth.
65 # storeVectorWidth_1 indicates the normal store vectorWidth.
66 # For non-atomic cases, these two are the same.
67 elements = []
68 storeVectorWidth = 0
69 if edge:
70 storeVectorWidth = kernel["StoreVectorWidth"] if kernel["_VectorStore"] else 1
71 storeVectorWidth = min(storeVectorWidth, writer.maxGwvw(kernel), kernel["AssertFree0ElementMultiple"])
72 else:
73 storeVectorWidth = kernel["StoreVectorWidth"] if kernel["_VectorStore"] else 1
74 storeVectorWidth = min(storeVectorWidth, writer.maxGwvw(kernel))
75
76 # handle mfma 4x4 instruction
77 matrixInstM = kernel["MatrixInstM"] * kernel["MatrixInstBM"] if (kernel["MatrixInstM"] == 4) else kernel["MatrixInstM"]
78 matrixInstN = kernel["MatrixInstN"] * kernel["MatrixInstBN"] if (kernel["MatrixInstN"] == 4) else kernel["MatrixInstN"]
79 matrixInstBM = 1 if (kernel["MatrixInstM"] == 4) else kernel["MatrixInstBM"]
80 matrixInstBN = 1 if (kernel["MatrixInstN"] == 4) else kernel["MatrixInstBN"]
81
82 outputsPerThread = matrixInstM * matrixInstN // kernel["WavefrontSize"]
83
84 # handle SourceSwap
85 totalTT0 = matrixInstBM * kernel["MIWaveTile"][0]
86 totalTT1 = matrixInstBN * kernel["MIWaveTile"][1]
87
88 totalTT0 = totalTT0 if kernel["SourceSwap"] else (totalTT0 * outputsPerThread)
89 totalTT1 = (totalTT1 * outputsPerThread) if kernel["SourceSwap"] else totalTT1
90 vectorWidth0 = kernel["VectorWidthA"] if kernel["SourceSwap"] else kernel["VectorWidthA"] * kernel["MIOutputVectorWidth"]
91 vectorWidth1 = kernel["VectorWidthB"] * kernel["MIOutputVectorWidth"] if kernel["SourceSwap"] else kernel["VectorWidthB"]
92
93 for tt1 in range(0, ceil(totalTT1//vectorWidth1)):
94 for vc1 in range(0, vectorWidth1):
95 for tt0 in range(0, ceil(totalTT0//vectorWidth0)):
96 for vc0 in range(0, vectorWidth0, storeVectorWidth): # note step by storeVectorWidth
97 element = (tt1, tt0, vc1, vc0)
98 elements.append(element)
99
100 return (storeVectorWidth, elements)
101
102 """
103 Partition thread-tile into writeElements for store code
104 This function creates the writeElement mapping for full tiles
105 (ie non-edge cases)
106 """
107 def __call__(self, writer, kernel, edge):
108 if kernel["GlobalSplitU"] == 0:
109 (storeVectorWidth, elements) = self.getElements(writer, kernel, edge)
110 return (storeVectorWidth, elements, storeVectorWidth, elements)
111 else:
112 gsuBackup = kernel["GlobalSplitU"]
113 kernel["GlobalSplitU"] = 2
114 (storeVectorWidth, elements) = self.getElements(writer, kernel, edge)
115 kernel["GlobalSplitU"] = 1
116 (storeVectorWidth_1, elements_1) = self.getElements(writer, kernel, edge)
117 kernel["GlobalSplitU"] = gsuBackup
118 return (storeVectorWidth, elements, storeVectorWidth_1, elements_1)