24 #ifndef TVM_TE_TENSOR_H_
25 #define TVM_TE_TENSOR_H_
32 #include <type_traits>
82 v->Visit(
"shape", &
shape);
83 v->Visit(
"dtype", &dtype);
85 v->Visit(
"value_index", &value_index);
94 static constexpr const
char* _type_key = "
Tensor";
127 inline size_t ndim()
const;
133 template <
typename... Args>
136 return operator()(indices);
155 template <
typename... Args>
158 return IndexWithNegativeIndices(indices);
181 : tensor_(tensor), indices_(indices) {}
188 std::vector<PrimExpr> other = indices_;
189 other.emplace_back(i);
190 return Slice(tensor_, other);
197 inline operator PrimExpr()
const {
return tensor_(indices_); }
201 std::vector<PrimExpr> indices_;
217 if (get() == other.
get())
return true;
218 if (get() ==
nullptr || other.
get() ==
nullptr)
return false;
219 if ((*this)->op.defined() || other->op.
defined()) {
220 return (*this)->op == other->op && (*this)->value_index == other->value_index;
229 #define DEFINE_OVERLOAD_SLICE_UNARY_OP(Op) \
230 inline PrimExpr operator Op(const Tensor::Slice& a) { return Op a.operator PrimExpr(); }
232 #define DEFINE_OVERLOAD_SLICE_BINARY_OP(Op) \
233 template <typename T> \
234 inline PrimExpr operator Op(const Tensor::Slice& a, const T& b) { \
235 return a.operator PrimExpr() Op b; \
237 template <typename T> \
238 inline PrimExpr operator Op(const T& a, const Tensor::Slice& b) { \
239 return a Op b.operator PrimExpr(); \
241 inline PrimExpr operator Op(const Tensor::Slice& a, const Tensor::Slice& b) { \
242 return a.operator PrimExpr() Op b.operator PrimExpr(); \
270 std::size_t operator()(const ::tvm::te::Tensor& k)
const {
272 if (k.defined() && k->op.defined()) {
273 return hasher(k->op);
Visitor class to get the attributes of an AST/IR node. The content is going to be called for each fie...
Definition: reflection.h:52
Reference to PrimExprNode.
Definition: expr.h:115
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
Runtime primitive data type.
Definition: data_type.h:43
A custom smart pointer for Object.
Definition: object.h:362
Base class of all object reference.
Definition: object.h:519
bool defined() const
Definition: object.h:552
const Object * get() const
Definition: object.h:554
base class of all object containers.
Definition: object.h:171
Reference to string objects.
Definition: string.h:98
Base class of all operation nodes.
Definition: operation.h:56
Operation that produces tensors.
Definition: tensor.h:47
Tensor output(size_t i) const
get the i-th output of the operation.
Operation(ObjectPtr< Object > n)
Definition: tensor.h:51
Operation()
default constructor
Definition: tensor.h:50
Node to represent a tensor.
Definition: tensor.h:68
Array< PrimExpr > shape
The shape of the tensor.
Definition: tensor.h:71
TensorNode()
constructor
Definition: tensor.h:79
void VisitAttrs(AttrVisitor *v)
Definition: tensor.h:81
DataType GetDataType() const final
Get the data type of the result.
Definition: tensor.h:90
String GetNameHint() const final
Get the name hint of the data producer.
Array< PrimExpr > GetShape() const final
Get the shape of the result.
Definition: tensor.h:88
DataType dtype
data type in the content of the tensor
Definition: tensor.h:73
Operation op
the source operation, can be None
Definition: tensor.h:75
data structure to represent a slice that fixes first k coordinates. This is used to enable syntax sug...
Definition: tensor.h:177
Slice operator[](PrimExpr i)
get i-th slice from the current slice.
Definition: tensor.h:187
Slice(const Tensor &tensor, std::vector< PrimExpr > indices)
Definition: tensor.h:180
Tensor structure representing a possible input, or intermediate computation result.
Definition: tensor.h:102
bool operator==(const Tensor &other) const
check if two tensors equals each other.
Definition: tensor.h:216
PrimExpr operator()(Array< Var > 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:156
Slice operator[](PrimExpr i) const
get i-th slice from the current Tensor.
Definition: tensor.h:208
PrimExpr IndexWithNegativeIndices(Array< PrimExpr > indices) const
Take elements from the tensor with support for negative indices.
size_t ndim() const
Definition: tensor.h:214
PrimExpr IndexWithNegativeIndices(Array< Var > indices) const
Take elements from the tensor with support for negative indices.
bool operator!=(const Tensor &other) const
check if two tensors are different.
Definition: tensor.h:226
PrimExpr operator()(Array< PrimExpr > indices) const
Take elements from the tensor.
PrimExpr operator()(Args &&... args) const
Take elements from the tensor.
Definition: tensor.h:134
TVM_DEFINE_OBJECT_REF_METHODS(Tensor, DataProducer, TensorNode)
Tensor(Array< PrimExpr > shape, DataType dtype, Operation op, int value_index)
Base node for data producers.
Definition: buffer.h:276
Managed reference to DataProducerNode.
Definition: buffer.h:313
PrimExpr operator==(const Tensor::Slice &a, const T &b)
Definition: tensor.h:250
PrimExpr operator!=(const Tensor::Slice &a, const T &b)
Definition: tensor.h:253
Definition: extracted_task.h:30
Tensor shape(const Tensor &src, DataType dtype, const std::string name="T_shape", const std::string tag=kInjective)
Get the shape of input tensor.
Definition: transform.h:1913
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
#define TVM_DECLARE_FINAL_OBJECT_INFO(TypeName, ParentType)
helper macro to declare type information in a final class.
Definition: object.h:702
ObjectRef hash functor.
Definition: object.h:655
#define DEFINE_OVERLOAD_SLICE_UNARY_OP(Op)
Definition: tensor.h:229
#define DEFINE_OVERLOAD_SLICE_BINARY_OP(Op)
Definition: tensor.h:232
Common operators defined for Expr.