24#ifndef TVM_TARGET_TARGET_KIND_H_
25#define TVM_TARGET_TARGET_KIND_H_
27#include <tvm/ffi/function.h>
28#include <tvm/ffi/reflection/registry.h>
34#include <unordered_map>
49 ffi::TypedFunction<ffi::Map<ffi::String, ffi::Any>(ffi::Map<ffi::String, ffi::Any>)>;
69 namespace refl = tvm::ffi::reflection;
70 refl::ObjectDef<TargetKindNode>()
73 refl::AttachFieldFlag::SEqHashIgnore())
75 refl::AttachFieldFlag::SEqHashIgnore());
83 uint32_t AttrRegistryIndex()
const {
return index_; }
85 ffi::String AttrRegistryName()
const {
return name; }
87 ir::ConfigSchema schema_;
91 template <
typename,
typename>
106 explicit TargetKind(ffi::ObjectPtr<TargetKindNode> data) : ffi::ObjectRef(data) {
110 template <
typename ValueType>
134template <
typename ValueType>
140 using TParent::operator[];
145static constexpr const char* kTvmRuntimeCpp =
"c++";
148static constexpr const char* kTvmRuntimeCrt =
"c";
169 template <
typename ValueType>
230 TVM_DLL void UpdateAttr(
const ffi::String& key, ffi::Any value,
int plevel);
231 template <
typename,
typename>
236template <
typename ValueType>
241template <
typename ValueType>
276 if (kind_->
name.empty()) {
282#define TVM_TARGET_KIND_REGISTER_VAR_DEF \
283 [[maybe_unused]] static ::tvm::TargetKindRegEntry& __make_##TargetKind
302#define TVM_REGISTER_TARGET_KIND(TargetKindName, DeviceType) \
303 TVM_FFI_STR_CONCAT(TVM_TARGET_KIND_REGISTER_VAR_DEF, __COUNTER__) = \
304 ::tvm::TargetKindRegEntry::RegisterOrGet(TargetKindName) \
306 .set_default_device_type(DeviceType) \
307 .add_attr_option<ffi::String>("kind") \
308 .add_attr_option<ffi::Array<ffi::String>>("keys") \
309 .add_attr_option<ffi::String>("tag") \
310 .add_attr_option<ffi::String>("device") \
311 .add_attr_option<ffi::String>("model") \
312 .add_attr_option<ffi::Array<ffi::String>>("libs") \
313 .add_attr_option<Target>("host") \
314 .add_attr_option<int64_t>("from_device") \
315 .add_attr_option<int64_t>("target_device_type")
Attribute map used in registry.
Generic attribute map.
Definition attr_registry_map.h:38
ffi::Map<Key, ValueType> used to store meta-data.
Definition attr_registry_map.h:105
ValueType get(const TargetKind &key, ValueType def_value) const
get the corresponding value element at key with default value.
Definition attr_registry_map.h:136
int count(const TargetKind &key) const
Check if the map has op as key.
Definition attr_registry_map.h:117
Definition instruction.h:31
ffi::Map<TargetKind, ValueType> used to store meta-information about TargetKind
Definition target_kind.h:135
TargetKindAttrMap(const AttrRegistryMapContainerMap< TargetKind > &map)
Definition target_kind.h:141
Target kind, specifies the kind of the target.
Definition target_kind.h:57
int default_device_type
Device type of target kind.
Definition target_kind.h:62
FTargetCanonicalizer target_canonicalizer
Function used to canonicalize a JSON target during creation.
Definition target_kind.h:66
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("target.TargetKind", TargetKindNode, ffi::Object)
friend class TargetInternal
Definition target_kind.h:96
ffi::String name
Name of the target kind.
Definition target_kind.h:60
ffi::Array< ffi::String > default_keys
Default keys of the target.
Definition target_kind.h:64
static void RegisterReflection()
Definition target_kind.h:68
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition target_kind.h:78
Helper structure to register TargetKind.
Definition target_kind.h:154
TargetKindRegEntry & set_name()
Set name of the TargetKind to be the same as registry if it is empty.
Definition target_kind.h:275
TargetKindRegEntry & add_attr_option(const ffi::String &key, Traits &&... traits)
Register a valid configuration option and its ValueType for validation.
Definition target_kind.h:269
TargetKindRegEntry & set_default_keys(std::vector< ffi::String > keys)
Set DLPack's device_type the target.
Definition target_kind.h:256
TargetKindRegEntry & set_target_canonicalizer(FTargetCanonicalizer canonicalizer)
Set the canonicalizer function applied upon target creation.
Definition target_kind.h:261
static ffi::Array< ffi::String > ListTargetKinds()
List all the entry names in the registry.
TargetKindRegEntry & set_default_device_type(int device_type)
Set DLPack's device_type the target.
Definition target_kind.h:251
static ffi::Map< ffi::String, ffi::String > ListTargetKindOptions(const TargetKind &kind)
Get all supported option names and types for a given Target kind.
static TargetKindRegEntry & RegisterOrGet(const ffi::String &target_kind_name)
Register or get a new entry.
TargetKindRegEntry & set_attr(const ffi::String &attr_name, const ValueType &value, int plevel=10)
Register additional attributes to target_kind.
Definition target_kind.h:242
Managed reference class to TargetKindNode.
Definition target_kind.h:103
TargetKindNode * operator->()
Mutable access to the container class
Definition target_kind.h:119
TargetKind(ffi::ObjectPtr< TargetKindNode > data)
Definition target_kind.h:106
static ffi::Optional< TargetKind > Get(const ffi::String &target_kind_name)
Retrieve the TargetKind given its name.
friend class TargetInternal
Definition target_kind.h:127
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(TargetKind, ffi::ObjectRef, TargetKindNode)
static TargetKindAttrMap< ValueType > GetAttrMap(const ffi::String &attr_name)
Get the attribute map given the attribute name.
Definition target_kind.h:237
RAII wrapper function to enter and exit a context object similar to python's with syntax.
Definition with_context.h:59
ConfigSchema & def_option(const ffi::String &key, Traits &&... traits)
Declare a typed option.
Definition config_schema.h:87
void set_canonicalizer(Canonicalizer f)
Set whole-object canonicalizer.
Definition config_schema.h:98
Minimal schema for dynamic config canonicalization and validation.
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analyzer.h:40
ffi::TypedFunction< ffi::Map< ffi::String, ffi::Any >(ffi::Map< ffi::String, ffi::Any >)> FTargetCanonicalizer
Target canonicalizer applied on instantiation of a given TargetKind.
Definition target_kind.h:49