Debian Codegraph @

tensilelite/Tensile/KernelWriterReduction.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 copy import deepcopy
26
27 from .Common import INDEX_CHARS
28 from .Common.DataType import DataType
29 from .KernelWriterBase import KernelWriterBase
30
31 class KernelWriterReduction(KernelWriterBase):
32
33 def __init__(self, state):
34 super().__init__()
35
36 self.state["ProblemType"] = deepcopy(state["ProblemType"])
37
38 # C dimensions
39 self.indicesStr = ""
40 for i in range(0, self.state["ProblemType"]["NumIndicesC"]):
41 c = INDEX_CHARS[i].lower()
42 self.indicesStr += INDEX_CHARS[i].lower()
43
44 # derive parameter
45 self.language = "HIP"
46 self.kernelName = self.getKernelName()
47 self.datatype = self.state["ProblemType"]["ComputeDataType"].toDevice(self.language)
48 if self.state["ProblemType"]["DataType"].isInt8() and self.state["ProblemType"]["ComputeDataType"].isSingle() and self.state["ProblemType"]["HighPrecisionAccumulate"]:
49 self.datatype = DataType('int32').toDevice(self.language)
50
51 # Currently dummy
52 def kernelBody(self):
53 kStr = ""
54 return kStr
55
56 @staticmethod
57 def kernelName(solution, btype):
58 state = solution._state if hasattr(solution, "_state") else solution.state
59 # C dimensions
60 indexChars = INDEX_CHARS
61 indicesStr = ""
62 for i in range(0, state["ProblemType"]["NumIndicesC"]):
63 c = indexChars[i].lower()
64 indicesStr += indexChars[i].lower()
65 name = "D"
66 name += indicesStr
67 name += "_%s%s"%(btype.toChar(), state["ProblemType"]["ComputeDataType"].toChar())
68 name += "_Reduction"
69 return name
70
71
72 def getKernelName(self):
73 return KernelWriterReduction.kernelName(self, self.state["ProblemType"]["BiasDataType"])
74
75
76 def getHeaderFileString(self):
77 fileString = "" # CHeader
78
79 # C dimensions
80 indicesStr = ""
81 for i in range(0, self.state["ProblemType"]["NumIndicesC"]):
82 c = INDEX_CHARS[i].lower()
83 if c == 'k':
84 continue
85 indicesStr += INDEX_CHARS[i].lower()
86
87 computeStr = self.state["ProblemType"]["ComputeDataType"].toDevice(self.language)
88 computeChar = self.state["ProblemType"]["ComputeDataType"].toChar()
89 MTVW = [[256, 1, 1], [128, 2, 1], [64, 4, 1], [32, 8, 1], [16, 16, 1], [8, 32, 1], [32, 32, 4]]
90 dstStr = self.state["ProblemType"]["BiasDataType"].toDevice(self.language)
91 dstChar = self.state["ProblemType"]["BiasDataType"].toChar()
92 for mtvw in MTVW:
93 fileString += "extern \"C\" __global__ void D%s_%s%s_MT%dx%d_VW%d_Reduction(%s *in, %s* out, int m, int n, int strideJ)\n"%(self.indicesStr, dstChar, computeChar, mtvw[0], mtvw[1], mtvw[2], computeStr, dstStr)
94 fileString += "{\n"
95 fileString += " reductionKernel_%s<%s, %s, %d, %d, %d>(in, out, m, n, strideJ);\n"%(self.indicesStr, computeStr, dstStr, mtvw[0], mtvw[1], mtvw[2])
96 fileString += "}\n"
97
98 fileString += "\n"
99
100 return fileString
101
102
103 def getSourceFileString(self):
104 fileString = ""
105 fileString += self.kernelBody()
106
107 return (0, fileString)