Debian Codegraph @

tensilelite/Tensile/Components/CustomSchedule.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 cop-
9 # ies of the Software, and to permit persons to whom the Software is furnished
10 # to do so, subject to the following conditions:
11 #
12 # The above copyright notice and this permission notice shall be included in all
13 # copies or substantial portions of the Software.
14 #
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IM-
16 # PLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNE-
20 # CTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ################################################################################
22
23 from rocisa.code import Module, TextBlock, StructuredModule, KernelBody
24 from rocisa.container import vgpr, sgpr, SMEMModifiers, replaceHolder, EXEC,\
25 VOP3PModifiers, ContinuousRegister
26 from rocisa.instruction import BufferLoadB128, BufferLoadB32, BufferLoadB64, \
27 BufferLoadD16B16, BufferLoadD16U8, DSLoad2B32, DSLoad2B64, DSLoadB128, \
28 DSLoadB32, DSLoadB64, DSLoadB64TrB16, DSLoadInstruction, DSLoadU16, \
29 DSLoadU8, DSStore2B32, DSStore2B64, DSStoreB128, DSStoreB16, DSStoreB256, \
30 DSStoreB32, DSStoreB64, DSStoreB8, DSStoreInstruction, FlatLoadB128, FlatLoadB32, \
31 FlatLoadB64, FlatStoreB128, FlatStoreB32, FlatStoreB64, Instruction, \
32 MFMAInstruction, SBarrier, SBranch, SCBranchSCC0, SCBranchSCC1, SCmpLeU32, \
33 SMovB32, SMFMAInstruction, SNop, SSetPrior, SSetRegIMM32B32, SSubU32, SWaitCnt, SWaitAlu, \
34 SLongBranchPositive, VFmaMixF32, VMadMixF32, VMovB32
35 from rocisa.instruction import SAddU32, SAddCU32, SCmpEQU32, SCSelectB32, SSubBU32
36 from Tensile.Common import IsaVersion
37
38 class ScheduleInfo:
39 numCodePaths: int
40 numMfma: int
41 def __init__(self, numCodePaths, numMfma, optSchedule, syncCode, mfmaReorder = []):
42 self.numCodePaths = numCodePaths
43 self.numMfma = numMfma
44 self.optSchedule = optSchedule
45 self.syncCode = syncCode
46 self.mfmaReorder = mfmaReorder
47
48 def removeComments(module):
49 retModule = Module()
50 for i in module.flatitems():
51 if type(i) != TextBlock and not isinstance(i, (SCBranchSCC1, SNop)):
52 retModule.add(i)
53 return retModule.flatitems()
54
55
56 def customMainLoopSchedule(writer, kernel, tensorParametersA, tensorParametersB, \
57 globalReadIncACode, globalReadIncBCode, \
58 LRCodeA, PackCodeA, LRCodeB, PackCodeB,\
59 LRSwapA, LRSwapB, \
60 globalReadA, globalReadB, \
61 LWSwapA, LWSwapB, \
62 mfmaCode, loopCounterCode, \
63 ):
64
65 module = Module()
66
67 globalReadIncACode = removeComments(globalReadIncACode)
68 globalReadIncBCode = removeComments(globalReadIncBCode)
69
70 numLoopIter = kernel["LoopIters"]
71
72 if numLoopIter > 1:
73 for uIdx in range(0, numLoopIter):
74 LRCodeA[uIdx] = removeComments(LRCodeA[uIdx])
75 LRCodeB[uIdx] = removeComments(LRCodeB[uIdx])
76 PackCodeA[uIdx] = removeComments(PackCodeA[uIdx])
77 PackCodeB[uIdx] = removeComments(PackCodeB[uIdx])
78 else: # numIterPLR = 0 case
79 numLoopIter = 2
80 # Split instruction stream for numiterPLR=0
81 # First half is done in subiter 1, second half is done in subiter 0
82 def splitForPLR(oldModule):
83 newList0 = []
84 newList1 = []
85 numInst = len(oldModule.flatitems())
86 for ii in range(numInst):
87 if ii < numInst // 2:
88 newList1.append(oldModule.flatitems()[ii])
89 else:
90 newList0.append(oldModule.flatitems()[ii])
91 return [newList0, newList1]
92
93 LRCodeA = splitForPLR(LRCodeA[0])
94 LRCodeB = splitForPLR(LRCodeB[0])
95 PackCodeA = splitForPLR(PackCodeA[0])
96 PackCodeB = splitForPLR(PackCodeB[0])
97
98
99 LRSwapA = removeComments(LRSwapA)
100 LRSwapB = removeComments(LRSwapB)
101 globalReadA = removeComments(globalReadA)
102 globalReadB = removeComments(globalReadB)
103 localWriteA = removeComments(writer.codes.localWriteA)
104 localWriteB = removeComments(writer.codes.localWriteB)
105 LWSwapA = removeComments(LWSwapA)
106 LWSwapB = removeComments(LWSwapB)
107 loopCounterCode = removeComments(loopCounterCode)
108 mfmaCode = removeComments(mfmaCode)
109
110 _, opt1 = hasCustomSchedule(kernel)
111 numCodePath = opt1.numCodePaths
112 assert opt1.numMfma == len(mfmaCode)
113
114 for _, indexList in opt1.optSchedule.items():
115 assert len(indexList) <= opt1.numCodePaths
116
117 if len(opt1.mfmaReorder) > 0:
118 mfmaCode = [mfmaCode[x] for x in opt1.mfmaReorder]
119
120 idMap = {
121 'GRIncA' : globalReadIncACode,
122 'GRIncB' : globalReadIncBCode,
123 'GRA' : globalReadA,
124 'GRB' : globalReadB,
125 'LWA' : localWriteA,
126 'LWB' : localWriteB,
127 'LRSA' : LRSwapA,
128 'LRSB' : LRSwapB,
129 'LWSA' : LWSwapA,
130 'LWSB' : LWSwapB,
131 'LCC' : loopCounterCode,
132 }
133
134
135 for uIdx in range(0, numLoopIter):
136 idMap["LRA%u"%uIdx] = LRCodeA[uIdx]
137 idMap["LRB%u"%uIdx] = LRCodeB[uIdx]
138 idMap["PackA%u"%uIdx] = PackCodeA[uIdx]
139 idMap["PackB%u"%uIdx] = PackCodeB[uIdx]
140
141 idMap['SYNC'] = opt1.syncCode
142
143 def convOptToStream(sched):
144 InstStreams = dict()
145 def addToStream(key, indexList, InstructionList):
146 if indexList:
147 for l in indexList:
148 assert len(l) == len(InstructionList), \
149 "Index list length (%u) for %s does not match instruction list length (%u)"%(len(l), key, len(InstructionList))
150 InstStreams[key] = [indexList, InstructionList]
151
152 for key,stream in opt1.optSchedule.items():
153 addToStream(key, stream, idMap[key])
154
155 return InstStreams
156
157 InstStreams = convOptToStream(opt1)
158
159
160 module.add(TextBlock(".macro MAINLOOP ID useGR=1 usePLR=1 useGRInc=1 useLoop=1\n"))
161 #module.add(SBarrier(comment="debug"))
162
163 lastIter = numLoopIter - 1
164
165 miIndex = 0
166 for mi in mfmaCode:
167 module.addComment0("mfmaIndex:%u"%(miIndex))
168 module.add(mi)
169
170 def scheduleInst(indexList, instructionList):
171 ret = [None]*len(indexList)
172 totalNumInst = len(instructionList)
173 for i in range(len(indexList)):
174 if indexList[i]: # For specific codepath
175 cc = 0
176 # Add slower, but allow reordering of instructions
177 while miIndex in indexList[i]:
178 ind = indexList[i].index(miIndex)
179 if cc == 0:
180 ret[i] = Module()
181 ret[i].add(instructionList[ind])
182 cc += 1
183 indexList[i][ind] = -1
184 if ret.count(None) == len(ret):
185 return [None]
186 else:
187 return ret
188
189 needIfMacro = False
190 ToSched = dict()
191 for k, stream in InstStreams.items():
192 ToSched[k] = scheduleInst(stream[0], stream[1])
193 if len(ToSched[k]) > 1:
194 needIfMacro = True
195
196 def scheduleInst1(instList, macroGuard=""):
197 if len(instList) == 1:
198 if instList[0] != None:
199 if macroGuard != "":
200 module.add(TextBlock(macroGuard))
201 module.add(instList[0])
202 if macroGuard != "":
203 module.add(TextBlock(".endif\n"))
204
205 for k,ts in ToSched.items():
206 if k in ['GRIncA', 'GRIncB']: # check for global read inc
207 scheduleInst1(ts, ".if \\useGRInc == 1\n")
208 elif k in ['GRA', 'GRB', 'LWSA', 'LWSB']: # check for global reads
209 scheduleInst1(ts, ".if \\useGR == 1\n")
210 elif k in ['LRA%u'%lastIter, 'LRB%u'%lastIter, 'LRSA', 'LRSB']: # check for next prefetch
211 scheduleInst1(ts, ".if \\usePLR == 1\n")
212 elif k in ['LCC']: # check for next prefetch
213 scheduleInst1(ts, ".if \\useLoop == 1\n")
214 else:
215 scheduleInst1(ts)
216
217 if needIfMacro:
218 for codepath in range(numCodePath):
219 if codepath == 0:
220 module.add(TextBlock(".if \\ID == %u\n"%codepath))
221 else:
222 module.add(TextBlock(".elseif \\ID == %u\n"%codepath))
223
224 def scheduleInst2(instList, macroGuard=""):
225 if len(instList) == numCodePath:
226 if instList[codepath] != None:
227 if macroGuard != "":
228 module.add(TextBlock(macroGuard))
229 module.add(instList[codepath])
230 if macroGuard != "":
231 module.add(TextBlock(".endif\n"))
232
233 for k,ts in ToSched.items():
234 if k in ['GRIncA', 'GRIncB']: # check for global read inc
235 scheduleInst2(ts, ".if \\useGRInc == 1\n")
236 elif k in ['GRA', 'GRB', 'LWSA', 'LWSB']: # check for global reads
237 scheduleInst2(ts, ".if \\useGR == 1\n")
238 elif k in ['LRA%u'%lastIter, 'LRB%u'%lastIter, 'LRSA', 'LRSB']: # check for next prefetch
239 scheduleInst2(ts, ".if \\usePLR == 1\n")
240 elif k in ['LCC']: # check for next prefetch
241 scheduleInst2(ts, ".if \\useLoop == 1\n")
242 else:
243 scheduleInst2(ts)
244
245 if codepath == numCodePath - 1:
246 module.add(TextBlock(".endif\n"))
247 miIndex += 1
248
249 module.add(TextBlock(".endm\n"))
250 return module, numCodePath
251
252
253 def hasCustomSchedule(kernel):
254
255 if not kernel["UseCustomMainLoopSchedule"]:
256 return False, None
257 # Only support kernels using matrix instructions for now
258 if not kernel["EnableMatrixInstruction"]:
259 return False, None
260 if not kernel["ISA"] == IsaVersion(9,5,0):
261 return False, None
262
263 is16bit = kernel["ProblemType"]["DataType"].isHalf() or kernel["ProblemType"]["DataType"].isBFloat16()
264 is8bit = kernel["ProblemType"]["DataType"].isInt8() or kernel["ProblemType"]["DataType"].is8bitFloat()
265 isMixed = kernel["ProblemType"]["DataTypeA"].numBytes() != kernel["ProblemType"]["DataTypeB"].numBytes()
266
267 MT0, MT1, DU, PGR, PLR, DTL = kernel["MacroTile0"], kernel["MacroTile1"], kernel["DepthU"], kernel["PrefetchGlobalRead"], kernel["PrefetchLocalRead"], kernel["DirectToLds"]
268 GRVWA, GRVWB = kernel["GlobalReadVectorWidthA"], kernel["GlobalReadVectorWidthB"]
269 LRVW = kernel["LocalReadVectorWidth"]
270 MI = kernel["MatrixInstruction"]
271 MIWG = kernel["MIWaveGroup"]
272 useLDSTr = kernel["LDSTrInst"]
273
274 is256x256x64DTL = [MT0, MT1, DU, PGR, PLR, DTL] == [256, 256, 64, 2, 1, True]
275 is192x256x64DTL = [MT0, MT1, DU, PGR, PLR, DTL] == [192, 256, 64, 2, 1, True]
276 is256x256x128DTL = [MT0, MT1, DU, PGR, PLR, DTL] == [256, 256, 128, 2, 0, True]
277
278
279 transA = kernel["ProblemType"]["TransposeA"]
280 transB = kernel["ProblemType"]["TransposeB"]
281
282 isNN = transA == False and transB == False
283 isNT = transA == False and transB == True
284 isTT = transA == True and transB == True
285 isTN = transA == True and transB == False
286
287 # Custom main loop scheduling for 256x256x64 16bit
288 if is256x256x64DTL and is16bit and not isMixed and ([GRVWA, GRVWB, LRVW] == [8,8,8]) and MI == [16,16,32,1] and MIWG == [2,2]:
289
290 kernel["MfmaInitCVgprs"] = True
291
292 optSchedule = dict()
293 syncCode = []
294
295 if isTN:
296 optSchedule = {
297 'SYNC' : [[19,20, 50,51, 67,68, 104, 105]],
298 'GRIncA' : [[0,1,2,3,4,5,6,7,8]],
299 'GRIncB' : [[9,10,11,12,13,14,15,16,17]],
300 'LRA0' : [[0,2,4,6,8,10,12,14],
301 [1,3,5,7,9,11,13,15]],
302 'LRB0' : [[24,27,30,33,36,38,40,42],
303 [22,25,28,31,34,37,39,41]],
304 'GRA' : [[21,22, 23,25, 26,28, 29,31, 32,34, 35,52, 53,55, 56,58],
305 [21,23, 24,26, 27,29, 30,32, 33,35, 36,53, 54,56, 57,59]],
306 'GRB' : [[59,61, 62,64, 65,85, 86,87, 88,89, 94,96, 98,100, 102,124],
307 [60,62, 63,65, 66,84, 85,86, 87,88, 93,95, 97,99, 103,123]],
308 'LRA1' : [[69,71,73,75,77,79,81,83],
309 [70,72,74,76,78,80,82,90]],
310 'LRB1' : [[106,108,110,112,114,116,118,120],
311 [107,109,111,113,115,117,119,121]],
312 'LRSA' : [[16]],
313 'LRSB' : [[83]],
314 'LWSA' : [[125]],
315 'LWSB' : [[125]],
316 'LCC' : [[126, 126]],
317 }
318 syncCode = [SWaitCnt(dscnt=0, vlcnt=-1, vscnt=-1, comment="Wait for LRA0 to complete"),
319 SBarrier(comment=""),
320 SWaitCnt(dscnt=0, vlcnt=-1, vscnt=-1, comment="Wait for LRB0 to complete"),
321 SBarrier(comment=""),
322 SWaitCnt(dscnt=-1, vlcnt=(2 + 8 + 8), vscnt=-1, comment="Wait for previous GRA to completely"),
323 SBarrier(comment=""),
324 SWaitCnt(dscnt=-1, vlcnt=15, vscnt=-1, comment="Wait for previous GRA to completely"),
325 SBarrier(comment="")]
326 elif isNT and not useLDSTr:
327 kernel["UsePLRPack"] = True
328
329 optSchedule = {
330 'SYNC' : [[12,13, 36,44, 56,59, 66,68, 73,92]],
331 'GRIncA' : [[0,1,2,3,4,5,6,7,8]],
332 'GRIncB' : [[28,29,30,31,32,33,34,35,36]],
333 'LRA0' : [[0,0,2,2,4,4,6,6],
334 [1,1,3,3,5,5,7,7]],
335 'LRB0' : [[8,8,10,10,15,15,18,18],
336 [9,9,11,11,14,14,17,17]],
337 'GRA' : [[14,14, 17,17, 20,20, 23,23, 26,26, 45,45, 48,48, 51,51],
338 [15,15, 18,18, 21,21, 24,24, 27,27, 46,46, 49,49, 52,52]],
339 'GRB' : [[54,54, 57,57, 87,87,90,90,93,93,96,96,99,99, 123,123],
340 [55,55, 58,58, 88,88,91,91,94,94,97,97,100,100, 124,124]],
341 'LRA1' : [[60,60,62,62,64,64,66,66],
342 [61,61,63,63,65,65,67,67]],
343 'LRB1' : [[69,69,71,71,73,73,75,75],
344 [70,70,72,72,74,74,76,76]],
345 'LRSA' : [[59]],
346 'LRSB' : [[59]],
347 'LWSA' : [[125]],
348 'LWSB' : [[125]],
349 'LCC' : [[126, 126]],
350 'PackA0' : [[16,16, 19,19, 21,21, 22,22, 24,24, 25,25, 27,27, 28,28, 29,29, 30,30, 31,31, 32,32, 33,33, 34,34, 35,35, 36,36],
351 [16,16, 19,19, 20,20, 22,22, 23,23, 25,25, 26,26, 28,28, 29,29, 30,30, 31,31, 32,32, 33,33, 34,34, 35,35, 36,36]],
352 'PackB0' : [[37,37, 38,38, 39,39, 40,40, 41,41, 42,42, 43,43, 46,46, 47,47, 49,49, 50,50, 52,52, 53,53, 55,55, 56,56, 58,58],
353 [37,37, 38,38, 39,39, 40,40, 41,41, 42,42, 43,43, 45,45, 47,47, 48,48, 50,50, 51,51, 53,53, 54,54, 56,56, 57,57]],
354 'PackA1' : [[74,74, 76,76, 77,77, 78,78, 79,79, 80,80, 81,81, 82,82, 83,83, 84,84, 85,85, 86,86, 88,88, 89,89, 91,91, 92,92],
355 [75,75, 77,77, 78,78, 79,79, 80,80, 81,81, 82,82, 83,83, 84,84, 85,85, 86,86, 87,87, 89,89, 90,90, 92,92, 93,93]],
356 'PackB1' : [[94,94, 95,95, 97,97, 98,98, 100,100, 101,101, 102,102, 103,103, 104,104, 105,105, 106,106, 107,107, 108,108, 109,109, 110,110, 111,111],
357 [95,95, 96,96, 98,98, 99,99, 101,101, 102,102, 103,103, 104,104, 105,105, 106,106, 107,107, 108,108, 109,109, 110,110, 111,111, 112,112]],
358 }
359 syncCode = [SWaitCnt(dscnt=4, vlcnt=-1, vscnt=-1, comment="Wait for LRA0 to complete"),
360 SBarrier(comment=""),
361 SWaitCnt(dscnt=0, vlcnt=-1, vscnt=-1, comment="Wait for LRB0 to complete"),
362 SBarrier(comment=""),
363 SWaitCnt(dscnt=-1, vlcnt=17, vscnt=-1, comment="Wait for GRA to complete"),
364 SBarrier(comment=""),
365 SWaitCnt(dscnt=-1, vlcnt=9, vscnt=-1, comment="Wait for GRB to complete"),
366 SBarrier(comment=""),
367 SWaitCnt(dscnt=4, vlcnt=-1, vscnt=-1, comment="Wait for LRA1 to complete"),
368 SWaitCnt(dscnt=0, vlcnt=-1, vscnt=-1, comment="Wait for LRB1 to complete")]
369 elif (isNN or isTT) and not useLDSTr:
370 kernel["UsePLRPack"] = True
371
372 optSchedule = {
373 'SYNC' : [[8, 12,13, 36,44, 56,59, 66,68, 73]],
374 'GRIncA' : [[0,1,2,3,4,5,6,7,8]],
375 'GRIncB' : [[28,29,30,31,32,33,34,35,36]],
376 'LRA0' : [[0,0,2,2,4,4,6,6],
377 [1,1,3,3,5,5,7,7]],
378 'LRB0' : [[9,11, 15,18,21,24,27,30],
379 [10,12, 14,17,20,23,26,29]],
380 'GRA' : [[14,14, 17,17, 20,20, 23,23, 26,26, 45,45, 48,48, 51,51],
381 [15,15, 18,18, 21,21, 24,24, 27,27, 46,46, 49,49, 52,52]],
382 'GRB' : [[54,54, 57,57, 87,87,90,90,93,93,96,96,99,99, 123,123],
383 [55,55, 58,58, 88,88,91,91,94,94,97,97,100,100, 124,124]],
384 'LRA1' : [[60,60,62,62,64,64,66,66],
385 [61,61,63,63,65,65,67,67]],
386 'LRB1' : [[68,70,72,74,76,78,80,82],
387 [69,71,73,75,77,79,81,83]],
388 'LRSA' : [[59]],
389 'LRSB' : [[59]],
390 'LWSA' : [[125]],
391 'LWSB' : [[125]],
392 'LCC' : [[126, 126]],
393 'PackA0' : [[8,8, 16,16, 19,19, 22,22, 25,25, 28,28, 29,29, 31,31, 32,32, 33,33, 34,34, 35,35, 36,36, 37,37, 38,38, 39,39]],
394 'PackA1' : [[75,75, 77,77, 79,79, 81,81, 83,83, 84,84, 85,85, 86,86, 88,88, 89,89, 91,91, 92,92, 94,94, 95,95, 97,97, 98,98],
395 [74,74, 76,76, 78,78, 80,80, 82,82, 84,84, 85,85, 86,86, 87,87, 89,89, 90,90, 92,92, 93,93, 95,95, 96,96, 98,98]],
396 }
397 syncCode = [SWaitCnt(dscnt=4, vlcnt=-1, vscnt=-1, comment="Wait for LRA0 first half to complete"),
398 SWaitCnt(dscnt=1, vlcnt=-1, vscnt=-1, comment="Wait for LRA0 to complete"),
399 SBarrier(comment=""),
400 SWaitCnt(dscnt=0, vlcnt=-1, vscnt=-1, comment="Wait for LRB0 to complete"),
401 SBarrier(comment=""),
402 SWaitCnt(dscnt=-1, vlcnt=17, vscnt=-1, comment="Wait for GRA to complete"),
403 SBarrier(comment=""),
404 SWaitCnt(dscnt=-1, vlcnt=9, vscnt=-1, comment="Wait for GRB to complete"),
405 SBarrier(comment=""),
406 SWaitCnt(dscnt=4, vlcnt=-1, vscnt=-1, comment="Wait for LRA1 to complete")]
407 if isTT:
408 kernel["SwapGlobalReadOrder"] = True
409
410 optSchedule['GRIncA'], optSchedule['GRIncB'] = optSchedule['GRIncB'], optSchedule['GRIncA']
411 optSchedule['LRA0'], optSchedule['LRB0'] = optSchedule['LRB0'], optSchedule['LRA0']
412 optSchedule['LRA1'], optSchedule['LRB1'] = optSchedule['LRB1'], optSchedule['LRA1']
413 optSchedule['PackB0'] = optSchedule['PackA0']
414 optSchedule['PackB1'] = optSchedule['PackA1']
415 del optSchedule['PackA0'], optSchedule['PackA1']
416 else:
417 return False, None
418
419
420 numMfma = 128
421 opt1 = ScheduleInfo(2, numMfma, optSchedule, syncCode)
422 return True, opt1
423 elif is256x256x128DTL and is8bit and not isMixed and ([GRVWA, GRVWB, LRVW] == [16, 16, 16]) and MI == [16,16,128,1] and MIWG == [2,2]:
424
425 kernel["MfmaInitCVgprs"] = True
426
427 optSchedule = dict()
428 syncCode = []
429
430 if isTN:
431 optSchedule = {
432 'SYNC' : [[6,7, 20,21, 46,47, 61]],
433 'GRIncA' : [[0,1,2,3,4,4,4,4,4]],
434 'GRIncB' : [[5,5,5,5,5,6,6,6,6]],
435 'LRA0' : [[0,0, 1,1, 2,2, 3,3]],
436 'GRA' : [[8,8,9,9,10,10,11,11,12,12, 23,23,24,24,25,25]],
437 'LRB0' : [[13,13,14,14,15,15,16,16]],
438 'LRA1' : [[48,48,49,49,50,50,51,51]],
439 'LRB1' : [[52,52,54,54,55,55,56,56]],
440 'GRB' : [[26,26,27,27, 39,39,40,40,41,41,42,42,43,43, 53,53]],
441 'LCC' : [[60, 60]],
442 'LRSA' : [[17]],
443 'LRSB' : [[17]],
444 'LWSA' : [[57]],
445 'LWSB' : [[57]],
446 }
447 syncCode = [SWaitCnt(dscnt=0, vlcnt=-1, vscnt=-1, comment="Wait for LRA0/LRB0 to complete"),
448 SBarrier(comment=""),
449 SWaitCnt(dscnt=0, vlcnt=-1, vscnt=-1, comment="Wait for LRA0/LRB0 to complete"),
450 SBarrier(comment=""),
451 SWaitCnt(dscnt=-1, vlcnt=15, vscnt=-1, comment="Wait for GRA to complete"),
452 SBarrier(comment=""),
453 SWaitCnt(dscnt=0, vlcnt=-1, vscnt=-1, comment="Wait for PLR to complete")]
454 else:
455 return False, None
456
457 numMfma = 64
458 # B0A0, B0A1, B1A0, B1A1
459 mfmaReorder = [0,1,2,3, 8,9,10,11, 16,17,18,19, 24,25,26,27,
460 4,5,6,7, 12,13,14,15, 20,21,22,23, 28,29,30,31,
461 32,33,34,35, 40,41,42,43, 48,49,50,51, 56,57,58,59,
462 36,37,38,39, 44,45,46,47, 52,53,54,55, 60,61,62,63]
463 opt1 = ScheduleInfo(1, numMfma, optSchedule, syncCode, mfmaReorder)
464 return True, opt1
465 elif is192x256x64DTL and is16bit and not isMixed and ([GRVWA, GRVWB, LRVW] == [8, 8, 8]) and MI == [16,16,32,1] and MIWG == [2,2]:
466
467 kernel["MfmaInitCVgprs"] = True
468
469 optSchedule = dict()
470 syncCode = []
471 if isNN and useLDSTr:
472 # Note: A/B Global read orders are swapped
473 # i.e. GRA contains GR for B
474 optSchedule = {
475 'SYNC' : [[20,21,23,25,27,29,31,33,46,57,58,94],
476 [20,21,24,26,28,30,32,34,47,58,58,94]],
477 'GRIncA' : [[0,1,2,3,4,5,6,7,8]],
478 'GRIncB' : [[9,10,11,12,13,14,15,16,17]],
479 'LRB0' : [[0,0,1,1,2,2,6,8],
480 [3,3,4,4,5,5,7,9]],
481 'LRA0' : [[10,12,14,16,18,23,35,37,39,41,43,45],
482 [11,13,15,17,19,22,36,38,40,42,44,46]],
483 'LWA' : [[23,25,27,29,31,33],
484 [24,26,28,30,32,34]],
485 'GRA' : [[22,22,24,24,26,26,28,28,30,30, 42,42,43,43,45,45],
486 [23,23,25,25,27,27,29,29,31,31, 43,43,44,44,46,46]],
487 'GRB' : [[54, 56, 58, 60, 62, 64],
488 [55, 57, 59, 61, 63, 65]],
489 'LRSA' : [[47]],
490 'LRSB' : [[37]],
491 'LWSB' : [[47]], # For B
492 'LWSA' : [[52]], # For A
493 'LRB1' : [[59,59,61,61,63,63,65,67],
494 [60,60,62,62,64,64,66,68]],
495 'LRA1' : [[69,71,73,75,77,79,81,83,85,85,87,87],
496 [70,72,74,76,78,80,82,84,86,86,88,88]],
497 'LCC' : [[95, 95]],
498 }
499 syncCode = [SWaitCnt(dscnt=5, vlcnt=-1, vscnt=-1, comment="Wait for LRB0 to complete"),
500 SBarrier(comment=""),
501 SWaitCnt(dscnt=-1, vlcnt=5, vscnt=-1, comment="Wait for LRB0 to complete"),
502 SWaitCnt(dscnt=-1, vlcnt=5, vscnt=-1, comment="Wait for LRB0 to complete"),
503 SWaitCnt(dscnt=-1, vlcnt=5, vscnt=-1, comment="Wait for LRB0 to complete"),
504 SWaitCnt(dscnt=-1, vlcnt=5, vscnt=-1, comment="Wait for LRB0 to complete"),
505 SWaitCnt(dscnt=-1, vlcnt=5, vscnt=-1, comment="Wait for LRB0 to complete"),
506 SWaitCnt(dscnt=-1, vlcnt=5, vscnt=-1, comment="Wait for LRB0 to complete"),
507 SWaitCnt(dscnt=0, vlcnt=-1, vscnt=-1, comment="Wait for LRB0 to complete"),
508 SWaitCnt(dscnt=-1, vlcnt=10, vscnt=-1, comment="Wait for LRB0 to complete"),
509 SBarrier(comment=""),
510 SWaitCnt(dscnt=0, vlcnt=-1, vscnt=-1, comment="Wait for LRB0 to complete"),]
511
512 else:
513 return False, None
514
515 numMfma = 96
516 opt1 = ScheduleInfo(2, numMfma, optSchedule, syncCode)
517 return True, opt1
518
519 return False, None