24#ifndef TVM_TE_TENSOR_H_
25#define TVM_TE_TENSOR_H_
28#include <tvm/ffi/reflection/registry.h>
52 explicit Operation(ffi::ObjectPtr<ffi::Object>
n) : ffi::ObjectRef(
n) {}
53 explicit Operation(ffi::UnsafeInit tag) : ffi::ObjectRef(tag) {}
124 inline size_t ndim()
const;
130 template <
typename...
Args>
132 ffi::Array<PrimExpr> indices{std::forward<Args>(args)...};
152 template <
typename...
Args>
154 ffi::Array<PrimExpr> indices{std::forward<Args>(args)...};
178 : tensor_(tensor), indices_(indices) {}
185 std::vector<PrimExpr>
other = indices_;
194 inline operator PrimExpr()
const {
return tensor_(indices_); }
198 std::vector<PrimExpr> indices_;
223 if (get() ==
other.
get())
return true;
224 if (get() ==
nullptr ||
other.
get() ==
nullptr)
return false;
225 if ((*this)->op.defined() ||
other->op.defined()) {
226 return (*this)->op ==
other->op && (*this)->value_index ==
other->value_index;
235#define DEFINE_OVERLOAD_SLICE_UNARY_OP(Op) \
236 inline PrimExpr operator Op(const Tensor::Slice& a) { return Op a.operator PrimExpr(); }
238#define DEFINE_OVERLOAD_SLICE_BINARY_OP(Op) \
239 template <typename T> \
240 inline PrimExpr operator Op(const Tensor::Slice& a, const T& b) { \
241 return a.operator PrimExpr() Op b; \
243 template <typename T> \
244 inline PrimExpr operator Op(const T& a, const Tensor::Slice& b) { \
245 return a Op b.operator PrimExpr(); \
247 inline PrimExpr operator Op(const Tensor::Slice& a, const Tensor::Slice& b) { \
248 return a.operator PrimExpr() Op b.operator PrimExpr(); \
276 std::size_t operator()(const ::tvm::te::Tensor& k)
const {
277 ::tvm::ffi::ObjectPtrHash
hasher;
278 if (k.defined() && k->op.defined()) {
Managed reference to CallNode.
Definition expr.h:474
Managed reference to ExprNode.
Definition base_expr.h:335
Base node for opaque construction-time expressions.
Definition base_expr.h:352
Managed reference to OpaqueExprNode.
Definition base_expr.h:364
Typed reference/view over any Expr whose ExprNode::ty is PrimType.
Definition base_expr.h:401
Definition base_expr.h:137
static PrimType Void()
Construct the void sentinel type, encoded as handle(0, 0).
RAII wrapper function to enter and exit a context object similar to python's with syntax.
Definition with_context.h:59
ContextType * get()
Definition with_context.h:81
Base class of all operation nodes.
Definition operation.h:157
Operation that produces tensors.
Definition tensor.h:48
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:507
Operation()
default constructor
Definition tensor.h:51
Operation(ffi::UnsafeInit tag)
Definition tensor.h:53
Operation(ffi::ObjectPtr< ffi::Object > n)
Definition tensor.h:52
Opaque construction-time node that represents a tensor.
Definition tensor.h:70
ffi::Array< PrimExpr > GetShape() const
Definition tensor.h:83
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("te.Tensor", TensorNode, OpaqueExprNode)
ffi::Array< PrimExpr > shape
The shape of the tensor.
Definition tensor.h:73
static void RegisterReflection()
Operation op
the source operation, can be None
Definition tensor.h:77
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition tensor.h:89
ffi::String GetNameHint() const
PrimType dtype
dtype in the content of the tensor
Definition tensor.h:75
int value_index
the output index from source operation
Definition tensor.h:79
PrimType GetDataType() const
Definition tensor.h:85
data structure to represent a slice that fixes first k coordinates. This is used to enable syntax sug...
Definition tensor.h:174
Slice operator[](PrimExpr i)
get i-th slice from the current slice.
Definition tensor.h:184
Slice(const Tensor &tensor, std::vector< PrimExpr > indices)
Definition tensor.h:177
Tensor structure representing a possible input, or intermediate computation result.
Definition tensor.h:98
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:222
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:153
Slice operator[](PrimExpr i) const
get i-th slice from the current Tensor.
Definition tensor.h:205
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Tensor, OpaqueExpr, TensorNode)
size_t ndim() const
Definition tensor.h:220
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:232
PrimExpr operator()(Args &&... args) const
Take elements from the tensor.
Definition tensor.h:131
Tensor(ffi::Array< PrimExpr > shape, PrimType dtype, Operation op, int value_index)
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 is a Call whose callee is a TE Tensor.
Tensor GetTensorFromLoad(const Call &call)
Recover and validate the Tensor callee of a tensor-load Call.
Definition axis_group_graph.h:39
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analyzer.h:40
#define DEFINE_OVERLOAD_SLICE_UNARY_OP(Op)
Definition tensor.h:235
#define DEFINE_OVERLOAD_SLICE_BINARY_OP(Op)
Definition tensor.h:238
Common operators defined for Expr.