24 #ifndef TVM_TARGET_TARGET_KIND_H_
25 #define TVM_TARGET_TARGET_KIND_H_
31 #include <unordered_map>
55 template <
typename,
typename,
typename>
56 struct ValueTypeInfoMaker;
62 class TargetKindAttrMap;
79 v->Visit(
"name", &
name);
84 static constexpr
const char*
_type_key =
"TargetKind";
89 uint32_t AttrRegistryIndex()
const {
return index_; }
91 String AttrRegistryName()
const {
return name; }
93 struct ValueTypeInfo {
96 std::unique_ptr<ValueTypeInfo> key;
97 std::unique_ptr<ValueTypeInfo> val;
100 std::unordered_map<String, ValueTypeInfo> key2vtype_;
102 std::unordered_map<String, ObjectRef> key2default_;
106 template <
typename,
typename,
typename>
108 template <
typename,
typename>
124 template <
typename ValueType>
147 template <
typename ValueType>
153 using TParent::operator[];
158 static constexpr
const char* kTvmRuntimeCpp =
"c++";
161 static constexpr
const char* kTvmRuntimeCrt =
"c";
182 template <
typename ValueType>
200 template <
typename FLambda>
212 template <
typename ValueType>
220 template <
typename ValueType>
248 kind_->index_ = reg_index;
257 template <
typename,
typename>
263 template <
typename Type,
template <
typename...>
class Container>
268 template <
template <
typename...>
class Container,
typename... Args>
273 template <typename ValueType, typename IsArray = typename is_specialized<ValueType, Array>::type,
277 template <
typename ValueType>
279 using ValueTypeInfo = TargetKindNode::ValueTypeInfo;
281 ValueTypeInfo operator()()
const {
282 uint32_t tindex = ValueType::ContainerType::_GetOrAllocRuntimeTypeIndex();
284 info.type_index = tindex;
292 template <
typename ValueType>
293 struct ValueTypeInfoMaker<ValueType, std::true_type, std::false_type> {
294 using ValueTypeInfo = TargetKindNode::ValueTypeInfo;
296 ValueTypeInfo operator()()
const {
297 using key_type = ValueTypeInfoMaker<typename ValueType::value_type>;
298 uint32_t tindex = ValueType::ContainerType::_GetOrAllocRuntimeTypeIndex();
300 info.type_index = tindex;
302 info.key = std::make_unique<ValueTypeInfo>(key_type()());
308 template <
typename ValueType>
309 struct ValueTypeInfoMaker<ValueType, std::false_type, std::true_type> {
310 using ValueTypeInfo = TargetKindNode::ValueTypeInfo;
311 ValueTypeInfo operator()()
const {
312 using key_type = ValueTypeInfoMaker<typename ValueType::key_type>;
313 using val_type = ValueTypeInfoMaker<typename ValueType::mapped_type>;
314 uint32_t tindex = ValueType::ContainerType::_GetOrAllocRuntimeTypeIndex();
316 info.type_index = tindex;
318 info.key = std::make_unique<ValueTypeInfo>(key_type()());
319 info.val = std::make_unique<ValueTypeInfo>(val_type()());
326 template <
typename ValueType>
331 template <
typename ValueType>
333 const ValueType& value,
int plevel) {
334 ICHECK_GT(plevel, 0) <<
"plevel in set_attr must be greater than 0";
337 UpdateAttr(attr_name, rv, plevel);
351 template <
typename FLambda>
353 LOG(WARNING) <<
"set_attrs_preprocessor is deprecated please use set_target_parser instead";
354 using FType =
typename tvm::runtime::detail::function_signature<FLambda>::FType;
364 template <
typename ValueType>
366 ICHECK(!kind_->key2vtype_.count(key))
367 <<
"AttributeError: add_attr_option failed because '" << key <<
"' has been set once";
372 template <
typename ValueType>
375 add_attr_option<ValueType>(key);
376 kind_->key2default_[key] = default_value;
387 #define TVM_TARGET_KIND_REGISTER_VAR_DEF \
388 static DMLC_ATTRIBUTE_UNUSED ::tvm::TargetKindRegEntry& __make_##TargetKind
407 #define TVM_REGISTER_TARGET_KIND(TargetKindName, DeviceType) \
408 TVM_STR_CONCAT(TVM_TARGET_KIND_REGISTER_VAR_DEF, __COUNTER__) = \
409 ::tvm::TargetKindRegEntry::RegisterOrGet(TargetKindName) \
411 .set_default_device_type(DeviceType) \
412 .add_attr_option<Array<String>>("keys") \
413 .add_attr_option<String>("tag") \
414 .add_attr_option<String>("device") \
415 .add_attr_option<String>("model") \
416 .add_attr_option<Array<String>>("libs") \
417 .add_attr_option<Target>("host") \
418 .add_attr_option<runtime::Int>("from_device") \
419 .add_attr_option<runtime::Int>("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: instruction.h:30
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
Map<TargetKind, ValueType> used to store meta-information about TargetKind.
Definition: target_kind.h:148
TargetKindAttrMap(const AttrRegistryMapContainerMap< TargetKind > &map)
Definition: target_kind.h:154
Target kind, specifies the kind of the target.
Definition: target_kind.h:65
int default_device_type
Device type of target kind.
Definition: target_kind.h:70
PackedFunc preprocessor
Function used to preprocess on target creation.
Definition: target_kind.h:74
String name
Name of the target kind.
Definition: target_kind.h:68
TVM_DECLARE_FINAL_OBJECT_INFO(TargetKindNode, Object)
FTVMTargetParser target_parser
Function used to parse a JSON target during creation.
Definition: target_kind.h:76
friend class TargetInternal
Definition: target_kind.h:113
void VisitAttrs(AttrVisitor *v)
Definition: target_kind.h:78
Array< String > default_keys
Default keys of the target.
Definition: target_kind.h:72
static constexpr const char * _type_key
Definition: target_kind.h:84
Helper structure to register TargetKind.
Definition: target_kind.h:167
TargetKindRegEntry & set_attrs_preprocessor(FLambda f)
Set the pre-processing function applied upon target creation.
Definition: target_kind.h:352
TargetKindRegEntry & set_target_parser(FTVMTargetParser parser)
Set the parsing function applied upon target creation.
Definition: target_kind.h:359
TargetKindRegEntry & set_default_keys(std::vector< String > keys)
Set DLPack's device_type the target.
Definition: target_kind.h:346
TargetKindRegEntry & set_name()
Set name of the TargetKind to be the same as registry if it is empty.
Definition: target_kind.h:380
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:332
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:341
TargetKindRegEntry & add_attr_option(const String &key)
Register a valid configuration option and its ValueType for validation.
Definition: target_kind.h:365
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:120
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:140
static TargetKindAttrMap< ValueType > GetAttrMap(const String &attr_name)
Get the attribute map given the attribute name.
Definition: target_kind.h:327
TargetKindNode * operator->()
Mutable access to the container class
Definition: target_kind.h:134
Managed reference to TypeNode.
Definition: type.h:93
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
Base class of all object reference.
Definition: object.h:520
ObjectPtr< Object > data_
Internal pointer that backs the reference.
Definition: object.h:606
base class of all object containers.
Definition: object.h:172
uint32_t type_index() const
Definition: object.h:180
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:141
Reference to string objects.
Definition: string.h:97
bool empty() const
Retun if the string is empty.
Definition: string.h:207
Return Value container, Unlike TVMArgValue, which only holds reference and do not delete the underlyi...
Definition: packed_func.h:946
ObjectPtr< ArrayNode > make_object()
Definition: array.h:908
constexpr const char * device_type
The device type.
Definition: stmt.h:1422
Performance counters for profiling via the PAPI library.
Definition: analyzer.h:36
Map< String, ObjectRef > TargetJSON
TargetParser to apply on instantiation of a given TargetKind.
Definition: target_kind.h:51
Definitions and helper macros for IR/AST nodes.
Definition: target_kind.h:275
std::true_type type
Definition: target_kind.h:270
Definition: target_kind.h:264
std::false_type type
Definition: target_kind.h:265