Debian Codegraph @

tensilelite/Tensile/Components/MAC_I8_HPA.py

raw symbols SCIP
1 ################################################################################
2 #
3 # Copyright (C) 2022-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 from rocisa.code import Module
26 from rocisa.enum import DataTypeEnum
27 from ..Common.DataType import DataType
28 from ..Component import Component, MAC
29
30 class FMA_I8_HPA(MAC):
31 @staticmethod
32 def asmCaps(caps):
33 return True
34
35 kernel = {
36 "ProblemType": {"DataType": DataType(DataTypeEnum.Int8), "HighPrecisionAccumulate": True},
37 }
38
39 def __call__(self, writer, m, innerUnroll):
40 kernel = writer.states.kernel
41 priority = Component.Priority.find(writer)
42 spacePerReg = writer.states.bpr // writer.states.bpeAB
43 elemPerReg = min(kernel['VectorWidth'], spacePerReg)
44
45 module = Module("FMA_I8_HPA")
46 module.addComment(self.commentHeader())
47
48 for a in range(kernel["ThreadTile0"]-1, -1, -1):
49 for iui in range(0, innerUnroll):
50 src = a // elemPerReg
51 idx = a % elemPerReg
52 sStr = f'v[vgprValuA_X{m}_I{iui}+{src}]'
53 tStr = f'v[vgprValuA_X{m}_I{iui}+{a}]'
54 module.addInst("v_lshlrev_b32", tStr, {(spacePerReg-idx-1)*8}, sStr, "")
55 module.add(priority(writer, 1, "Raise priority while processing macs"))
56 module.addInst("v_ashrrev_i32", tStr, {(spacePerReg -1)*8}, tStr, "")
57
58 for b in range(kernel["ThreadTile1"]-1, -1, -1):
59 for iui in range(0, innerUnroll):
60 src = b // elemPerReg
61 idx = b % elemPerReg
62 sStr = f'v[vgprValuB_X{m}_I{iui}+{src}]'
63 tStr = f'v[vgprValuB_X{m}_I{iui}+{b}]'
64 module.addInst("v_lshlrev_b32", tStr, {(spacePerReg-idx-1)*8}, sStr, "")
65 module.add(priority(writer, 1, "Raise priority while processing macs"))
66 module.addInst("v_ashrrev_i32", tStr, {(spacePerReg -1)*8}, tStr, "")
67
68 ThreadTile0 = kernel["ThreadTile0"]
69 for b in range(0, kernel["ThreadTile1"]):
70 for a in range(0, kernel["ThreadTile0"]):
71 for iui in range(0, innerUnroll):
72 cStr = f'v[vgprValuC + {a} + {b}*{ThreadTile0}]'
73 aStr = f'v[vgprValuA_X{m}_I{iui} + {a}]'
74 bStr = f'v[vgprValuB_X{m}_I{iui} + {b}]'
75 module.addInst("v_mad_i32_i24", cStr, aStr, bStr, cStr, "")
76 module.add(priority(writer, 1, "Raise priority while processing macs"))
77
78 module.add(priority(writer, 0, "Reset priority after macs"))
79
80 return module