tvm
einsum.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
24 #ifndef TVM_TOPI_EINSUM_H_
25 #define TVM_TOPI_EINSUM_H_
26 
27 #define LABELRANGE 128
28 #define NPY_MAXDIMS 16
29 #define NPY_MAXARGS 16
30 
31 #include <tvm/te/operation.h>
32 #include <tvm/tir/data_layout.h>
36 #include <tvm/topi/tags.h>
37 
38 #include <algorithm>
39 #include <bitset>
40 #include <iterator>
41 #include <string>
42 #include <tuple>
43 #include <unordered_set>
44 #include <vector>
45 
46 namespace tvm {
47 namespace topi {
48 
49 using namespace tvm::te;
50 using namespace topi::detail;
51 
59 Array<PrimExpr> InferEinsumShape(const std::string& subscripts,
60  const std::vector<Array<PrimExpr>>& operands);
61 
73 Tensor einsum(const std::string& subscripts_str, const Array<Tensor> inputs,
74  std::string name = "T_einsum", std::string tag = kEinsum);
75 
82  static EinsumEquation FromString(const std::string& equation);
83  using Label = char;
84  using Subscript = std::vector<Label>;
85  // Special label value for ellipsis. The value is chosen to be less than any other letters so make
86  // sorting easier.
87  static constexpr Label kEllipsis = '\0';
88  // The input subscripts for each operand of the Einsum operator.
89  std::vector<Subscript> inputs;
90  // The output subscript of the Einsum equation.
92 };
93 
94 } // namespace topi
95 } // namespace tvm
96 #endif // TVM_TOPI_EINSUM_H_
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
Tensor structure representing a possible input, or intermediate computation result.
Definition: tensor.h:102
Utility functions for handling constants in TVM expressions.
Layout expression to describe the data organization of a tensor. And BijectiveLayout to mapping two d...
Tensor expression language DSL.
Definition: extracted_task.h:33
constexpr auto kEinsum
Definition: tags.h:44
Array< PrimExpr > InferEinsumShape(const std::string &subscripts, const std::vector< Array< PrimExpr >> &operands)
Compute the shape of the output.
Tensor einsum(const std::string &subscripts_str, const Array< Tensor > inputs, std::string name="T_einsum", std::string tag=kEinsum)
Evaluates the Einstein summation convention on the operands.
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
Operation node can generate one or multiple Tensors.
Index ravel and unraval operations.
Definition: einsum.h:76
static EinsumEquation FromString(const std::string &equation)
Create EinsumEquation from a string. The result will be converted to the explicit mode of Einsum if i...
char Label
Definition: einsum.h:83
std::vector< Label > Subscript
Definition: einsum.h:84
std::vector< Subscript > inputs
Definition: einsum.h:89
Subscript output
Definition: einsum.h:91
External function interface to rocBLAS libraries.
Utility functions for handling tensor.