Skip to content

Commit

Permalink
Updated script for generating supported ops table
Browse files Browse the repository at this point in the history
  • Loading branch information
gkrivor committed Feb 21, 2025
1 parent e92f8f0 commit 87c7249
Show file tree
Hide file tree
Showing 2 changed files with 249 additions and 223 deletions.
65 changes: 45 additions & 20 deletions src/frontends/onnx/docs/check_supported_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,25 @@ def run_in_ci():
"MMDEPLOY_DOMAIN":"mmdeploy"
}

hdr = ""
with open(supported_ops_doc, 'rt') as src:
table_line = 0
for line in src:
if table_line <= 2:
hdr += line
if line.count('|') == 6:
table_line += 1
if table_line > 2:
row = [cell.strip() for cell in line.split('|')] # Split line by "|" delimeter and remove spaces
domain = row[1]
if not domain in ops:
ops[domain] = {}
opname = row[2]
if not opname in ops[domain]:
ops[domain][opname] = {'supported':[], 'defined': row[4], 'limitations':row[5]}

documentation_errors = []

for file_path in files:
with open(file_path.as_posix(), "r") as src:
reg_macro = None
Expand All @@ -70,44 +89,50 @@ def run_in_ci():
# Registration macro has been found, trying parse it
m = op_regex.search(reg_macro)
if m is None:
raise Exception(f"Registration in file {file_path.as_posix()} is corrupted {reg_macro}")
documentation_errors.append(f"Registration in file {file_path.as_posix()} is corrupted {reg_macro}, please check correctness")
if ');' in line: reg_macro = None
continue
domain = m.group(5)[2:].strip() if not m.group(5) is None else ""
if not domain in known_domains:
raise Exception(f"Unknown domain found in file {file_path.as_posix()} with identifier {domain}")
documentation_errors.append(f"Unknown domain found in file {file_path.as_posix()} with identifier {domain}, please modify check_supported_ops.py if needed")
if ');' in line: reg_macro = None
continue
domain = known_domains[domain]
opname = m.group(2)
opset = m.group(3)
if not domain in ops:
ops[domain] = {}
if not m.group(2) in ops[domain]:
ops[domain][opname] = []
documentation_errors.append(f"Domain {domain} is missing in a list of documented operations supported_ops.md, update it by adding operation description")
if ');' in line: reg_macro = None
continue
if not opname in ops[domain]:
documentation_errors.append(f"Operation {domain if domain=='' else domain + '.'}{opname} is missing in a list of documented operations supported_ops.md, update it by adding operation description")
if ');' in line: reg_macro = None
continue
if opset.startswith('OPSET_SINCE'):
ops[domain][opname].append(int(opset[12:]))
ops[domain][opname]['supported'].append(int(opset[12:]))
elif opset.startswith('OPSET_IN'):
ops[domain][opname].append(int(opset[9:]))
ops[domain][opname]['supported'].append(int(opset[9:]))
elif opset.startswith('OPSET_RANGE'):
ops[domain][opname].append(int(opset[12:].split(',')[0]))
ops[domain][opname]['supported'].append(int(opset[12:].split(',')[0]))
elif opset.startswith('{'):
ops[domain][opname].append(int(opset[1:].split(',')[0]))
ops[domain][opname]['supported'].append(int(opset[1:].split(',')[0]))
else:
raise Exception(f"Line {line} in file {file_path.as_posix()} contains an unknown opset definition {opset}")
documentation_errors.append(f"Domain {domain} is missing in a list of documented operations supported_ops.md, update it by adding operation description")
if ');' in line: reg_macro = None
continue
if ');' in line:
reg_macro = None

hdr = ""
with open(supported_ops_doc, 'rt') as src:
table_line = 0
for line in src:
hdr += line
if line.count('|') == 5:
table_line += 1
if table_line == 2:
break
if len(documentation_errors) > 0:
for errstr in documentation_errors:
print('[ONNX Frontend] ' + errstr)
raise Exception('[ONNX Frontend] failed: due to documentation errors')

with open(supported_ops_doc, 'wt') as dst:
dst.write(hdr)
for domain, ops in ops.items():
for op_name in sorted(list(ops.keys())):
dst.write(f"|{domain:<24}|{op_name:<56}|{', '.join([str(i) for i in sorted(ops[op_name], reverse=True)]):<24}|{'':<32}|\n")
data = ops[op_name]
dst.write(f"|{domain:<24}|{op_name:<56}|{', '.join([str(i) for i in sorted(data['supported'], reverse=True)]):<24}|{data['defined']:<32}|{data['limitations']:<32}|\n")

print("Data collected and stored")
Loading

0 comments on commit 87c7249

Please sign in to comment.