• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #ifndef TENSORFLOW_COMPILER_MLIR_TENSORFLOW_UTILS_MANGLING_UTIL_H_
17 #define TENSORFLOW_COMPILER_MLIR_TENSORFLOW_UTILS_MANGLING_UTIL_H_
18 
19 #include "absl/strings/string_view.h"
20 #include "tensorflow/core/framework/tensor.pb.h"
21 #include "tensorflow/core/framework/tensor_shape.pb.h"
22 #include "tensorflow/core/framework/types.h"
23 #include "tensorflow/core/lib/core/status.h"
24 
25 namespace tensorflow {
26 namespace mangling_util {
27 // The type of a mangled string.
28 enum class MangledKind { kUnknown, kDataType, kTensorShape, kTensor };
29 
30 // Mangles an attribute name, marking the attribute as a TensorFlow attribute.
31 string MangleAttributeName(absl::string_view str);
32 
33 // Returns true if 'str' was mangled with MangleAttributeName.
34 bool IsMangledAttributeName(absl::string_view str);
35 
36 // Demangles an attribute name that was manged with MangleAttributeName.
37 // REQUIRES: IsMangledAttributeName returns true.
38 absl::string_view DemangleAttributeName(absl::string_view str);
39 
40 // Returns the type of a mangled string, or kUnknown.
41 MangledKind GetMangledKind(absl::string_view str);
42 
43 // Return a TensorShapeProto mangled as a string.
44 string MangleShape(const TensorShapeProto& shape);
45 // Demangle a string mangled with MangleShape.
46 Status DemangleShape(absl::string_view str, TensorShapeProto* proto);
47 
48 // Return a TensorProto mangled as a string.
49 string MangleTensor(const TensorProto& tensor);
50 // Demangle a string mangled with MangleTensor.
51 Status DemangleTensor(absl::string_view str, TensorProto* proto);
52 
53 // Return a DataType mangled as a string.
54 string MangleDataType(const DataType& dtype);
55 // Demangle a string mangled with MangleDataType.
56 Status DemangleDataType(absl::string_view str, DataType* proto);
57 
58 }  // namespace mangling_util
59 }  // namespace tensorflow
60 
61 #endif  // TENSORFLOW_COMPILER_MLIR_TENSORFLOW_UTILS_MANGLING_UTIL_H_
62