Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#!/usr/bin/env python
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
 
import argparse
import io  # noqa: F401
import os
import pathlib
from collections import defaultdict
 
import onnxruntime.capi.onnxruntime_pybind11_state as rtpy
 
 
def format_version_range(v):
    if v[1] >= 2147483647:
        return str(v[0]) + "+"
    else:
        if v[0] == v[1]:
            return str(v[0])
        else:
            return "[" + str(v[0]) + ", " + str(v[1]) + "]"
 
 
def format_type_constraints(tc):
    tcstr = ""
    firsttcitem = True
    for tcitem in tc:
        if firsttcitem:
            firsttcitem = False
        else:
            tcstr += ", "
        tcstr += tcitem
    return tcstr
 
 
def format_param_strings(params):
    firstparam = True
    s = ""
    if params:
        for param in sorted(params):
            if firstparam:
                firstparam = False
            else:
                s += "<br><br>or<br><br>"
            s += param
    return s
 
 
def expand_providers(provider_filter: [str]):
    providers = set()
    if provider_filter:
        for provider in provider_filter:
            p = provider.lower()
            if not p.endswith("executionprovider"):
                p += "executionprovider"
            providers.add(p)
 
    return providers
 
 
def load_plugin_ep_kernel_defs(plugin_eps):
    """Register plugin EP libraries and return their kernel defs.
 
    Args:
        plugin_eps: list of "name:path" strings, e.g.
            ["CUDAExecutionProvider:/path/to/lib.so"]
 
    Returns:
        list of KernelDef objects from the plugin EPs.
    """
    if not plugin_eps:
        return []
 
    import onnxruntime as ort  # noqa: PLC0415
 
    defs = []
    for spec in plugin_eps:
        if ":" not in spec:
            print(f"Warning: invalid --plugin-ep spec '{spec}' (expected NAME:PATH), skipping")
            continue
        ep_name, lib_path = spec.split(":", 1)
        try:
            ort.register_execution_provider_library(ep_name, lib_path)
        except Exception as e:
            if "already registered" not in str(e).lower():
                print(f"Warning: failed to register plugin EP '{ep_name}': {e}")
                continue
        try:
            defs.extend(rtpy.get_registered_ep_kernel_defs(ep_name))
        except Exception as e:
            print(f"Warning: failed to get kernel defs for plugin EP '{ep_name}': {e}")
 
    return defs
 
 
def main(output_path: pathlib.Path, provider_filter: [str], plugin_eps=None):
    providers = expand_providers(provider_filter)
 
    with open(output_path, "w", newline="", encoding="utf-8") as fout:
        fout.write("## Supported Operators and Data Types\n")
        fout.write(
            "*This file is automatically generated from the registered kernels by "
            "[this script](https://github.com/microsoft/onnxruntime/blob/main/tools/python/gen_opkernel_doc.py).\n"
            "Do not modify directly.*\n\n"
        )
        fout.write(
            "### Version Notation\n\n"
            "The **OpSet Version** column uses the following notation:\n\n"
            "- `N` — registered only for opset N (e.g., `13`).\n"
            "- `[N, M]` — registered for opsets N through M inclusive (e.g., `[6, 12]`).\n"
            "- `N+` — registered for opset N and all later opsets until superseded by a newer"
            " kernel registration (e.g., `16+`).\n\n"
        )
        opdef = rtpy.get_all_operator_schema()
        paramdict = {}
        for schema in opdef:
            inputs = schema.inputs
            domain = schema.domain
            if not domain:
                domain = "ai.onnx"
            fullname = domain + "." + schema.name
            paramstr = ""
            firstinput = True
            if inputs:
                for inp in inputs:
                    if firstinput:
                        firstinput = False
                    else:
                        paramstr += "<br> "
                    paramstr += f"*in* {inp.name}:**{inp.typeStr}**"
 
            outputs = schema.outputs
            if outputs:
                for outp in outputs:
                    if firstinput:
                        firstinput = False
                    else:
                        paramstr += "<br> "
                    paramstr += f"*out* {outp.name}:**{outp.typeStr}**"
 
            paramstr += ""
            paramset = paramdict.get(fullname)
            if paramset is None:
                paramdict[fullname] = set()
 
            paramdict[fullname].add(paramstr)
 
        index = defaultdict(lambda: defaultdict(lambda: defaultdict(list)))
        for op in rtpy.get_all_opkernel_def():
            domain = op.domain
            if not domain:
                domain = "ai.onnx"
            index[op.provider][domain][op.op_name].append(op)
 
        # Include kernel defs from plugin EPs
        for op in load_plugin_ep_kernel_defs(plugin_eps):
            domain = op.domain
            if not domain:
                domain = "ai.onnx"
            index[op.provider][domain][op.op_name].append(op)
 
        # TOC
        fout.write("## Execution Providers\n\n")
        for provider in sorted(index.keys()):
            if providers and provider.lower() not in providers:
                continue
            fout.write(f"- [{provider}](#{provider.lower()})\n")
        fout.write("\n---------------")
 
        for provider, domainmap in sorted(index.items()):
            if providers and provider.lower() not in providers:
                continue
 
            fout.write(f'\n\n<a name="{provider.lower()}"/>\n\n')
            fout.write(f"## Operators implemented by {provider}\n\n")
            fout.write("| Op Name | Parameters | OpSet Version | Types Supported |\n")
            fout.write("|---------|------------|---------------|-----------------|\n")
            for domain, namemap in sorted(domainmap.items()):
                fout.write("|**Operator Domain:** *" + domain + "*||||\n")
                for name, ops in sorted(namemap.items()):
                    version_type_index = defaultdict(lambda: defaultdict(set))
                    for op in ops:
                        for tname, tclist in op.type_constraints.items():
                            for c in tclist:
                                version_type_index[op.version_range][tname].add(c)
 
                    namefirsttime = True
                    for version_range, typemap in sorted(version_type_index.items(), key=lambda x: x[0], reverse=True):
                        if namefirsttime:
                            params = paramdict.get(domain + "." + name, None)
                            fout.write("|" + name + "|" + format_param_strings(params) + "|")
                            namefirsttime = False
                        else:
                            fout.write("|||")
                        fout.write(format_version_range(version_range) + "|")
                        for i, (tname, tcset) in enumerate(sorted(typemap.items())):
                            tnameindex = i + 1
                            tclist = []
                            for tc in sorted(tcset):
                                tclist.append(tc)
                            fout.write("**" + tname + "** = " + format_type_constraints(tclist))
                            if tnameindex < len(typemap):
                                fout.write("<br/> ")
                        fout.write("|\n")
 
                fout.write("| |\n| |\n")
 
 
if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="ONNX Runtime Operator Kernel Documentation Generator")
    parser.add_argument(
        "--providers",
        nargs="+",
        help="Filter to specified execution providers. Case-insensitive. "
        "Matches provider names from <ORT>/include/onnxruntime/core/graph/constants.h'. "
        "'ExecutionProvider' is automatically appended as needed. "
        "e.g. `--providers cpu cuda` will match CPUExecutionProvider and CUDAExecutionProvider.",
    )
    parser.add_argument(
        "--plugin-ep",
        nargs="+",
        dest="plugin_eps",
        help="Register plugin EP libraries and include their kernels. "
        "Each entry is NAME:PATH, e.g. "
        "'CUDAExecutionProvider:/path/to/libonnxruntime_providers_cuda.so'.",
    )
    parser.add_argument(
        "--output_path",
        help="output markdown file path",
        type=pathlib.Path,
        required=True,
        default=os.path.join(os.path.dirname(os.path.realpath(__file__)), "OperatorKernels.md"),
    )
    args = parser.parse_args()
 
    main(args.output_path, args.providers, args.plugin_eps)