24 #ifndef TVM_TARGET_TARGET_KIND_H_
25 #define TVM_TARGET_TARGET_KIND_H_
32 #include <unordered_map>
80 template <
typename,
typename,
typename>
81 struct ValueTypeInfoMaker;
87 class TargetKindAttrMap;
104 v->Visit(
"name", &
name);
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>
149 template <
typename ValueType>
172 template <
typename ValueType>
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>
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>
318 struct ValueTypeInfoMaker<ValueType, std::true_type, std::false_type> {
319 using ValueTypeInfo = TargetKindNode::ValueTypeInfo;
321 ValueTypeInfo operator()()
const {
322 using key_type = ValueTypeInfoMaker<typename ValueType::value_type>;
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>
334 struct ValueTypeInfoMaker<ValueType, std::false_type, std::true_type> {
335 using ValueTypeInfo = TargetKindNode::ValueTypeInfo;
336 ValueTypeInfo operator()()
const {
337 using key_type = ValueTypeInfoMaker<typename ValueType::key_type>;
338 using val_type = ValueTypeInfoMaker<typename ValueType::mapped_type>;
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);
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;
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;
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")
Attribute map used in registry.
Generic attribute map.
Definition: attr_registry_map.h:38
Map<Key, ValueType> used to store meta-data.
Definition: attr_registry_map.h:101
ValueType get(const TargetKind &key, ValueType def_value) const
get the corresponding value element at key with default value.
Definition: attr_registry_map.h:126
int count(const TargetKind &key) const
Check if the map has op as key.
Definition: attr_registry_map.h:113
Definition: executor.h:43
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
Managed reference class to IRModuleNode.
Definition: module.h:348
Map<TargetKind, ValueType> used to store meta-information about TargetKind.
Definition: target_kind.h:173
TargetKindAttrMap(const AttrRegistryMapContainerMap< TargetKind > &map)
Definition: target_kind.h:179
Target kind, specifies the kind of the target.
Definition: target_kind.h:90
int default_device_type
Device type of target kind.
Definition: target_kind.h:95
PackedFunc preprocessor
Function used to preprocess on target creation.
Definition: target_kind.h:99
String name
Name of the target kind.
Definition: target_kind.h:93
TVM_DECLARE_FINAL_OBJECT_INFO(TargetKindNode, Object)
FTVMTargetParser target_parser
Function used to parse a JSON target during creation.
Definition: target_kind.h:101
friend class TargetInternal
Definition: target_kind.h:138
void VisitAttrs(AttrVisitor *v)
Definition: target_kind.h:103
Array< String > default_keys
Default keys of the target.
Definition: target_kind.h:97
static constexpr const char * _type_key
Definition: target_kind.h:109
Helper structure to register TargetKind.
Definition: target_kind.h:192
TargetKindRegEntry & set_attrs_preprocessor(FLambda f)
Set the pre-processing function applied upon target creation.
Definition: target_kind.h:377
TargetKindRegEntry & set_target_parser(FTVMTargetParser parser)
Set the parsing function applied upon target creation.
Definition: target_kind.h:384
TargetKindRegEntry & set_default_keys(std::vector< String > keys)
Set DLPack's device_type the target.
Definition: target_kind.h:371
TargetKindRegEntry & set_name()
Set name of the TargetKind to be the same as registry if it is empty.
Definition: target_kind.h:405
static TargetKindRegEntry & RegisterOrGet(const String &target_kind_name)
Register or get a new entry.
TargetKindRegEntry & set_attr(const String &attr_name, const ValueType &value, int plevel=10)
Register additional attributes to target_kind.
Definition: target_kind.h:357
static Array< 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:366
TargetKindRegEntry & add_attr_option(const String &key)
Register a valid configuration option and its ValueType for validation.
Definition: target_kind.h:390
static Map< String, String > ListTargetKindOptions(const TargetKind &kind)
Get all supported option names and types for a given Target kind.
Managed reference class to TargetKindNode.
Definition: target_kind.h:145
static Optional< TargetKind > Get(const String &target_kind_name)
Retrieve the TargetKind given its name.
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(TargetKind, ObjectRef, TargetKindNode)
friend class TargetInternal
Definition: target_kind.h:165
static TargetKindAttrMap< ValueType > GetAttrMap(const String &attr_name)
Get the attribute map given the attribute name.
Definition: target_kind.h:352
Managed reference class to TargetNode.
Definition: target.h:193
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
Map container of NodeRef->NodeRef in DSL graph. Map implements copy on write semantics,...
Definition: map.h:1271
Module container of TVM.
Definition: module.h:79
Base class of all object reference.
Definition: object.h:515
ObjectPtr< Object > data_
Internal pointer that backs the reference.
Definition: object.h:601
base class of all object containers.
Definition: object.h:167
uint32_t type_index() const
Definition: object.h:175
static std::string TypeIndex2Key(uint32_t tindex)
Get the type key of the corresponding index from runtime.
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
Packed function is a type-erased function. The arguments are passed by packed format.
Definition: packed_func.h:138
Reference to string objects.
Definition: string.h:98
bool empty() const
Retun if the string is empty.
Definition: string.h:208
Return Value container, Unlike TVMArgValue, which only holds reference and do not delete the underlyi...
Definition: packed_func.h:799
Please refer to TypedPackedFunc<R(Args..)>.
Definition: packed_func.h:60
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
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
tvm::Type Type
Definition: type.h:47
ObjectPtr< ArrayNode > make_object()
Definition: array.h:898
constexpr const char * device_type
The device type.
Definition: stmt.h:1418
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
Map< String, ObjectRef > TargetJSON
TargetParser to apply on instantiation of a given TargetKind.
Definition: target_kind.h:52
Definitions and helper macros for IR/AST nodes.
Definition: target_kind.h:300
std::true_type type
Definition: target_kind.h:295
Definition: target_kind.h:289
std::false_type type
Definition: target_kind.h:290