24 #ifndef TVM_TARGET_TARGET_H_
25 #define TVM_TARGET_TARGET_H_
27 #include <tvm/ffi/reflection/registry.h>
37 #include <unordered_set>
54 ffi::Optional<ObjectRef>
host;
58 ffi::Array<ffi::String>
keys;
60 ffi::Map<ffi::String, Any>
attrs;
69 TVM_DLL
const std::string&
str()
const;
71 TVM_DLL ffi::Map<ffi::String, ffi::Any>
Export()
const;
73 TVM_DLL ffi::Optional<Target>
GetHost()
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 ffi::Optional<TObjectRef> default_value = ffi::Optional<TObjectRef>(std::nullopt))
const {
118 auto it =
attrs.find(attr_key);
119 if (it !=
attrs.end()) {
120 return Downcast<ffi::Optional<TObjectRef>>((*it).second);
122 return default_value;
132 template <
typename TObjectRef>
133 ffi::Optional<TObjectRef>
GetAttr(
const std::string& attr_key, TObjectRef default_value)
const {
134 return GetAttr<TObjectRef>(attr_key, ffi::Optional<TObjectRef>(default_value));
156 template <
typename TObjectRef>
158 const std::string& feature_key,
159 ffi::Optional<TObjectRef> default_value = std::nullopt)
const {
160 if (
auto feature =
features.Get(feature_key)) {
161 return Downcast<TObjectRef>(feature.value());
163 return default_value;
167 template <
typename TObjectRef>
168 ffi::Optional<TObjectRef>
GetFeature(
const std::string& attr_key,
169 TObjectRef default_value)
const {
170 return GetFeature<TObjectRef>(attr_key, ffi::Optional<TObjectRef>(default_value));
174 TVM_DLL std::vector<std::string>
GetKeys()
const;
176 TVM_DLL std::unordered_set<std::string>
GetLibs()
const;
183 mutable std::string str_repr_;
195 TVM_DLL
explicit Target(std::nullptr_t) { data_ =
nullptr; }
200 TVM_DLL
explicit Target(
const ffi::String& tag_or_config_or_target_str);
205 TVM_DLL
explicit Target(
const ffi::Map<ffi::String, ffi::Any>& config);
235 ffi::Array<ffi::String> keys, ffi::Map<ffi::String, ffi::Any> attrs);
245 TVM_DLL
void EnterWithScope();
250 TVM_DLL
void ExitWithScope();
Attribute map used in registry.
Managed reference class to TargetKindNode.
Definition: target_kind.h:126
Compilation target.
Definition: target.h:49
int GetTargetDeviceType() const
std::unordered_set< std::string > GetLibs() const
Get the keys for this target as an unordered_set of string.
ffi::Optional< TObjectRef > GetAttr(const std::string &attr_key, TObjectRef default_value) const
Get an entry from attrs of the target.
Definition: target.h:133
const std::string & str() const
The raw string representation of the target.
ffi::String tag
Tag of the target, can be empty.
Definition: target.h:56
ffi::Map< ffi::String, Any > attrs
Collection of attributes.
Definition: target.h:60
static void RegisterReflection()
Definition: target.h:96
ffi::Map< ffi::String, Any > features
Target features.
Definition: target.h:62
ffi::Optional< Target > GetHost() const
ffi::String ToDebugString() const
Returns a human readable representation of Target which includes all fields, especially the host....
friend class TargetInternal
Definition: target.h:185
ffi::Array< ffi::String > keys
Keys for this target.
Definition: target.h:58
ffi::Optional< TObjectRef > GetFeature(const std::string &feature_key, ffi::Optional< TObjectRef > default_value=std::nullopt) const
Get a Target feature.
Definition: target.h:157
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition: target.h:178
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.
ffi::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
ffi::Optional< TObjectRef > GetAttr(const std::string &attr_key, ffi::Optional< TObjectRef > default_value=ffi::Optional< TObjectRef >(std::nullopt)) const
Get an entry from attrs of the target.
Definition: target.h:115
ffi::Optional< TObjectRef > GetFeature(const std::string &attr_key, TObjectRef default_value) const
Definition: target.h:168
ffi::Map< ffi::String, ffi::Any > Export() const
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("target.Target", TargetNode, Object)
Managed reference class to TargetNode.
Definition: target.h:192
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:195
Target WithoutHost() const
friend class TargetInternal
Definition: target.h:238
Target(const ffi::Map< ffi::String, ffi::Any > &config)
Construct a Target using a JSON-like configuration.
Target(const ffi::String &tag_or_config_or_target_str)
Construct a Target given a string.
static tvm::Target Current(bool allow_not_defined=true)
Get the current target context from thread local storage.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Target, ObjectRef, TargetNode)
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.