mxnet
util.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 
25 #ifndef NNVM_COMPILER_UTIL_H_
26 #define NNVM_COMPILER_UTIL_H_
27 
28 #include <tvm/expr.h>
29 #include <nnvm/tuple.h>
30 
31 namespace nnvm {
32 namespace compiler {
33 
34 /*
35  * \brief Helper function to convert TShape to TVM array. Useful for
36  * passing data from NNVM param structures to TOPI ops.
37  *
38  * \param shape The shape to convert
39  *
40  * \return An Array of Expr, where each element is a constant int32
41  */
42 inline tvm::Array<tvm::Expr> ShapeToArray(TShape shape) {
43  tvm::Array<tvm::Expr> result;
44  for (auto i : shape) {
45  result.push_back(tvm::make_const(tvm::Int(32), i));
46  }
47  return result;
48 }
49 
50 /*
51  * \brief Helper function to convert TShape to TVM array. Useful for
52  * passing data from NNVM param structures to TOPI ops.
53  *
54  * \param shape The shape to convert
55  *
56  * \return An Array of Expr, where each element is a constant int32
57  */
58 inline tvm::Array<tvm::Integer> ShapeToIntArray(TShape shape) {
59  return tvm::Array<tvm::Integer>(ShapeToArray(shape).node_);
60 }
61 } // namespace compiler
62 } // namespace nnvm
63 #endif // NNVM_COMPILER_UTIL_H_
Definition: base.h:36
A Shape class that is used to represent shape of each tensor.
Definition: tuple.h:344
tvm::Array< tvm::Expr > ShapeToArray(TShape shape)
Definition: util.h:42
Data structure Tuple and TShape to store dynamic sized shapes.
tvm::Array< tvm::Integer > ShapeToIntArray(TShape shape)
Definition: util.h:58