24 #ifndef TVM_TOPI_DETAIL_EXTERN_H_ 25 #define TVM_TOPI_DETAIL_EXTERN_H_ 48 inline Buffer DeclExternBuffer(Array<PrimExpr>
shape,
DataType dtype, std::string name) {
50 auto elem_offset = PrimExpr();
51 return Buffer(data, dtype, shape, Array<PrimExpr>(), elem_offset, name, -1, 0, kDefault);
59 using FExtern = std::function<PrimExpr(Array<Buffer>, Array<Buffer>)>;
78 inline Array<Tensor> make_extern(
const Array<Array<PrimExpr>>& out_shapes,
79 const std::vector<DataType>& out_types,
80 const Array<Tensor>& inputs, FExtern fextern, std::string name,
82 ICHECK_EQ(out_shapes.size(), out_types.size())
83 <<
"make_extern: out_shapes and out_types must have equal size";
85 Array<Buffer> input_placeholders;
86 for (
auto t : inputs) {
87 input_placeholders.push_back(DeclExternBuffer(t->shape, t->dtype, t->op->name));
89 Array<Buffer> output_placeholders;
90 for (
size_t i = 0; i < out_shapes.size(); ++i) {
91 output_placeholders.push_back(DeclExternBuffer(out_shapes[i], out_types[i], name));
94 auto body = fextern(input_placeholders, output_placeholders);
97 auto op =
ExternOp(name, tag, attrs, inputs, input_placeholders, output_placeholders, body_stmt);
99 Array<Tensor> outputs;
100 for (
size_t i = 0; i < output_placeholders.size(); ++i) {
101 outputs.push_back(op.output(i));
114 inline PrimExpr pack_buffer(Buffer buf) {
115 ICHECK_GT(buf->shape.size(), 0) <<
"buf shape must have at least one element";
119 if (buf->strides.size() > 0) {
125 Array<PrimExpr> pack_args{buf->data,
143 inline PrimExpr call_packed(Array<PrimExpr> args) {
150 #endif // TVM_TOPI_DETAIL_EXTERN_H_ PrimExpr make_const(DataType t, ValueType value, Span span=Span())
Make a const value with certain data type.
Definition: op.h:954
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
Tensor expression language DSL.
Definition: extracted_task.h:33
Managed reference to CallNode.
Definition: expr.h:913
const Op & tvm_call_packed()
See pesudo code.
static DataType Handle(int bits=64, int lanes=1)
Construct a handle type.
Definition: data_type.h:198
const Op & tvm_stack_make_array()
Allocate a NDArray(DLTensor) on stack, return the handle.
Managed reference to ExternOpNode.
Definition: operation.h:460
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:1768
const Op & tvm_stack_make_shape()
Allocate a shape tuple on stack, return the handle.
Var var(std::string name_hint, DataType t=DataType::Int(32))
Construct a new Var expression.
Operation node can generate one or multiple Tensors.
Map container of NodeRef->NodeRef in DSL graph. Map implements copy on write semantics, which means map is mutable but copy will happen when array is referenced in more than two places.
Definition: map.h:1271
void Evaluate(PrimExpr value)
Evaluate the input expression.
runtime::DataType DataType
Definition: data_type.h:398
static DataType Int(int bits, int lanes=1)
Construct an int type.
Definition: data_type.h:164