Class BaseFuncObj#

Inheritance Relationships#

Base Type#

Derived Type#

Class Documentation#

class BaseFuncObj : public tvm::ExprObj#

Base node of all functions.

We support several variants of functions throughout the stack. All of the functions share the same type system to support cross variant calls.

See also

BaseFunc

Subclassed by tvm::tirx::FunctionObj

Public Functions

template<typename TObjectRef>
inline ffi::Optional<TObjectRef> GetAttr(const std::string &attr_key, ffi::Optional<TObjectRef> default_value = std::nullopt) const#

Get a function attribute.

void GetAttrExample(const BaseFunc& f) {
auto value = f->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 LinkageType GetLinkageType() const#

Get the type of the linkage.

Currently, we only consider external/internal linkage. This can be extended in the future when necessary.

void Example(const BaseFunc& f) {
if (f->GetLinkageType() == tvm::LinkageType::kExternal) {
// Do not remove a function with external linkage
  }
}

Returns:

Linkage type.

Public Members

DictAttrs attrs#

Additional attributes storing the meta-data.

Public Static Functions

static inline void RegisterReflection()#
static inline int32_t _GetOrAllocRuntimeTypeIndex()#
static inline int32_t RuntimeTypeIndex() noexcept#