23#ifndef TVM_RUNTIME_MEMORY_SCOPE_H_
24#define TVM_RUNTIME_MEMORY_SCOPE_H_
26#include <tvm/ffi/enum.h>
27#include <tvm/ffi/reflection/enum_def.h>
49 "runtime.memory_alloc_property"};
72 const ffi::String&
name()
const {
return get()->_str_index; }
75 return ffi::reflection::EnumDef<MemoryScopeObj>::IsDefined(
name);
81 namespace refl = ffi::reflection;
82 detail::RegisterBuiltinMemoryScopes();
83 TVM_FFI_CHECK(!
name.empty(), ValueError) <<
"Memory scope name must not be empty";
84 TVM_FFI_CHECK(std::string_view(
name.data(),
name.size()).find(
'\0') == std::string_view::npos,
86 <<
"Memory scope name must not contain a null character";
87 refl::EnumDef<MemoryScopeObj>(
name.c_str());
99 return os << scope.
name();
105inline constexpr bool use_default_type_traits_v<runtime::MemoryScope> =
false;
107struct TypeTraits<runtime::MemoryScope>
108 :
public ObjectRefWithFallbackTraitsBase<runtime::MemoryScope, ffi::String> {
110 return runtime::MemoryScope::Get(name);
#define TVM_RUNTIME_DLL
Definition base.h:73
Canonical identity of an extensible memory space.
Definition memory_scope.h:53
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("runtime.MemoryScope", MemoryScopeObj, ffi::EnumObj)
A registered memory space, independent of backend allocation policy.
Definition memory_scope.h:65
static bool IsDefined(const ffi::String &name)
Test whether a name is registered, without initializing memory scopes.
Definition memory_scope.h:74
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(MemoryScope, ffi::Enum, MemoryScopeObj)
static MemoryScope Register(const ffi::String &name)
Register a new name. Duplicate names raise ValueError.
Definition memory_scope.h:80
MemoryScope(const ffi::String &name)
Look up a registered name; never implicitly register it.
Definition memory_scope.h:70
static TVM_RUNTIME_DLL const MemoryScope & Global()
Return the canonical global singleton.
const ffi::String & name() const
Return the canonical spelling.
Definition memory_scope.h:72
static TVM_RUNTIME_DLL MemoryScope Get(const ffi::String &name)
Look up a registered name. Unknown names raise ValueError.
bool operator!=(const MemoryScope &other) const
Definition memory_scope.h:93
bool operator==(const MemoryScope &other) const
Definition memory_scope.h:92
MemoryScope()
Default to the global memory space.
Definition memory_scope.h:68
constexpr ffi::reflection::AttrKey< MemoryAllocProperty > kMemoryAllocProperty
Integer-valued MemoryAllocProperty; absence denotes kNormal.
Definition memory_scope.h:48
MemoryAllocProperty
Allocation behavior associated with a memory scope.
Definition memory_scope.h:40
std::ostream & operator<<(std::ostream &os, DLDevice dev)
Definition device_api.h:322
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analysis.h:41
static runtime::MemoryScope ConvertFallbackValue(ffi::String name)
Definition memory_scope.h:109