24#ifndef TVM_TIRX_EXPR_H_
25#define TVM_TIRX_EXPR_H_
27#include <tvm/ffi/container/array.h>
28#include <tvm/ffi/reflection/registry.h>
29#include <tvm/ffi/string.h>
58 <<
"Expected a non-null Var with TensorType";
77 ffi::String
scope()
const {
return (*this)->storage_scope; }
93 explicit TensorVar(ffi::ObjectPtr<VarNode> node) :
Var(std::move(node)) {}
98 const auto* var_node =
static_cast<const VarNode*
>(data_.get());
99 TVM_FFI_ICHECK(var_node !=
nullptr);
101 TVM_FFI_ICHECK(type_node !=
nullptr)
102 <<
"Expected a Var with TensorType, but " << var_node->name <<
" has type " << var_node->ty;
123 return ffi::make_object<TensorTypeNode>(*var.operator->());
127 ffi::Optional<ffi::String> name = std::nullopt) {
142 ffi::String name =
"tensor", ffi::String storage_scope =
"",
158 std::string name,
int data_alignment,
160 std::string memory_scope =
"");
183inline constexpr bool use_default_type_traits_v<tirx::TensorVar> =
false;
186struct TypeTraits<tirx::TensorVar> :
public ObjectRefTypeTraitsBase<tirx::TensorVar> {
187 using Base = ObjectRefTypeTraitsBase<tirx::TensorVar>;
188 using Base::CopyFromAnyViewAfterCheck;
189 using Base::CopyToAnyView;
190 using Base::GetMismatchTypeInfo;
191 using Base::MoveFromAnyAfterCheck;
192 using Base::MoveToAny;
193 using Base::TypeSchema;
197 if (src->type_index == TypeIndex::kTVMFFINone) {
200 if (src->type_index != tvm::VarNode::RuntimeTypeIndex()) {
204 details::ObjectUnsafe::ObjectPtrFromUnowned<Object>(src->v_obj).get());
205 return details::AnyUnsafe::CheckAnyStrict<tirx::TensorType>(var->ExprNode::ty);
209 if (CheckAnyStrict(src)) {
210 return details::ObjectUnsafe::ObjectRefFromObjectPtr<tirx::TensorVar>(
211 details::ObjectUnsafe::ObjectPtrFromUnowned<tvm::VarNode>(src->v_obj));
Managed reference to CallNode.
Definition expr.h:972
Type ty
The deduced or annotated type of the expression.
Definition base_expr.h:338
Location loc
Location that points to the original source code. Reserved debug information.
Definition base_expr.h:330
Managed reference to ExprNode.
Definition base_expr.h:359
Non-nullable source-location metadata.
Definition location.h:91
Definition base_expr.h:161
static TVM_TIRX_DLL PrimType Float(int bits, int lanes=1)
Construct a floating-point type with fixed lanes.
Managed reference to TensorLoadNode.
Definition expr.h:464
Managed reference to TensorRegionNode.
Definition expr.h:1079
Reference to the shared immutable unknown location.
Definition location.h:105
A local variable in the IR.
Definition expr.h:694
ffi::String name
The variable name.
Definition expr.h:697
Managed reference to VarNode.
Definition expr.h:714
Structural type of a TIRx tensor variable.
Definition type.h:64
Managed reference to TensorTypeNode.
Definition type.h:146
Checked zero-state view over an ordinary VarNode with TensorType.
Definition expr.h:50
Expr data() const
Project the physical pointer established by the definition site.
Definition expr.h:74
TVM_TIRX_DLL bool IsScalar(bool alloc_or_decl=true) const
Return a new tensor with the allocated address.
const ffi::String & name() const
Return the tensor's diagnostic name.
Definition expr.h:68
TensorType type() const
Return the tensor type carried by the ordinary variable.
Definition expr.h:65
TensorVar(Var var)
Create a checked tensor view over an existing ordinary Var.
Definition expr.h:56
Var var() const
Return the ordinary variable view over the same identity.
Definition expr.h:62
TensorVar(ffi::UnsafeInit tag)
Definition expr.h:94
TVM_FFI_DEFINE_DEFAULT_COPY_MOVE_AND_ASSIGN(TensorVar)
const VarNode * get() const
Definition expr.h:106
const Location & loc() const
Return the source location carried by the ordinary Var.
Definition expr.h:71
ffi::String scope() const
Return the storage scope associated with this tensor.
Definition expr.h:77
static constexpr bool _type_container_is_exact
Definition expr.h:109
static constexpr bool _type_is_nullable
Definition expr.h:108
TensorVar(ffi::ObjectPtr< VarNode > node)
Definition expr.h:93
PrimType ElementType() const
Definition expr.h:91
TVM_TIRX_DLL TensorVar(ffi::String name, TensorType type, Location loc=UnknownLoc())
Construct a fresh tensor variable from an explicit TensorType.
const TensorTypeNode * operator->() const
Definition expr.h:97
Definition base_expr.h:487
ffi::ObjectPtr< TensorTypeNode > CopyTensorType(const TensorVar &var)
Definition expr.h:122
TVM_TIRX_DLL const Op & tensor_data_ptr_op()
Project the physical pointer associated with a TensorVar definition.
TVM_TIRX_DLL tirx::TensorVar TensorWithOffsetAlignment(ffi::Array< PrimExpr > shape, PrimType dtype, std::string name, int data_alignment, int offset_factor, std::string memory_scope="")
Creates a TIR tensor for the provided parameters.
TVM_TIRX_DLL TensorRegion TensorRegionFromPoint(TensorVar tensor, ffi::Array< PrimExpr > indices)
Construct unit or vector-lane ranges from point indices.
TVM_TIRX_DLL TensorVar decl_tensor(ffi::Array< PrimExpr > shape, PrimType dtype=PrimType::Float(32), ffi::String name="tensor", ffi::String storage_scope="", Location loc=UnknownLoc())
Construct a new tensor given shape, and dtype.
bool operator!=(const TensorVar &lhs, const TensorVar &rhs)
Definition expr.h:117
TensorVar GetTensorVar(const VarNode *var)
Recover a checked tensor view from an ordinary VarNode pointer.
Definition expr.h:120
TVM_TIRX_DLL TensorLoad MakeTensorLoad(TensorVar tensor, ffi::Array< PrimExpr > indices, Location loc=UnknownLoc())
Construct a TensorLoad from a TensorVar.
bool operator==(const TensorVar &lhs, const TensorVar &rhs)
Definition expr.h:115
TVM_TIRX_DLL TensorRegion FullTensorRegion(TensorVar tensor)
Select the entire tensor.
TensorVar RebuildTensorVar(const TensorVar &var, ffi::ObjectPtr< TensorTypeNode > type, ffi::Optional< ffi::String > name=std::nullopt)
Definition expr.h:126
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition attr.h:23
#define TVM_TIRX_DLL
Definition base.h:83
static TVM_FFI_INLINE bool CheckAnyStrict(const TVMFFIAny *src)
Definition expr.h:196
static TVM_FFI_INLINE std::optional< tirx::TensorVar > TryCastFromAnyView(const TVMFFIAny *src)
Definition expr.h:208
ObjectRefTypeTraitsBase< tirx::TensorVar > Base
Definition expr.h:187
Memory operations for TIRx.