Class DictAttrs#
Defined in File attrs.h
Inheritance Relationships#
Base Type#
public tvm::Attrs(Class Attrs)
Class Documentation#
-
class DictAttrs : public tvm::Attrs#
Managed reference to DictAttrsObj.
See also
Note
DictAttrs is NOTNULLABLE: every instance must hold a backing DictAttrsObj. The class enforces this end-to-end by:
the default constructor (no args) allocating an empty backing,
the copy/move ctors and assignments leaving the moved-from instance in a defined-but-empty state rather than null,
the FFI type traits rejecting None at deserialization boundaries (since
_type_is_nullable == false), andthe FFI lambda for
ir.IRModuleexplicitly normalizing a missing/None attrs argument toDictAttrs()before forwarding to the C++ constructor. Callers (including third-party code via templates likeWithAttr) can therefore rely onattrs->dictbeing safe to dereference without a.defined()guard.
Public Types
-
using __PtrType = std::conditional_t<DictAttrsObj::_type_mutable, DictAttrsObj*, const DictAttrsObj*>#
-
using ContainerType = DictAttrsObj#
Public Functions
-
inline explicit DictAttrs(ffi::Map<ffi::String, Any> dict = {})#
Construct a DictAttrs backed by DictAttrsObj.
The no-argument form constructs an empty (but always defined) DictAttrs.
- Parameters:
dict – The attributes.
-
inline DictAttrs(DictAttrs &&other) noexcept#
Move constructor that leaves the source in a defined-but-empty state rather than null, preserving the NOTNULLABLE invariant even after
std::move.
-
inline DictAttrs &operator=(DictAttrs &&other) noexcept#
Move assignment that leaves the source in a defined-but-empty state rather than null, preserving the NOTNULLABLE invariant even after
std::move.
-
template<typename TObjectRef>
inline ffi::Optional<TObjectRef> GetAttr(const std::string &attr_key, ffi::Optional<TObjectRef> default_value = ffi::Optional<TObjectRef>(std::nullopt)) const# Get a function attribute.
void GetAttrExample(const BaseFunc& f) { auto value = f->attrs.GetAttr<int64_t>("AttrKey", 0); }
- Parameters:
attr_key – The attribute key.
default_value – The default value if the key does not exist, defaults to nullptr.
- Template Parameters:
TOBjectRef – the expected object type.
- Throws:
Error – if the key exists but the value does not match TObjectRef
- Returns:
The result
-
template<typename T>
inline ffi::Optional<T> GetAttr(ffi::reflection::AttrKey<T> key, ffi::Optional<typename ffi::reflection::AttrKey<T>::ValueType> default_value = std::nullopt) const# Get an attribute with its value type deduced only from the key.
- Parameters:
key – The typed attribute key.
default_value – Value returned only when the key is absent.
- Returns:
The attribute or default, with the same conversions as the name-based getter.
-
template<typename T>
inline ffi::Optional<T> GetAttr(ffi::reflection::AttrKey<T> key, typename ffi::reflection::AttrKey<T>::ValueType default_value) const# Accept a default convertible to the key’s value type.
-
template<typename TObjectRef>
inline ffi::Optional<TObjectRef> GetAttr(const std::string &attr_key, TObjectRef default_value) const#
-
inline bool HasNonzeroAttr(const std::string &attr_key) const#
Check whether the function has an non-zero integer attr.
This function can be used to check whether an optional attribute mark(e.g. inline) exists.
void HasNonzeroAttrExample(const BaseFunc& f) { if (f->HasNonzeroAttr(attr::kInline)) { // inline the function. } }
- Parameters:
attr_key – The key to the attribute.
- Returns:
The check result.
-
inline explicit DictAttrs(::tvm::ffi::UnsafeInit tag)#
-
inline DictAttrsObj *CopyOnWrite()#