24#ifndef TVM_TE_TENSOR_H_
25#define TVM_TE_TENSOR_H_
28#include <tvm/ffi/reflection/registry.h>
43using s_tir::IterVarObj;
67 explicit Operation(ffi::UnsafeInit tag) : ffi::ObjectRef(tag) {}
91 ffi::Optional<Operation>
op;
120 inline PrimExpr IndexTensor(ffi::Array<PrimExpr> indices,
bool support_negative_indices)
const;
123 TVM_DLL
Tensor(ffi::Array<PrimExpr> shape,
PrimType dtype, ffi::Optional<Operation> op,
139 inline size_t ndim()
const;
145 template <
typename... Args>
147 ffi::Array<PrimExpr> indices{std::forward<Args>(args)...};
167 template <
typename... Args>
169 ffi::Array<PrimExpr> indices{std::forward<Args>(args)...};
193 : tensor_(tensor), indices_(indices) {}
200 std::vector<PrimExpr> other = indices_;
201 other.emplace_back(i);
202 return Slice(tensor_, other);
209 inline operator PrimExpr()
const {
return tensor_(indices_); }
213 std::vector<PrimExpr> indices_;
240 if (get() == other.get())
return true;
241 if (get() ==
nullptr || other.get() ==
nullptr)
return false;
242 if ((*this)->op.has_value() || other->op.has_value()) {
243 return (*this)->op == other->op && (*this)->value_index == other->value_index;
252#define DEFINE_OVERLOAD_SLICE_UNARY_OP(Op) \
253 inline PrimExpr operator Op(const Tensor::Slice& a) { return Op a.operator PrimExpr(); }
255#define DEFINE_OVERLOAD_SLICE_BINARY_OP(Op) \
256 template <typename T> \
257 inline PrimExpr operator Op(const Tensor::Slice& a, const T& b) { \
258 return a.operator PrimExpr() Op b; \
260 template <typename T> \
261 inline PrimExpr operator Op(const T& a, const Tensor::Slice& b) { \
262 return a Op b.operator PrimExpr(); \
264 inline PrimExpr operator Op(const Tensor::Slice& a, const Tensor::Slice& b) { \
265 return a.operator PrimExpr() Op b.operator PrimExpr(); \
293 std::size_t operator()(const ::tvm::te::Tensor& k)
const {
294 ::tvm::ffi::ObjectPtrHash hasher;
295 if (k.defined() && k->op.has_value()) {
296 return hasher(k->op.value());
Shared primitive construction and constant helpers.
TIRx tensor expressions and construction helpers.
Managed reference to CallObj.
Definition expr.h:825
Managed reference to ExprObj.
Definition expr.h:101
Base node for opaque construction-time expressions.
Definition expr.h:136
Managed reference to OpaqueExprObj.
Definition expr.h:148
Typed reference/view over any Expr whose ExprObj::ty is PrimType.
Definition expr.h:187
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:64
Tensor output(size_t i) const
get the i-th output of the operation.
static constexpr bool _type_is_nullable
Definition tensor.h:66
const OperationObj * operator->() const
access the internal node container
Definition operation.h:521
Operation(ffi::UnsafeInit tag)
Definition tensor.h:67
Opaque construction-time node that represents a tensor.
Definition tensor.h:84
ffi::Array< PrimExpr > shape
The shape of the tensor.
Definition tensor.h:87
int value_index
the output index from source operation
Definition tensor.h:93
ffi::Array< PrimExpr > GetShape() const
Definition tensor.h:97
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition tensor.h:103
PrimType dtype
dtype in the content of the tensor
Definition tensor.h:89
ffi::String GetNameHint() const
ffi::Optional< Operation > op
the source operation, can be None
Definition tensor.h:91
PrimType GetDataType() const
Definition tensor.h:99
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("te.Tensor", TensorObj, OpaqueExprObj)
static void RegisterReflection()
data structure to represent a slice that fixes first k coordinates. This is used to enable syntax sug...
Definition tensor.h:189
Slice operator[](PrimExpr i)
get i-th slice from the current slice.
Definition tensor.h:199
Slice(const Tensor &tensor, std::vector< PrimExpr > indices)
Definition tensor.h:192
Tensor structure representing a possible input, or intermediate computation result.
Definition tensor.h:112
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:239
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:168
Slice operator[](PrimExpr i) const
get i-th slice from the current Tensor.
Definition tensor.h:220
size_t ndim() const
Definition tensor.h:237
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:249
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Tensor, OpaqueExpr, TensorObj)
PrimExpr operator()(Args &&... args) const
Take elements from the tensor.
Definition tensor.h:146
Tensor(ffi::ObjectPtr< TensorObj > node)
Definition tensor.h:222
Tensor(ffi::Array< PrimExpr > shape, PrimType dtype, ffi::Optional< Operation > op, int value_index)
Parent compiler symbol visibility.
#define DEFINE_OVERLOAD_SLICE_UNARY_OP(Op)
Definition tensor.h:252
#define DEFINE_OVERLOAD_SLICE_BINARY_OP(Op)
Definition tensor.h:255
Axis metadata for schedulable tensor computations.
const char * IterVarType2String(IterVarType t)
Definition iter_var.h:160
IterVarType
Type of iteration variable. Each IterVar have a specific type.
Definition iter_var.h:40
@ kOrdered
Serial loops with loop carry dependency, the iteration must execute in order. Cannot be re-ordered.
Definition iter_var.h:72
@ kTensorized
Marks boundary of tensorization intrinsic.
Definition iter_var.h:100
@ kThreadIndex
The IterVar itself is a thread-index of a fixed thread launching group. Note that this is already ass...
Definition iter_var.h:57
@ kParallelized
The loop is parallelized.
Definition iter_var.h:96
@ kCommReduce
Communicative reduction. Cannot be directly parallelized.
Definition iter_var.h:64
@ kOpaque
IterVar is opaque,.
Definition iter_var.h:82
@ kDataPar
Data parallel iteration. This normally corresponds to axis of Tensor. Allow all IterVar manipulations...
Definition iter_var.h:49
@ kUnrolled
The execution is unrolled.
Definition iter_var.h:88
@ kVectorized
The loop is vectorized.
Definition iter_var.h:92
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.
Definition axis_group_graph.h:41
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analysis.h:41