24 #ifndef TVM_TARGET_TARGET_H_
25 #define TVM_TARGET_TARGET_H_
27 #include <tvm/ffi/reflection/registry.h>
37 #include <unordered_set>
69 TVM_DLL
const std::string&
str()
const;
71 TVM_DLL Map<String, ffi::Any>
Export()
const;
85 TVM_DLL
bool HasKey(
const std::string& query_key)
const;
98 refl::ObjectDef<TargetNode>()
114 template <
typename TObjectRef>
116 const std::string& attr_key,
117 Optional<TObjectRef> default_value = Optional<TObjectRef>(std::nullopt))
const {
118 auto it =
attrs.find(attr_key);
119 if (it !=
attrs.end()) {
120 return Downcast<Optional<TObjectRef>>((*it).second);
122 return default_value;
132 template <
typename TObjectRef>
133 Optional<TObjectRef>
GetAttr(
const std::string& attr_key, TObjectRef default_value)
const {
134 return GetAttr<TObjectRef>(attr_key, Optional<TObjectRef>(default_value));
156 template <
typename TObjectRef>
157 Optional<TObjectRef>
GetFeature(
const std::string& feature_key,
158 Optional<TObjectRef> default_value = std::nullopt)
const {
159 if (
auto feature =
features.Get(feature_key)) {
160 return Downcast<TObjectRef>(feature.value());
162 return default_value;
166 template <
typename TObjectRef>
167 Optional<TObjectRef>
GetFeature(
const std::string& attr_key, TObjectRef default_value)
const {
168 return GetFeature<TObjectRef>(attr_key, Optional<TObjectRef>(default_value));
172 TVM_DLL std::vector<std::string>
GetKeys()
const;
174 TVM_DLL std::unordered_set<std::string>
GetLibs()
const;
176 static constexpr
const char*
_type_key =
"target.Target";
182 mutable std::string str_repr_;
194 TVM_DLL
explicit Target(std::nullptr_t) { data_ =
nullptr; }
199 TVM_DLL
explicit Target(
const String& tag_or_config_or_target_str);
204 TVM_DLL
explicit Target(
const Map<String, ffi::Any>& config);
233 Target(
TargetKind kind, Optional<ObjectRef> host, String tag, Array<String> keys,
234 Map<String, ffi::Any> attrs);
244 TVM_DLL
void EnterWithScope();
249 TVM_DLL
void ExitWithScope();
Attribute map used in registry.
Managed reference class to TargetKindNode.
Definition: target_kind.h:127
Compilation target.
Definition: target.h:49
int GetTargetDeviceType() const
Optional< TObjectRef > GetAttr(const std::string &attr_key, TObjectRef default_value) const
Get an entry from attrs of the target.
Definition: target.h:133
std::unordered_set< std::string > GetLibs() const
Get the keys for this target as an unordered_set of string.
String tag
Tag of the target, can be empty.
Definition: target.h:56
const std::string & str() const
The raw string representation of the target.
String ToDebugString() const
Returns a human readable representation of Target which includes all fields, especially the host....
static constexpr const char * _type_key
Definition: target.h:176
Map< String, Any > features
Target features.
Definition: target.h:62
static void RegisterReflection()
Definition: target.h:96
friend class TargetInternal
Definition: target.h:184
Map< String, Any > attrs
Collection of attributes.
Definition: target.h:60
Map< String, ffi::Any > Export() const
TVM_DECLARE_FINAL_OBJECT_INFO(TargetNode, Object)
Optional< Target > GetHost() const
Optional< TObjectRef > GetAttr(const std::string &attr_key, Optional< TObjectRef > default_value=Optional< TObjectRef >(std::nullopt)) const
Get an entry from attrs of the target.
Definition: target.h:115
Optional< TObjectRef > GetFeature(const std::string &attr_key, TObjectRef default_value) const
Definition: target.h:167
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition: target.h:177
bool HasKey(const std::string &query_key) const
Check if the target contains a key.
std::vector< std::string > GetKeys() const
Get the keys for this target as a vector of string.
Optional< ObjectRef > host
Target host information, must be Target type.
Definition: target.h:54
TargetKind kind
The kind of the target device.
Definition: target.h:52
Optional< TObjectRef > GetFeature(const std::string &feature_key, Optional< TObjectRef > default_value=std::nullopt) const
Get a Target feature.
Definition: target.h:157
Array< String > keys
Keys for this target.
Definition: target.h:58
Managed reference class to TargetNode.
Definition: target.h:191
Target(Target target, Target host)
Construct a Target given target and host.
static Target WithHost(const Target &target, const Target &host)
Create a new Target object with given target (w.o host) and target host.
Target(std::nullptr_t)
Construct a null Target.
Definition: target.h:194
Target WithoutHost() const
Target(const String &tag_or_config_or_target_str)
Construct a Target given a string.
friend class TargetInternal
Definition: target.h:237
static tvm::Target Current(bool allow_not_defined=true)
Get the current target context from thread local storage.
TVM_DEFINE_OBJECT_REF_METHODS(Target, ObjectRef, TargetNode)
Target(const Map< String, ffi::Any > &config)
Construct a Target using a JSON-like configuration.
RAII wrapper function to enter and exit a context object similar to python's with syntax.
Definition: with.h:58
Abstract device memory management API.
Definition: repr_printer.h:91
Performance counters for profiling via the PAPI library.
Definition: analyzer.h:37
void CheckAndUpdateHostConsistency(Target *target, Target *host)
Check and update host field of the given legacy target and target host pair. Note that this function ...
Definitions and helper macros for IR/AST nodes.
RAII wrapper function to enter and exit a context object similar to python's with syntax.