diff options
author | Eric Kunze <eric.kunze@arm.com> | 2023-02-13 16:19:34 -0800 |
---|---|---|
committer | Eric Kunze <eric.kunze@arm.com> | 2023-04-14 16:13:27 -0700 |
commit | 544227ef40dc226707d2c97b41cf0ee0b6111d39 (patch) | |
tree | 871a149f9e7c686a5c18e61ac5194d6eee5f970d | |
parent | 9bb5f5dd6b3999e46eb32ee2a897cc643c86c96d (diff) | |
download | specification-544227ef40dc226707d2c97b41cf0ee0b6111d39.tar.gz |
Add enumerations to TOSA specification
Currently used by RESIZE and AVG_POOL2D
Change-Id: I4f401ac092fcf426e6d57b3729943135f634a31e
Signed-off-by: Eric Kunze <eric.kunze@arm.com>
-rw-r--r-- | chapters/enumerations.adoc | 16 | ||||
-rwxr-xr-x | tools/genspec.py | 13 | ||||
-rwxr-xr-x | tools/get_descriptions.py | 2 | ||||
-rw-r--r-- | tools/tosa.py | 17 | ||||
-rw-r--r-- | tosa.xml | 16 | ||||
-rw-r--r-- | tosa.xsd | 20 | ||||
-rw-r--r-- | tosa_spec.adoc | 2 |
7 files changed, 83 insertions, 3 deletions
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 @@ -69,7 +69,7 @@ <levellimit value="pad_left" limit="MAX_KERNEL"/> <levellimit value="pad_right" limit="MAX_KERNEL"/> </argument> - <argument category="attribute" name="acc_size" type="acc_t" shape="-"> + <argument category="attribute" name="acc_size" type="acc_size_t" shape="-"> <description>Enumerated type, must be one of INT32, FP16, FP32, as defined in the Supported Data Types table for this operation</description> </argument> <argument category="attribute" name="input_zp" type="in_out_t" shape="-"> @@ -1977,7 +1977,7 @@ used.</description> <argument category="attribute" name="border" type="int16_t*" shape="[2]"> <description>[border_y, border_x]</description> </argument> - <argument category="attribute" name="mode" type="mode_t" shape="-"> + <argument category="attribute" name="mode" type="resize_t" shape="-"> <description>BILINEAR or NEAREST</description> </argument> <argument category="output" name="output" type="out_t*" shape="[N,OH,OW,C]"> @@ -2283,4 +2283,16 @@ used.</description> </operator> </operatorgroup> </operators> + + <enum name="resize_t" description="Valid resize types"> + <enumval value="0" name="NEAREST_NEIGHBOR" description="Nearest neighbor resize"/> + <enumval value="1" name="BILINEAR" description="Bilinear resize"/> + </enum> + + <enum name="acc_size_t" description="Allowed accumulator sizes"> + <enumval value="0" name="INT32" description="32-bit integer"/> + <enumval value="1" name="FP16" description="16-bit floating-point"/> + <enumval value="2" name="FP32" description="32-bit floating-point"/> + </enum> + </tosa> @@ -126,6 +126,25 @@ <!-- TODO pattern for attribute name --> <!-- TODO enumerations/patterns for attribute type --> <!-- TODO enumerations/patterns for attribute shape --> + +<xs:element name="enumval"> + <xs:complexType> + <xs:attribute name="name" type="xs:string"/> + <xs:attribute name="value" type="xs:integer"/> + <xs:attribute name="description" type="xs:string"/> + </xs:complexType> +</xs:element> + +<xs:element name="enum"> + <xs:complexType> + <xs:sequence> + <xs:element ref="enumval" minOccurs="1" maxOccurs="unbounded"/> + </xs:sequence> + <xs:attribute name="name" type="xs:string" use="required"/> + <xs:attribute name="description" type="xs:string" use="required"/> + </xs:complexType> +</xs:element> + <xs:element name="argument"> <xs:complexType> <xs:sequence> @@ -213,6 +232,7 @@ <xs:element ref="profiles"/> <xs:element ref="levels"/> <xs:element ref="operators"/> + <xs:element ref="enum" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> </xs:element> 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[] |