24 #ifndef TVM_TARGET_TARGET_H_
25 #define TVM_TARGET_TARGET_H_
27 #include <tvm/ffi/reflection/registry.h>
50 ffi::Optional<ffi::ObjectRef>
host;
54 ffi::Array<ffi::String>
keys;
56 ffi::Map<ffi::String, Any>
attrs;
62 TVM_DLL
const std::string&
str()
const;
64 TVM_DLL ffi::Map<ffi::String, ffi::Any>
ToConfig()
const;
66 TVM_DLL ffi::Optional<Target>
GetHost()
const;
78 TVM_DLL
bool HasKey(
const std::string& query_key)
const;
81 namespace refl = tvm::ffi::reflection;
82 refl::ObjectDef<TargetNode>()
97 template <
typename TObjectRef>
99 const std::string& attr_key,
100 ffi::Optional<TObjectRef> default_value = ffi::Optional<TObjectRef>(std::nullopt))
const {
101 auto it =
attrs.find(attr_key);
102 if (it !=
attrs.end()) {
103 return (*it).second.as_or_throw<ffi::Optional<TObjectRef>>();
105 return default_value;
115 template <
typename TObjectRef>
116 ffi::Optional<TObjectRef>
GetAttr(
const std::string& attr_key, TObjectRef default_value)
const {
117 return GetAttr<TObjectRef>(attr_key, ffi::Optional<TObjectRef>(default_value));
125 mutable std::string str_repr_;
137 TVM_DLL
explicit Target(std::nullptr_t) { data_ =
nullptr; }
142 TVM_DLL
explicit Target(
const ffi::String& tag_or_config_or_target_str);
147 TVM_DLL
explicit Target(
const ffi::Map<ffi::String, ffi::Any>& config);
171 Target(
TargetKind kind, ffi::Optional<ffi::ObjectRef> host, ffi::String tag,
172 ffi::Array<ffi::String> keys, ffi::Map<ffi::String, ffi::Any> attrs);
182 TVM_DLL
void EnterWithScope();
187 TVM_DLL
void ExitWithScope();
Managed reference class to TargetKindNode.
Definition: target_kind.h:103
Compilation target.
Definition: target.h:45
int GetTargetDeviceType() const
ffi::Optional< TObjectRef > GetAttr(const std::string &attr_key, TObjectRef default_value) const
Get an entry from attrs of the target.
Definition: target.h:116
const std::string & str() const
The JSON string representation of the target.
ffi::String tag
Tag of the target, can be empty.
Definition: target.h:52
ffi::Map< ffi::String, Any > attrs
Collection of attributes (includes feature.* keys set by canonicalizer)
Definition: target.h:56
ffi::Optional< ffi::ObjectRef > host
Target host information, must be Target type.
Definition: target.h:50
static void RegisterReflection()
Definition: target.h:80
ffi::Optional< Target > GetHost() const
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("target.Target", TargetNode, ffi::Object)
friend class TargetInternal
Definition: target.h:127
ffi::Array< ffi::String > keys
Keys for this target.
Definition: target.h:54
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition: target.h:120
bool HasKey(const std::string &query_key) const
Check if the target contains a key.
TargetKind kind
The kind of the target device.
Definition: target.h:48
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:98
ffi::Map< ffi::String, ffi::Any > ToConfig() const
Managed reference class to TargetNode.
Definition: target.h:134
Target(Target target, Target host)
Construct a Target given target and host.
static Target WithHost(const Target &target, const Target &host)
Target(std::nullptr_t)
Construct a null Target.
Definition: target.h:137
Target WithoutHost() const
friend class TargetInternal
Definition: target.h:175
Target(const ffi::Map< ffi::String, ffi::Any > &config)
Construct a Target using a JSON-like configuration.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Target, ffi::ObjectRef, TargetNode)
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.
RAII wrapper function to enter and exit a context object similar to python's with syntax.
Definition: with_context.h:59
Abstract device memory management API.
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition: analyzer.h:40
void CheckAndUpdateHostConsistency(Target *target, Target *host)
Check and update host field of the given legacy target and target host pair. Note that this function ...
RAII wrapper function to enter and exit a context object similar to python's with syntax.