24 #ifndef TVM_TARGET_TARGET_H_
25 #define TVM_TARGET_TARGET_H_
27 #include <tvm/ffi/reflection/registry.h>
51 ffi::Optional<ObjectRef>
host;
55 ffi::Array<ffi::String>
keys;
57 ffi::Map<ffi::String, Any>
attrs;
63 TVM_DLL
const std::string&
str()
const;
65 TVM_DLL ffi::Map<ffi::String, ffi::Any>
ToConfig()
const;
67 TVM_DLL ffi::Optional<Target>
GetHost()
const;
79 TVM_DLL
bool HasKey(
const std::string& query_key)
const;
83 refl::ObjectDef<TargetNode>()
98 template <
typename TObjectRef>
100 const std::string& attr_key,
101 ffi::Optional<TObjectRef> default_value = ffi::Optional<TObjectRef>(std::nullopt))
const {
102 auto it =
attrs.find(attr_key);
103 if (it !=
attrs.end()) {
104 return Downcast<ffi::Optional<TObjectRef>>((*it).second);
106 return default_value;
116 template <
typename TObjectRef>
117 ffi::Optional<TObjectRef>
GetAttr(
const std::string& attr_key, TObjectRef default_value)
const {
118 return GetAttr<TObjectRef>(attr_key, ffi::Optional<TObjectRef>(default_value));
126 mutable std::string str_repr_;
138 TVM_DLL
explicit Target(std::nullptr_t) { data_ =
nullptr; }
143 TVM_DLL
explicit Target(
const ffi::String& tag_or_config_or_target_str);
148 TVM_DLL
explicit Target(
const ffi::Map<ffi::String, ffi::Any>& config);
173 ffi::Array<ffi::String> keys, ffi::Map<ffi::String, ffi::Any> attrs);
183 TVM_DLL
void EnterWithScope();
188 TVM_DLL
void ExitWithScope();
Managed reference class to TargetKindNode.
Definition: target_kind.h:103
Compilation target.
Definition: target.h:46
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:117
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:53
ffi::Map< ffi::String, Any > attrs
Collection of attributes (includes feature.* keys set by canonicalizer)
Definition: target.h:57
static void RegisterReflection()
Definition: target.h:81
ffi::Optional< Target > GetHost() const
friend class TargetInternal
Definition: target.h:128
ffi::Array< ffi::String > keys
Keys for this target.
Definition: target.h:55
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition: target.h:121
bool HasKey(const std::string &query_key) const
Check if the target contains a key.
ffi::Optional< ObjectRef > host
Target host information, must be Target type.
Definition: target.h:51
TargetKind kind
The kind of the target device.
Definition: target.h:49
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:99
ffi::Map< ffi::String, ffi::Any > ToConfig() const
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("target.Target", TargetNode, Object)
Managed reference class to TargetNode.
Definition: target.h:135
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:138
Target WithoutHost() const
friend class TargetInternal
Definition: target.h:176
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:59
Abstract device memory management API.
Definition: repr_printer.h:91
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
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 ...
RAII wrapper function to enter and exit a context object similar to python's with syntax.