Debian Codegraph @

tensilelite/Tensile/Hardware.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 . import Properties
26 from Tensile.Common.Architectures import isaToGfx
27 import copy
28
29 class HardwarePredicate(Properties.Predicate):
30 # TODO- And also FromISA() is hard to detect CU-fallback case.
31 # Perhaps we can always use FromHardware(). FromISA() is not used so far.
32 @classmethod
33 def FromISA(cls, isa):
34 gfxArch = isaToGfx(tuple(isa))
35 return cls("AMDGPU", value=cls("Processor", value=gfxArch))
36
37 @classmethod
38 def FromHardware(cls, isa, cuCount=None):
39 gfxArch = isaToGfx(tuple(isa))
40 if cuCount == None:
41 return cls("AMDGPU", value=cls("Processor", value=gfxArch))
42 else:
43 return cls("AMDGPU", value=cls.And([cls("Processor", value=gfxArch),
44 cls("CUCount", value=cuCount)]))
45
46 def __lt__(self, other):
47 # Use superclass logic for TruePreds
48 if other.tag == 'TruePred' or self.tag == 'TruePred':
49 return super().__lt__(other)
50
51 # Compute unit counts are embedded as 'And' with
52 # 'Processor' and 'ComputeUnitCount' as children
53 if self.value.tag == 'And':
54 myAndPred = self.value
55 myProcPred = next(iter(x for x in myAndPred.value if x.tag == "Processor"), None)
56 myCUPred = next(iter(x for x in myAndPred.value if x.tag == "CUCount"), None)
57 myCUCount = myCUPred.value if myCUPred != None else 0
58 else:
59 myProcPred = self.value
60 myCUCount = 0
61
62 if other.value.tag == 'And':
63 otherAndPred = other.value
64 otherProcPred = next(iter(x for x in otherAndPred.value if x.tag == "Processor"), None)
65 otherCUPred = next(iter(x for x in otherAndPred.value if x.tag == "CUCount"), None)
66 otherCUCount = otherCUPred.value if otherCUPred != None else 0
67 else:
68 otherProcPred = other.value
69 otherCUCount = 0
70
71 # If CU properties are empty, then compare processor predicates
72 if myCUCount == otherCUCount == 0:
73 # Make sure that we have valid processor preds
74 assert myProcPred != None and otherProcPred != None, "Missing processor predicate"
75 assert myProcPred.tag == otherProcPred.tag == "Processor", "Invalid processor predicate"
76
77 # Downgrade to base class so that we don't recurse
78 myProcPredCopy = copy.deepcopy(myProcPred)
79 otherProcPredCopy = copy.deepcopy(otherProcPred)
80 myProcPredCopy.__class__ = otherProcPredCopy.__class__ = Properties.Predicate
81 return myProcPredCopy < otherProcPredCopy
82
83 # Higher priority given to higher CU count
84 return myCUCount > otherCUCount