| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
from copy import deepcopy |
| 24 |
|
| 25 |
from .Activation import ActivationType |
| 26 |
from .KernelWriterBase import KernelWriterBase |
| 27 |
|
| 28 |
class KernelWriterActivationEnumHeader(KernelWriterBase): |
| 29 |
|
| 30 |
def __init__(self, state): |
| 31 |
super().__init__() |
| 32 |
self.state["ProblemType"] = deepcopy(state["ProblemType"]) |
| 33 |
|
| 34 |
self.actGradientPrefix = "" |
| 35 |
self.actExportType = ActivationType.Export.NORMAL |
| 36 |
if self.state["ProblemType"]["Gradient"]: |
| 37 |
self.actGradientPrefix = "Gradient" |
| 38 |
self.actExportType = ActivationType.Export.GRADONLY |
| 39 |
|
| 40 |
|
| 41 |
self.language = "HIP" |
| 42 |
self.kernelName = self.getKernelName() |
| 43 |
|
| 44 |
def keys(self): |
| 45 |
return self.getKernelName() |
| 46 |
|
| 47 |
@staticmethod |
| 48 |
def kernelName(solution): |
| 49 |
state = solution._state if hasattr(solution, "_state") else solution.state |
| 50 |
s = "Gradient" if state["ProblemType"]["Gradient"] else "" |
| 51 |
return "Tensile%sActivationEnum_%s"%(s, |
| 52 |
state["ProblemType"]["ActivationComputeDataType"].toChar()) |
| 53 |
|
| 54 |
def getKernelName(self): |
| 55 |
return KernelWriterActivationEnumHeader.kernelName(self) |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
def getSourceFileString(self): |
| 60 |
fileString = "// This is a dummy file." |
| 61 |
return (0, fileString) |
| 62 |
|
| 63 |
def getHeaderFileString(self): |
| 64 |
fileString = "" |
| 65 |
activationCDataType = self.state["ProblemType"]["ActivationComputeDataType"] |
| 66 |
supportedBy = ActivationType.SupportedBy.ALL if self.state["ProblemType"]["ActivationType"] == 'all' else ActivationType.SupportedBy.HIPBLASLT |
| 67 |
enumName = "%sActivationType_%s"%(self.actGradientPrefix, activationCDataType.toChar()) |
| 68 |
fileString += "namespace Tensile {\n" |
| 69 |
fileString += "enum class %s : uint32_t\n"%enumName |
| 70 |
fileString += "{\n" |
| 71 |
enumList = ActivationType.getEnumStrList(activationCDataType, supportedBy, exportType=self.actExportType) |
| 72 |
for idx, enumStr in enumerate(enumList): |
| 73 |
fileString += " %s = %s,\n"%(ActivationType(enumStr).toEnum(), ActivationType.getEnumIndex(enumStr)) |
| 74 |
fileString += "};\n" |
| 75 |
fileString += "} // End of namespace Tensile\n" |
| 76 |
|
| 77 |
return fileString |