24 #ifndef TVM_TARGET_TARGET_KIND_H_ 25 #define TVM_TARGET_TARGET_KIND_H_ 32 #include <unordered_map> 80 template <
typename,
typename,
typename>
104 v->Visit(
"name", &name);
105 v->Visit(
"default_device_type", &default_device_type);
106 v->Visit(
"default_keys", &default_keys);
109 static constexpr
const char* _type_key =
"TargetKind";
114 uint32_t AttrRegistryIndex()
const {
return index_; }
116 String AttrRegistryName()
const {
return name; }
118 struct ValueTypeInfo {
121 std::unique_ptr<ValueTypeInfo> key;
122 std::unique_ptr<ValueTypeInfo> val;
125 std::unordered_map<String, ValueTypeInfo> key2vtype_;
127 std::unordered_map<String, ObjectRef> key2default_;
131 template <
typename,
typename,
typename>
133 template <
typename,
typename>
138 friend class TargetInternal;
149 template <
typename ValueType>
165 friend class TargetInternal;
172 template <
typename ValueType>
176 using TParent::count;
178 using TParent::operator[];
183 static constexpr
const char* kTvmRuntimeCpp =
"c++";
186 static constexpr
const char* kTvmRuntimeCrt =
"c";
207 template <
typename ValueType>
225 template <
typename FLambda>
237 template <
typename ValueType>
245 template <
typename ValueType>
272 explicit TargetKindRegEntry(uint32_t reg_index) : kind_(make_object<TargetKindNode>()) {
273 kind_->index_ = reg_index;
282 template <
typename,
typename>
288 template <
typename Type,
template <
typename...>
class Container>
293 template <
template <
typename...>
class Container,
typename... Args>
298 template <typename ValueType, typename IsArray = typename is_specialized<ValueType, Array>::type,
302 template <
typename ValueType>
304 using ValueTypeInfo = TargetKindNode::ValueTypeInfo;
306 ValueTypeInfo operator()()
const {
307 uint32_t tindex = ValueType::ContainerType::_GetOrAllocRuntimeTypeIndex();
309 info.type_index = tindex;
317 template <
typename ValueType>
319 using ValueTypeInfo = TargetKindNode::ValueTypeInfo;
321 ValueTypeInfo operator()()
const {
323 uint32_t tindex = ValueType::ContainerType::_GetOrAllocRuntimeTypeIndex();
325 info.type_index = tindex;
327 info.key = std::make_unique<ValueTypeInfo>(key_type()());
333 template <
typename ValueType>
335 using ValueTypeInfo = TargetKindNode::ValueTypeInfo;
336 ValueTypeInfo operator()()
const {
339 uint32_t tindex = ValueType::ContainerType::_GetOrAllocRuntimeTypeIndex();
341 info.type_index = tindex;
343 info.key = std::make_unique<ValueTypeInfo>(key_type()());
344 info.val = std::make_unique<ValueTypeInfo>(val_type()());
351 template <
typename ValueType>
356 template <
typename ValueType>
358 const ValueType& value,
int plevel) {
359 ICHECK_GT(plevel, 0) <<
"plevel in set_attr must be greater than 0";
362 UpdateAttr(attr_name, rv, plevel);
372 kind_->default_keys = keys;
376 template <
typename FLambda>
378 LOG(WARNING) <<
"set_attrs_preprocessor is deprecated please use set_target_parser instead";
379 using FType =
typename tvm::runtime::detail::function_signature<FLambda>::FType;
385 kind_->target_parser = parser;
389 template <
typename ValueType>
391 ICHECK(!kind_->key2vtype_.count(key))
392 <<
"AttributeError: add_attr_option failed because '" << key <<
"' has been set once";
397 template <
typename ValueType>
400 add_attr_option<ValueType>(key);
401 kind_->key2default_[key] = default_value;
406 if (kind_->name.empty()) {
412 #define TVM_TARGET_KIND_REGISTER_VAR_DEF \ 413 static DMLC_ATTRIBUTE_UNUSED ::tvm::TargetKindRegEntry& __make_##TargetKind 462 #define TVM_REGISTER_TARGET_KIND(TargetKindName, DeviceType) \ 463 TVM_STR_CONCAT(TVM_TARGET_KIND_REGISTER_VAR_DEF, __COUNTER__) = \ 464 ::tvm::TargetKindRegEntry::RegisterOrGet(TargetKindName) \ 466 .set_default_device_type(DeviceType) \ 467 .add_attr_option<Array<String>>("keys") \ 468 .add_attr_option<String>("tag") \ 469 .add_attr_option<String>("device") \ 470 .add_attr_option<String>("model") \ 471 .add_attr_option<Array<String>>("libs") \ 472 .add_attr_option<Target>("host") \ 473 .add_attr_option<Integer>("from_device") \ 474 .add_attr_option<Integer>("target_device_type") 478 #endif // TVM_TARGET_TARGET_KIND_H_ int default_device_type
Device type of target kind.
Definition: target_kind.h:95
Return Value container, Unlike TVMArgValue, which only holds reference and do not delete the underlyi...
Definition: packed_func.h:799
constexpr const char * device_type
The device type.
Definition: stmt.h:1355
Definition: target_kind.h:289
constexpr const char * kRelayToTIR
A TargetKind attribute of type FTVMRelayToTIR. If set, then the target kind name also corresponds to ...
Definition: target_kind.h:441
TargetKindRegEntry & set_default_keys(std::vector< String > keys)
Set DLPack's device_type the target.
Definition: target_kind.h:371
Definitions and helper macros for IR/AST nodes.
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
void VisitAttrs(AttrVisitor *v)
Definition: target_kind.h:103
TargetKindRegEntry & set_name()
Set name of the TargetKind to be the same as registry if it is empty.
Definition: target_kind.h:405
std::true_type type
Definition: target_kind.h:295
base class of all object containers.
Definition: object.h:167
Definition: executor.h:43
Managed reference class to TargetKindNode.
Definition: target_kind.h:145
Generic attribute map.
Definition: attr_registry_map.h:38
Visitor class to get the attributes of an AST/IR node. The content is going to be called for each fie...
Definition: reflection.h:52
TargetKindRegEntry & add_attr_option(const String &key)
Register a valid configuration option and its ValueType for validation.
Definition: target_kind.h:390
TargetKindAttrMap(const AttrRegistryMapContainerMap< TargetKind > &map)
Definition: target_kind.h:179
Helper structure to register TargetKind.
Definition: target_kind.h:192
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
FTVMTargetParser target_parser
Function used to parse a JSON target during creation.
Definition: target_kind.h:101
Reference to string objects.
Definition: string.h:98
Please refer to TypedPackedFunc<R(Args..)>.
Definition: packed_func.h:60
Definition: target_kind.h:81
tvm::Type Type
Definition: type.h:47
Array< String > default_keys
Default keys of the target.
Definition: target_kind.h:97
Base class of all object reference.
Definition: object.h:511
Map<Key, ValueType> used to store meta-data.
Definition: attr_registry_map.h:101
Target kind, specifies the kind of the target.
Definition: target_kind.h:90
Attribute map used in registry.
constexpr const char * kIsExternalCodegen
A TargetKind attribute of type Bool. If true, then the target kind name also corresponds to an extern...
Definition: target_kind.h:432
#define TVM_DECLARE_FINAL_OBJECT_INFO(TypeName, ParentType)
helper macro to declare type information in a final class.
Definition: object.h:671
TargetKindRegEntry & set_attr(const String &attr_name, const ValueType &value, int plevel=10)
Register additional attributes to target_kind.
Definition: target_kind.h:357
std::false_type type
Definition: target_kind.h:290
Map container of NodeRef->NodeRef in DSL graph. Map implements copy on write semantics, which means map is mutable but copy will happen when array is referenced in more than two places.
Definition: map.h:1271
static std::string TypeIndex2Key(uint32_t tindex)
Get the type key of the corresponding index from runtime.
PackedFunc preprocessor
Function used to preprocess on target creation.
Definition: target_kind.h:99
Packed function is a type-erased function. The arguments are passed by packed format.
Definition: packed_func.h:138
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
Map<TargetKind, ValueType> used to store meta-information about TargetKind.
Definition: target_kind.h:87
TargetKindRegEntry & set_target_parser(FTVMTargetParser parser)
Set the parsing function applied upon target creation.
Definition: target_kind.h:384
TargetKindRegEntry & set_default_device_type(int device_type)
Set DLPack's device_type the target.
Definition: target_kind.h:366
static TargetKindAttrMap< ValueType > GetAttrMap(const String &attr_name)
Get the attribute map given the attribute name.
Definition: target_kind.h:352
String name
Name of the target kind.
Definition: target_kind.h:93
#define TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName)
Definition: object.h:728
TargetKindRegEntry & set_attrs_preprocessor(FLambda f)
Set the pre-processing function applied upon target creation.
Definition: target_kind.h:377