24 #ifndef TVM_TARGET_TARGET_KIND_H_ 25 #define TVM_TARGET_TARGET_KIND_H_ 32 #include <unordered_map> 65 template <
typename,
typename,
typename>
87 v->Visit(
"name", &name);
88 v->Visit(
"device_type", &device_type);
89 v->Visit(
"default_keys", &default_keys);
92 static constexpr
const char* _type_key =
"TargetKind";
97 uint32_t AttrRegistryIndex()
const {
return index_; }
99 String AttrRegistryName()
const {
return name; }
101 struct ValueTypeInfo {
104 std::unique_ptr<ValueTypeInfo> key;
105 std::unique_ptr<ValueTypeInfo> val;
108 std::unordered_map<String, ValueTypeInfo> key2vtype_;
110 std::unordered_map<String, ObjectRef> key2default_;
114 template <
typename,
typename,
typename>
116 template <
typename,
typename>
121 friend class TargetInternal;
132 template <
typename ValueType>
148 friend class TargetInternal;
155 template <
typename ValueType>
159 using TParent::count;
161 using TParent::operator[];
166 static constexpr
const char* kTvmRuntimeCpp =
"c++";
169 static constexpr
const char* kTvmRuntimeCrt =
"c";
190 template <
typename ValueType>
208 template <
typename FLambda>
215 template <
typename ValueType>
223 template <
typename ValueType>
250 explicit TargetKindRegEntry(uint32_t reg_index) : kind_(make_object<TargetKindNode>()) {
251 kind_->index_ = reg_index;
260 template <
typename,
typename>
266 template <
typename Type,
template <
typename...>
class Container>
271 template <
template <
typename...>
class Container,
typename... Args>
276 template <typename ValueType, typename IsArray = typename is_specialized<ValueType, Array>::type,
280 template <
typename ValueType>
282 using ValueTypeInfo = TargetKindNode::ValueTypeInfo;
284 ValueTypeInfo operator()()
const {
285 uint32_t tindex = ValueType::ContainerType::_GetOrAllocRuntimeTypeIndex();
287 info.type_index = tindex;
295 template <
typename ValueType>
297 using ValueTypeInfo = TargetKindNode::ValueTypeInfo;
299 ValueTypeInfo operator()()
const {
301 uint32_t tindex = ValueType::ContainerType::_GetOrAllocRuntimeTypeIndex();
303 info.type_index = tindex;
305 info.key = std::unique_ptr<ValueTypeInfo>(
new ValueTypeInfo(key_type()()));
311 template <
typename ValueType>
313 using ValueTypeInfo = TargetKindNode::ValueTypeInfo;
314 ValueTypeInfo operator()()
const {
317 uint32_t tindex = ValueType::ContainerType::_GetOrAllocRuntimeTypeIndex();
319 info.type_index = tindex;
321 info.key = std::unique_ptr<ValueTypeInfo>(
new ValueTypeInfo(key_type()()));
322 info.val = std::unique_ptr<ValueTypeInfo>(
new ValueTypeInfo(val_type()()));
329 template <
typename ValueType>
334 template <
typename ValueType>
336 const ValueType& value,
int plevel) {
337 ICHECK_GT(plevel, 0) <<
"plevel in set_attr must be greater than 0";
340 UpdateAttr(attr_name, rv, plevel);
350 kind_->default_keys = keys;
354 template <
typename FLambda>
356 using FType =
typename tvm::runtime::detail::function_signature<FLambda>::FType;
361 template <
typename ValueType>
363 ICHECK(!kind_->key2vtype_.count(key))
364 <<
"AttributeError: add_attr_option failed because '" << key <<
"' has been set once";
369 template <
typename ValueType>
372 add_attr_option<ValueType>(key);
373 kind_->key2default_[key] = default_value;
378 if (kind_->name.empty()) {
384 #define TVM_TARGET_KIND_REGISTER_VAR_DEF \ 385 static DMLC_ATTRIBUTE_UNUSED ::tvm::TargetKindRegEntry& __make_##TargetKind 434 #define TVM_REGISTER_TARGET_KIND(TargetKindName, DeviceType) \ 435 TVM_STR_CONCAT(TVM_TARGET_KIND_REGISTER_VAR_DEF, __COUNTER__) = \ 436 ::tvm::TargetKindRegEntry::RegisterOrGet(TargetKindName) \ 438 .set_device_type(DeviceType) \ 439 .add_attr_option<Array<String>>("keys") \ 440 .add_attr_option<String>("tag") \ 441 .add_attr_option<String>("device") \ 442 .add_attr_option<String>("model") \ 443 .add_attr_option<Array<String>>("libs") \ 444 .add_attr_option<Target>("host") \ 445 .add_attr_option<Integer>("from_device") 449 #endif // TVM_TARGET_TARGET_KIND_H_ TargetKindRegEntry & set_device_type(int device_type)
Set DLPack's device_type the target.
Definition: target_kind.h:344
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:1357
Definition: target_kind.h:267
constexpr const char * kRelayToTIR
A TargetKind attribute of type FTVMRelayToTIR. If set, then the target kind name also corresponds to ...
Definition: target_kind.h:413
TargetKindRegEntry & set_default_keys(std::vector< String > keys)
Set DLPack's device_type the target.
Definition: target_kind.h:349
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:86
TargetKindRegEntry & set_name()
Set name of the TargetKind to be the same as registry if it is empty.
Definition: target_kind.h:377
std::true_type type
Definition: target_kind.h:273
base class of all object containers.
Definition: object.h:167
Definition: executor.h:43
Managed reference class to TargetKindNode.
Definition: target_kind.h:128
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:362
TargetKindAttrMap(const AttrRegistryMapContainerMap< TargetKind > &map)
Definition: target_kind.h:162
Helper structure to register TargetKind.
Definition: target_kind.h:175
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:270
Reference to string objects.
Definition: string.h:124
Please refer to TypedPackedFunc<R(Args..)>.
Definition: packed_func.h:60
Definition: target_kind.h:66
tvm::Type Type
Definition: type.h:47
Array< String > default_keys
Default keys of the target.
Definition: target_kind.h:82
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:75
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:404
#define TVM_DECLARE_FINAL_OBJECT_INFO(TypeName, ParentType)
helper macro to declare type information in a final class.
Definition: object.h:671
int device_type
Device type of target kind.
Definition: target_kind.h:80
TargetKindRegEntry & set_attr(const String &attr_name, const ValueType &value, int plevel=10)
Register additional attributes to target_kind.
Definition: target_kind.h:335
std::false_type type
Definition: target_kind.h:268
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:1268
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:84
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:72
static TargetKindAttrMap< ValueType > GetAttrMap(const String &attr_name)
Get the attribute map given the attribute name.
Definition: target_kind.h:330
String name
Name of the target kind.
Definition: target_kind.h:78
#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:355