tvm
Loading...
Searching...
No Matches
Public Member Functions | List of all members
tvm::OpDef Class Reference

Noncopyable temporary builder for a canonical Op; see Op for the example. More...

#include <op.h>

Collaboration diagram for tvm::OpDef:

Public Member Functions

TVM_TIRX_DLL OpDef (const ffi::String &name)
 Get or create the named Op without changing its documentation.
 
TVM_TIRX_DLL OpDef (const ffi::String &name, const ffi::String &doc)
 Get or create the named Op and set its documentation.
 
 OpDef (const OpDef &)=delete
 
OpDef & operator= (const OpDef &)=delete
 
 OpDef (OpDef &&)=delete
 
OpDef & operator= (OpDef &&)=delete
 
Op op () const
 Get the canonical operator.
 
void expose () const
 Request API exposure after this operator's signature and attributes are complete.
 
TVM_TIRX_DLL OpDef & add_arg (const ffi::String &name, const ffi::String &doc)
 Append a required value-argument descriptor.
 
template<typename AttrsType >
OpDef & attrs_type ()
 Set the attribute object type key and runtime index together.
 
TVM_TIRX_DLL OpDef & set_attrs_type_key (const ffi::String &key)
 Resolve and set the attribute object type key and runtime index together.
 
TVM_TIRX_DLL OpDef & add_ty_arg (const ffi::String &name, const ffi::String &doc)
 Append a descriptor for a type argument in Call.ty_args.
 
template<typename... Specs>
OpDef & signature (const Specs &... specs)
 Register a complete typed Call signature and its validator.
 
template<typename ValueType >
OpDef & set_attr (const ffi::String &attr_name, const ValueType &value, bool override=false)
 Register an extensible attribute, rejecting duplicates unless overridden.
 
template<typename ValueType , typename Value , std::enable_if_t<(std::is_convertible_v< Value &&, ValueType > &&((!std::is_same_v< std::decay_t< Value >, ffi::Any > &&!std::is_same_v< std::decay_t< Value >, ffi::AnyView >)||std::is_same_v< ValueType, ffi::Any >||std::is_same_v< ValueType, ffi::AnyView >)), int > = 0>
OpDef & set_attr (ffi::reflection::AttrKey< ValueType > key, Value &&value, bool override=false)
 Register a value using the key's declared type.
 
template<auto Fn, typename ValueType >
OpDef & set_native_fn_attr (ffi::reflection::AttrKey< ValueType > key, bool override=false)
 Register a native callback using the key's declared adapter.
 
OpDef & set_validator (ffi::reflection::NativeFunctionView< void(const CallObj *)> validator, bool override=false)
 Register a validator that checks a Call with this operator.
 
TVM_TIRX_DLL OpDef & reset_attr (const ffi::String &attr_name)
 Remove the current attribute value, with no priority fallback.
 
template<typename ValueType >
OpDef & reset_attr (ffi::reflection::AttrKey< ValueType > key)
 Remove the value named by a typed key. Cached views observe the removal.
 

Detailed Description

Noncopyable temporary builder for a canonical Op; see Op for the example.

Constructor & Destructor Documentation

◆ OpDef() [1/4]

TVM_TIRX_DLL tvm::OpDef::OpDef ( const ffi::String &  name)
explicit

Get or create the named Op without changing its documentation.

Parameters
nameThe canonical operator name.

◆ OpDef() [2/4]

TVM_TIRX_DLL tvm::OpDef::OpDef ( const ffi::String &  name,
const ffi::String &  doc 
)

Get or create the named Op and set its documentation.

Parameters
nameThe canonical operator name.
docOperator documentation, replacing any existing documentation.

◆ OpDef() [3/4]

tvm::OpDef::OpDef ( const OpDef &  )
delete

◆ OpDef() [4/4]

tvm::OpDef::OpDef ( OpDef &&  )
delete

Member Function Documentation

◆ add_arg()

TVM_TIRX_DLL OpDef & tvm::OpDef::add_arg ( const ffi::String &  name,
const ffi::String &  doc 
)

Append a required value-argument descriptor.

Parameters
nameArgument name.
docArgument documentation.
Returns
This builder. Without a variadic descriptor, this is part of the complete list.

◆ add_ty_arg()

TVM_TIRX_DLL OpDef & tvm::OpDef::add_ty_arg ( const ffi::String &  name,
const ffi::String &  doc 
)

Append a descriptor for a type argument in Call.ty_args.

Parameters
nameType-argument name.
docType-argument documentation.
Returns
This builder. Inference retains responsibility for type-argument counts.

◆ attrs_type()

template<typename AttrsType >
OpDef & tvm::OpDef::attrs_type ( )
inline

Set the attribute object type key and runtime index together.

Template Parameters
AttrsTypeThe attribute object node type.
Returns
This builder.

◆ expose()

void tvm::OpDef::expose ( ) const
inline

Request API exposure after this operator's signature and attributes are complete.

Note
Does nothing if the optional receiver was absent on Op::Expose's first call.

◆ op()

Op tvm::OpDef::op ( ) const
inline

Get the canonical operator.

Returns
A copied handle, safe after this builder dies.

◆ operator=() [1/2]

OpDef & tvm::OpDef::operator= ( const OpDef &  )
delete

◆ operator=() [2/2]

OpDef & tvm::OpDef::operator= ( OpDef &&  )
delete

◆ reset_attr() [1/2]

TVM_TIRX_DLL OpDef & tvm::OpDef::reset_attr ( const ffi::String &  attr_name)

Remove the current attribute value, with no priority fallback.

Parameters
attr_nameAttribute column name; missing columns and values are ignored.
Returns
This builder. Existing cached maps observe the removal.

◆ reset_attr() [2/2]

template<typename ValueType >
OpDef & tvm::OpDef::reset_attr ( ffi::reflection::AttrKey< ValueType >  key)
inline

Remove the value named by a typed key. Cached views observe the removal.

◆ set_attr() [1/2]

template<typename ValueType >
OpDef & tvm::OpDef::set_attr ( const ffi::String &  attr_name,
const ValueType &  value,
bool  override = false 
)
inline

Register an extensible attribute, rejecting duplicates unless overridden.

Template Parameters
ValueTypeThe attribute value type.
Parameters
attr_nameAttribute column name.
valueNon-null attribute value.
overrideWhether to replace an existing value; no prior value is retained.
Returns
This builder. Existing cached maps observe the new value.

◆ set_attr() [2/2]

template<typename ValueType , typename Value , std::enable_if_t<(std::is_convertible_v< Value &&, ValueType > &&((!std::is_same_v< std::decay_t< Value >, ffi::Any > &&!std::is_same_v< std::decay_t< Value >, ffi::AnyView >)||std::is_same_v< ValueType, ffi::Any >||std::is_same_v< ValueType, ffi::AnyView >)), int > = 0>
OpDef & tvm::OpDef::set_attr ( ffi::reflection::AttrKey< ValueType >  key,
Value &&  value,
bool  override = false 
)
inline

Register a value using the key's declared type.

Parameters
keyAttribute column key.
valueValue convertible to the key's type; erased values require explicit extraction.
overrideWhether to replace an existing value.
Returns
This builder. Stored callbacks retain their packed function owner.

◆ set_attrs_type_key()

TVM_TIRX_DLL OpDef & tvm::OpDef::set_attrs_type_key ( const ffi::String &  key)

Resolve and set the attribute object type key and runtime index together.

Parameters
keyA registered attribute object type key.
Returns
This builder. An unknown key raises an error before modifying metadata.

◆ set_native_fn_attr()

template<auto Fn, typename ValueType >
OpDef & tvm::OpDef::set_native_fn_attr ( ffi::reflection::AttrKey< ValueType >  key,
bool  override = false 
)
inline

Register a native callback using the key's declared adapter.

Template Parameters
FnThe native callback.
Parameters
keyAttribute column key.
overrideWhether to replace an existing value.
Returns
This builder.

◆ set_validator()

OpDef & tvm::OpDef::set_validator ( ffi::reflection::NativeFunctionView< void(const CallObj *)>  validator,
bool  override = false 
)
inline

Register a validator that checks a Call with this operator.

The callback accepts a const CallObj* and reports invalid input by throwing or returning an Expected<void> error. A native function pointer can be bound with NativeFunctionView::FromNative. A borrowed packed function may also be passed while it remains alive for this call. The setter retains an owning copy, so the original packed function may then be destroyed. Call::Validate invokes it explicitly; Relax normalization and well-formedness also validate when inputs are ready. A signature installs its generated validator only if none is registered, so a custom validator registered first takes precedence. Replacing a generated or custom validator requires override; duplicate registration without override raises ValueError. NativeFunctionView cannot be null.

Parameters
validatorCallback to install.
overrideWhether to replace the current validator.
Returns
This builder.

◆ signature()

template<typename... Specs>
OpDef & tvm::OpDef::signature ( const Specs &...  specs)
inline

Register a complete typed Call signature and its validator.

Fixed descriptors require exactly one value/type argument each. A variadic tail accepts zero or more trailing arguments of its category. Validation throws on arity or class mismatch; it does not infer types or mutate the Call. Call::Validate invokes the validator separately from construction. Without call_attrs<T>, Call.attrs is unconstrained. Repeated registration replaces metadata but retains any existing validator, including a generated one. Replace the callback explicitly if its executable checks must change.

OpDef("example.op")
sig::arg("value"),
sig::arg<PrimExpr>("index"),
sig::var_args<PrimExpr>("rest"),
sig::ty_arg("T"),
sig::var_ty_args("Ts"),
sig::call_attrs<DictAttrsObj>());
Noncopyable temporary builder for a canonical Op; see Op for the example.
Definition op.h:467
OpDef & signature(const Specs &... specs)
Register a complete typed Call signature and its validator.
Definition op.h:546

The documentation for this class was generated from the following file: