24#ifndef TVM_TE_TENSOR_H_
25#define TVM_TE_TENSOR_H_
27#include <tvm/ffi/reflection/registry.h>
42using s_tir::IterVarNode;
66 explicit Operation(ffi::UnsafeInit tag) : ffi::ObjectRef(tag) {}
90 ffi::Optional<Operation>
op;
119 inline PrimExpr IndexTensor(ffi::Array<PrimExpr> indices,
bool support_negative_indices)
const;
122 TVM_DLL
Tensor(ffi::Array<PrimExpr> shape,
PrimType dtype, ffi::Optional<Operation> op,
138 inline size_t ndim()
const;
144 template <
typename... Args>
146 ffi::Array<PrimExpr> indices{std::forward<Args>(args)...};
166 template <
typename... Args>
168 ffi::Array<PrimExpr> indices{std::forward<Args>(args)...};
192 : tensor_(tensor), indices_(indices) {}
199 std::vector<PrimExpr> other = indices_;
200 other.emplace_back(i);
201 return Slice(tensor_, other);
208 inline operator PrimExpr()
const {
return tensor_(indices_); }
212 std::vector<PrimExpr> indices_;
239 if (get() == other.get())
return true;
240 if (get() ==
nullptr || other.get() ==
nullptr)
return false;
241 if ((*this)->op.has_value() || other->op.has_value()) {
242 return (*this)->op == other->op && (*this)->value_index == other->value_index;
251#define DEFINE_OVERLOAD_SLICE_UNARY_OP(Op) \
252 inline PrimExpr operator Op(const Tensor::Slice& a) { return Op a.operator PrimExpr(); }
254#define DEFINE_OVERLOAD_SLICE_BINARY_OP(Op) \
255 template <typename T> \
256 inline PrimExpr operator Op(const Tensor::Slice& a, const T& b) { \
257 return a.operator PrimExpr() Op b; \
259 template <typename T> \
260 inline PrimExpr operator Op(const T& a, const Tensor::Slice& b) { \
261 return a Op b.operator PrimExpr(); \
263 inline PrimExpr operator Op(const Tensor::Slice& a, const Tensor::Slice& b) { \
264 return a.operator PrimExpr() Op b.operator PrimExpr(); \
292 std::size_t operator()(const ::tvm::te::Tensor& k)
const {
293 ::tvm::ffi::ObjectPtrHash hasher;
294 if (k.defined() && k->op.has_value()) {
295 return hasher(k->op.value());
Managed reference to CallNode.
Definition expr.h:972
Managed reference to ExprNode.
Definition base_expr.h:359
Base node for opaque construction-time expressions.
Definition base_expr.h:394
Managed reference to OpaqueExprNode.
Definition base_expr.h:406
Typed reference/view over any Expr whose ExprNode::ty is PrimType.
Definition base_expr.h:447
Definition base_expr.h:161
static TVM_TIRX_DLL PrimType Void()
Construct the void sentinel type, encoded as handle(0, 0).
Base class of all operation nodes.
Definition operation.h:165
Operation that produces tensors.
Definition tensor.h:63
Tensor output(size_t i) const
get the i-th output of the operation.
const OperationNode * operator->() const
access the internal node container
Definition operation.h:521
static constexpr bool _type_is_nullable
Definition tensor.h:65
Operation(ffi::UnsafeInit tag)
Definition tensor.h:66
Opaque construction-time node that represents a tensor.
Definition tensor.h:83
ffi::Array< PrimExpr > GetShape() const
Definition tensor.h:96
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("te.Tensor", TensorNode, OpaqueExprNode)
ffi::Array< PrimExpr > shape
The shape of the tensor.
Definition tensor.h:86
ffi::Optional< Operation > op
the source operation, can be None
Definition tensor.h:90
static void RegisterReflection()
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition tensor.h:102
ffi::String GetNameHint() const
PrimType dtype
dtype in the content of the tensor
Definition tensor.h:88
int value_index
the output index from source operation
Definition tensor.h:92
PrimType GetDataType() const
Definition tensor.h:98
data structure to represent a slice that fixes first k coordinates. This is used to enable syntax sug...
Definition tensor.h:188
Slice operator[](PrimExpr i)
get i-th slice from the current slice.
Definition tensor.h:198
Slice(const Tensor &tensor, std::vector< PrimExpr > indices)
Definition tensor.h:191
Tensor structure representing a possible input, or intermediate computation result.
Definition tensor.h:111
PrimExpr IndexWithNegativeIndices(ffi::Array< PrimExpr > indices) const
Take elements from the tensor with support for negative indices.
PrimExpr IndexWithNegativeIndices(ffi::Array< PrimVar > indices) const
Take elements from the tensor with support for negative indices.
bool operator==(const Tensor &other) const
check if two tensors equals each other.
Definition tensor.h:238
PrimExpr operator()(ffi::Array< PrimVar > indices) const
Take elements from the tensor.
PrimExpr IndexWithNegativeIndices(Args &&... args) const
Take elements from the tensor with support for negative indices.
Definition tensor.h:167
Slice operator[](PrimExpr i) const
get i-th slice from the current Tensor.
Definition tensor.h:219
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Tensor, OpaqueExpr, TensorNode)
size_t ndim() const
Definition tensor.h:236
Tensor(ffi::ObjectPtr< TensorNode > node)
Definition tensor.h:221
PrimExpr operator()(ffi::Array< PrimExpr > indices) const
Take elements from the tensor.
bool operator!=(const Tensor &other) const
check if two tensors are different.
Definition tensor.h:248
PrimExpr operator()(Args &&... args) const
Take elements from the tensor.
Definition tensor.h:145
Tensor(ffi::Array< PrimExpr > shape, PrimType dtype, ffi::Optional< Operation > op, int value_index)
Shared primitive construction and constant helpers.
Axis metadata for schedulable tensor computations.
const char * IterVarType2String(IterVarType t)
Definition iter_var.h:159
IterVarType
Type of iteration variable. Each IterVar have a specific type.
Definition iter_var.h:39
@ kOrdered
Serial loops with loop carry dependency, the iteration must execute in order. Cannot be re-ordered.
Definition iter_var.h:71
@ kTensorized
Marks boundary of tensorization intrinsic.
Definition iter_var.h:99
@ kThreadIndex
The IterVar itself is a thread-index of a fixed thread launching group. Note that this is already ass...
Definition iter_var.h:56
@ kParallelized
The loop is parallelized.
Definition iter_var.h:95
@ kCommReduce
Communicative reduction. Cannot be directly parallelized.
Definition iter_var.h:63
@ kOpaque
IterVar is opaque,.
Definition iter_var.h:81
@ kDataPar
Data parallel iteration. This normally corresponds to axis of Tensor. Allow all IterVar manipulations...
Definition iter_var.h:48
@ kUnrolled
The execution is unrolled.
Definition iter_var.h:87
@ kVectorized
The loop is vectorized.
Definition iter_var.h:91
ffi::Array< PrimExpr > GetTensorLoadIndices(const Call &call)
Recover and validate the primitive indices of a tensor-load Call.
bool IsTensorLoad(const Expr &expr)
Return whether an expression calls the registered te.tensor_load operator.
Tensor GetTensorFromLoad(const Call &call)
Recover and validate the first Tensor argument of a tensor-load Call.
Backend-defined execution hierarchy nodes shared by layouts and tile calls.
Definition axis_group_graph.h:41
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition attr.h:23
#define DEFINE_OVERLOAD_SLICE_UNARY_OP(Op)
Definition tensor.h:251
#define DEFINE_OVERLOAD_SLICE_BINARY_OP(Op)
Definition tensor.h:254
TIRx tensor expressions and construction helpers.