| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
from . import Properties |
| 26 |
from Tensile.Common.Architectures import isaToGfx |
| 27 |
import copy |
| 28 |
|
| 29 |
class HardwarePredicate(Properties.Predicate): |
| 30 |
|
| 31 |
|
| 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 |
|
| 48 |
if other.tag == 'TruePred' or self.tag == 'TruePred': |
| 49 |
return super().__lt__(other) |
| 50 |
|
| 51 |
|
| 52 |
|
| 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 |
|
| 72 |
if myCUCount == otherCUCount == 0: |
| 73 |
|
| 74 |
assert myProcPred != None and otherProcPred != None, "Missing processor predicate" |
| 75 |
assert myProcPred.tag == otherProcPred.tag == "Processor", "Invalid processor predicate" |
| 76 |
|
| 77 |
|
| 78 |
myProcPredCopy = copy.deepcopy(myProcPred) |
| 79 |
otherProcPredCopy = copy.deepcopy(otherProcPred) |
| 80 |
myProcPredCopy.__class__ = otherProcPredCopy.__class__ = Properties.Predicate |
| 81 |
return myProcPredCopy < otherProcPredCopy |
| 82 |
|
| 83 |
|
| 84 |
return myCUCount > otherCUCount |