From 544227ef40dc226707d2c97b41cf0ee0b6111d39 Mon Sep 17 00:00:00 2001 From: Eric Kunze Date: Mon, 13 Feb 2023 16:19:34 -0800 Subject: Add enumerations to TOSA specification Currently used by RESIZE and AVG_POOL2D Change-Id: I4f401ac092fcf426e6d57b3729943135f634a31e Signed-off-by: Eric Kunze --- chapters/enumerations.adoc | 16 ++++++++++++++++ tools/genspec.py | 13 ++++++++++++- tools/get_descriptions.py | 2 ++ tools/tosa.py | 17 +++++++++++++++++ tosa.xml | 16 ++++++++++++++-- tosa.xsd | 20 ++++++++++++++++++++ tosa_spec.adoc | 2 ++ 7 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 chapters/enumerations.adoc diff --git a/chapters/enumerations.adoc b/chapters/enumerations.adoc new file mode 100644 index 0000000..24a1708 --- /dev/null +++ b/chapters/enumerations.adoc @@ -0,0 +1,16 @@ +// +// This confidential and proprietary software may be used only as +// authorised by a licensing agreement from ARM Limited +// (C) COPYRIGHT 2023 ARM Limited +// ALL RIGHTS RESERVED +// The entire notice above must be reproduced on all authorised +// copies and copies may only be made to the extent permitted +// by a licensing agreement from ARM Limited. + +== Enumerations + +Where enumerated types are specified for an operator, the provided value must be a valid enumerant for that type. +The included tables provide reference values for the enumerations. +Implementations do not need to use these values, they may subtitue other values as long as they are functionally equivalent. + +include::{generated}/enums.adoc[] diff --git a/tools/genspec.py b/tools/genspec.py index 38ae6e3..2bc1283 100755 --- a/tools/genspec.py +++ b/tools/genspec.py @@ -8,6 +8,15 @@ class TOSASpecAsciidocGenerator: def __init__(self, spec): self.spec = spec + def generate_enum(self, enum, file): + file.write(f"\n=== {enum.name}\n") + file.write(f"{enum.description}\n") + file.write("|===\n") + file.write("|Name|Value|Description\n\n") + for val in enum.values: + file.write(f"|{val[0]}|{val[1]}|{val[2]}\n") + file.write("|===\n") + def generate_operator(self, op, file): file.write("\n*Arguments:*\n") file.write("\n|===\n") @@ -75,7 +84,9 @@ class TOSASpecAsciidocGenerator: for op in group.operators: with open(os.path.join(opdir, op.name + ".adoc"), "w") as f: self.generate_operator(op, f) - + with open(os.path.join(outdir, "enums.adoc"), 'w') as f: + for enum in self.spec.enums: + self.generate_enum(enum, f) if __name__ == "__main__": import argparse diff --git a/tools/get_descriptions.py b/tools/get_descriptions.py index 0a39a19..2f29879 100755 --- a/tools/get_descriptions.py +++ b/tools/get_descriptions.py @@ -49,5 +49,7 @@ for name in args.filenames: # skip comments elif re.match(r"\w*\/\/", text): continue + elif re.match(r"include::", text): + continue else: print(text) diff --git a/tools/tosa.py b/tools/tosa.py index 74d43d6..9af0756 100644 --- a/tools/tosa.py +++ b/tools/tosa.py @@ -7,6 +7,12 @@ class TOSAOperatorArgumentCategory: self.name = name self.profiles = profiles +class TOSAEnum: + def __init__(self, name, description, values): + self.name = name + self.description = description + self.values = values + class TOSAOperatorArgument: def __init__(self, name, description, categories, ty, shape, levellimits): @@ -44,12 +50,15 @@ class TOSASpec: tree = ET.parse(xmlpath) self.xmlroot = tree.getroot() self.operatorgroups = [] + self.enums = [] self.__load_spec() def __load_spec(self): self.__load_version() for group in self.xmlroot.findall("./operators/operatorgroup"): self.operatorgroups.append(self.__load_operator_group(group)) + for enum in self.xmlroot.findall("./enum"): + self.enums.append(self.load_enum(enum)) def __load_version(self): version = self.xmlroot.find("./version") @@ -112,3 +121,11 @@ class TOSASpec: argcats.append(TOSAOperatorArgumentCategory(cat[0], cat[1].split(","))) return TOSAOperatorArgument(name, desc, argcats, argtype, shape, levellimits) + + def load_enum(self, arg): + name = arg.get("name") + desc = arg.get("description").strip() + values = [] + for val in arg.findall("enumval"): + values.append((val.get("name"), val.get("value"), val.get("description"))) + return TOSAEnum(name, desc, values) \ No newline at end of file diff --git a/tosa.xml b/tosa.xml index f7d865c..7effd1c 100644 --- a/tosa.xml +++ b/tosa.xml @@ -69,7 +69,7 @@ - + Enumerated type, must be one of INT32, FP16, FP32, as defined in the Supported Data Types table for this operation @@ -1977,7 +1977,7 @@ used. [border_y, border_x] - + BILINEAR or NEAREST @@ -2283,4 +2283,16 @@ used. + + + + + + + + + + + + diff --git a/tosa.xsd b/tosa.xsd index 7bf2c40..8c1e2b5 100644 --- a/tosa.xsd +++ b/tosa.xsd @@ -126,6 +126,25 @@ + + + + + + + + + + + + + + + + + + + @@ -213,6 +232,7 @@ + diff --git a/tosa_spec.adoc b/tosa_spec.adoc index 64611f0..60404d9 100644 --- a/tosa_spec.adoc +++ b/tosa_spec.adoc @@ -22,6 +22,8 @@ include::chapters/introduction.adoc[] include::chapters/operators.adoc[] +include::chapters/enumerations.adoc[] + include::chapters/pseudocode.adoc[] include::chapters/appendix_a.adoc[] -- cgit v1.2.1