Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Onnx Onnx Operator Sets Registry

From Leeroopedia


Knowledge Sources
Domains Operator Registry, Schema Management, Operator Versioning
Last Updated 2026-02-10 00:00 GMT

Overview

operator_sets.h declares all operator schemas for the standard ONNX operator set across opset versions 1 through 26, providing forward declarations, per-version operator set classes, and registration functions for the complete ONNX operator catalog.

Description

This header file serves as the central registry definition for all standard ONNX (ai.onnx domain) operators. It is organized into three major sections:

Forward declarations at the top of the file declare all operator schema classes using the ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME macro. These declarations cover every operator across all opset versions, including operators like Abs, Add, Conv, Gemm, MatMul, Relu, Reshape, and many more. Each forward declaration follows the naming convention OperatorName_Onnx_verN where N is the opset version.

Operator set classes (OpSet_Onnx_ver1 through OpSet_Onnx_ver26) each contain a static ForEachSchema template method that applies a given function to every operator schema introduced or updated in that specific opset version. These classes group operators by the version in which they were added or had breaking changes.

Registration functions at the bottom provide two overloads of RegisterOnnxOperatorSetSchema: one that registers all opset versions (used for full initialization) and one that registers only schemas up to a specified target version (used for version-specific loading). The file also provides DeregisterOnnxOperatorSetSchema for cleanup and IsOnnxStaticRegistrationDisabled for querying the static registration mode.

The registration functions call RegisterOpSetSchema for each version in descending order, which is important for correct version resolution when loading a specific target opset version.

Usage

This header is included by schema.cc during the ONNX library initialization process. When static registration is enabled (the default), all operator schemas are automatically registered when the OpSchemaRegistry::map() function is first called. When static registration is disabled (via __ONNX_DISABLE_STATIC_REGISTRATION), the linking module must explicitly call RegisterOnnxOperatorSetSchema() to register the desired operator schemas.

Code Reference

Source Location

Signature

// Registration functions
ONNX_API inline void RegisterOnnxOperatorSetSchema();
ONNX_API inline void RegisterOnnxOperatorSetSchema(int target_version, bool fail_duplicate_schema = true);
ONNX_API inline void DeregisterOnnxOperatorSetSchema();
ONNX_API bool IsOnnxStaticRegistrationDisabled();

// Per-version operator set class pattern (ver1 through ver26)
class OpSet_Onnx_verN {
 public:
  static void ForEachSchema(std::function<void(OpSchema&&)> fn) {
    fn(GetOpSchema<ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(Onnx, N, OperatorName)>());
    // ... one call per operator in this version
  }
};

Import

#include "onnx/defs/operator_sets.h"

I/O Contract

Inputs

Name Type Required Description
target_version int No When provided to the version-specific overload, only schemas with since_version less than or equal to this value are registered. A value of 0 means register all versions.
fail_duplicate_schema bool No When true (default), throws an error if a schema with the same name, domain, and version is already registered.

Outputs

Name Type Description
(side effect) OpSchemaRegistry All operator schemas for the ai.onnx domain are registered in the global OpSchemaRegistry singleton, making them available for lookup via OpSchemaRegistry::Schema().

Usage Examples

#include "onnx/defs/operator_sets.h"

// Register all ONNX operator schemas (all versions)
ONNX_NAMESPACE::RegisterOnnxOperatorSetSchema();

// Register only operators up to opset version 13
ONNX_NAMESPACE::RegisterOnnxOperatorSetSchema(13);

// Deregister all ONNX operator schemas
ONNX_NAMESPACE::DeregisterOnnxOperatorSetSchema();

// Check if static registration is disabled
if (ONNX_NAMESPACE::IsOnnxStaticRegistrationDisabled()) {
    // Manually register operators
    ONNX_NAMESPACE::RegisterOnnxOperatorSetSchema();
}

// Access a specific operator's schema after registration
const auto* schema = ONNX_NAMESPACE::OpSchemaRegistry::Schema("Add", 13, "");

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment