Debian Codegraph @

tensilelite/Tensile/KernelWriterBase.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 abc import ABC
26 from abc import abstractmethod
27 from copy import deepcopy
28
29 KERNEL_HELPER_FILENAME_CPP: str = "Kernels.cpp"
30 KERNEL_HELPER_FILENAME_H: str = "Kernels.h"
31
32 class KernelWriterBase(ABC):
33
34 def __init__(self):
35 super().__init__()
36
37 self.state = {}
38
39 self.endLine = "\n"
40 self.getGroupIdStr = "hc_get_group_id"
41 self.getNumGroupsStr = "hc_get_num_groups"
42 self.getLocalIdStr = "hc_get_workitem_id"
43 self.getGlobalIdStr = "hc_get_workitem_absolute_id"
44 self.sharedDeclStr = "__shared__ "
45 self.sharedPtrStr = ""
46 self.globalPtrStr = ""
47 self.macFStr = "fmaf"
48 self.macDStr = "fma"
49 self.int64Str = "int64_t"
50 self.uint64Str = "uint64_t"
51 self.vectorComponents = ["x", "y", "z", "w"]
52 self.atomicCasStr = "atomicCAS"
53 self.volatileStr = ""
54 self.deviceFunctionStr = "__device__ "
55
56
57 @abstractmethod
58 def getKernelName(self):
59 pass
60
61
62 @abstractmethod
63 def getHeaderFileString(self):
64 pass
65
66
67 @abstractmethod
68 def getSourceFileString(self):
69 pass
70
71
72 ##########################
73 # make class look like dict
74 def keys(self):
75 return list(self.state.keys())
76
77 def __len__(self):
78 return len(self.state)
79
80 def __iter__(self):
81 return iter(self.state)
82
83 def __getitem__(self, key):
84 return self.state[key]
85
86 def __setitem__(self, key, value):
87 self.state[key] = value
88
89 def __str__(self):
90 return self.getKernelName()
91
92 def __repr__(self):
93 return self.__str__()
94
95 def getAttributes(self):
96 return deepcopy(self.state)
97
98 def __hash__(self):
99 return hash(str(self))
100
101 def __eq__(self, other):
102 return isinstance(other, KernelWriterBase) and str(self) == str(other)
103
104 def __ne__(self, other):
105 result = self.__eq__(other)
106 if result is NotImplemented:
107 return result
108 return not result