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>)>;
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(ObjectPtr<TargetKindNode> data) : ObjectRef(data) {
107 TVM_FFI_ICHECK(data !=
nullptr);
110 template <
typename ValueType>
117 TVM_DLL
static ffi::Optional<TargetKind>
Get(
const ffi::String& target_kind_name);
125 const ffi::String& attr_name);
134 template <
typename ValueType>
140 using TParent::operator[];
145 static constexpr
const char* kTvmRuntimeCpp =
"c++";
148 static constexpr
const char* kTvmRuntimeCrt =
"c";
169 template <
typename ValueType>
194 template <
typename ValueType,
typename... Traits>
222 kind_->index_ = reg_index;
230 TVM_DLL
void UpdateAttr(
const ffi::String& key, ffi::Any value,
int plevel);
231 template <
typename,
typename>
236 template <
typename ValueType>
241 template <
typename ValueType>
243 const ValueType& value,
int plevel) {
244 TVM_FFI_ICHECK_GT(plevel, 0) <<
"plevel in set_attr must be greater than 0";
247 UpdateAttr(attr_name, rv, plevel);
268 template <
typename ValueType,
typename... Traits>
270 Traits&&... traits) {
271 kind_->schema_.
def_option<ValueType>(key, std::forward<Traits>(traits)...);
276 if (kind_->
name.empty()) {
282 #define TVM_TARGET_KIND_REGISTER_VAR_DEF \
283 static TVM_ATTRIBUTE_UNUSED ::tvm::TargetKindRegEntry& __make_##TargetKind
302 #define TVM_REGISTER_TARGET_KIND(TargetKindName, DeviceType) \
303 TVM_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:30
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, 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
static ffi::Map< ffi::String, ffi::String > ListTargetKindOptions(const TargetKind &kind)
Get all supported option names and types for a given Target kind.
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
static TargetKindRegEntry & RegisterOrGet(const ffi::String &target_kind_name)
Register or get a new entry.
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
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
TargetKind(ObjectPtr< TargetKindNode > data)
Definition: target_kind.h:106
friend class TargetInternal
Definition: target_kind.h:127
static TargetKindAttrMap< ValueType > GetAttrMap(const ffi::String &attr_name)
Get the attribute map given the attribute name.
Definition: target_kind.h:237
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(TargetKind, ObjectRef, TargetKindNode)
TargetKindNode * operator->()
Mutable access to the container class
Definition: target_kind.h:119
static ffi::Optional< TargetKind > Get(const ffi::String &target_kind_name)
Retrieve the TargetKind given its name.
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.
Definition: repr_printer.h:91
constexpr const char * device_type
The device type.
Definition: stmt.h:913
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition: analyzer.h:37
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
A managed object in the TVM runtime.