1 /* Copyright 2017 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_XLA_SERVICE_HLO_PARSER_H_ 17 #define TENSORFLOW_COMPILER_XLA_SERVICE_HLO_PARSER_H_ 18 19 #include "absl/memory/memory.h" 20 #include "absl/strings/string_view.h" 21 #include "tensorflow/compiler/xla/service/hlo_computation.h" 22 #include "tensorflow/compiler/xla/service/hlo_instruction.h" 23 #include "tensorflow/compiler/xla/service/hlo_lexer.h" 24 #include "tensorflow/compiler/xla/service/hlo_module.h" 25 #include "tensorflow/compiler/xla/statusor.h" 26 #include "tensorflow/compiler/xla/xla_data.pb.h" 27 28 namespace xla { 29 30 // For details about the syntax accepted by this parser, see 31 // g3doc/hlo_parser.md. 32 33 // Given a string in the HloModule::ToString() format, parses the string and 34 // creates a HloModule with the given config. 35 StatusOr<std::unique_ptr<HloModule>> ParseHloString( 36 absl::string_view str, const HloModuleConfig& config); 37 38 // Given a string in the HloModule::ToString() format, parses the string and 39 // builds the HloModule in place at the given module pointer. 'module' must 40 // point to an empty module (no computations). 41 Status ParseHloString(absl::string_view str, HloModule* module); 42 43 // Given a string in the HloModule::ToString() format, parses the string and 44 // creates a HloModule with default config. 45 StatusOr<std::unique_ptr<HloModule>> ParseHloString(absl::string_view str); 46 47 // Parses sharding from str. str is supposed to contain the body of the 48 // sharding, i.e. just the rhs of the "sharding={...}" attribute string, e.g., 49 // "{replicated}". 50 StatusOr<HloSharding> ParseSharding(absl::string_view str); 51 52 // Parses parameter replication from str. str is supposed to contain the body of 53 // the parameter replication, i.e. just the rhs of the 54 // "parameter_replication={...}" attribute string, e.g., "{true, false}". 55 StatusOr<std::vector<bool>> ParseParameterReplication(absl::string_view str); 56 57 // Parses the result of window_util::ToString(const Window&). 58 StatusOr<Window> ParseWindow(absl::string_view str); 59 60 // Parses the result of ConvolutionDimensionNumbersToString(), e.g. 61 // "b0f_0io->b0f". 62 StatusOr<ConvolutionDimensionNumbers> ParseConvolutionDimensionNumbers( 63 absl::string_view str); 64 65 // Parses the result of PaddingConfigToString(), e.g. "0_0x1_1". 66 StatusOr<PaddingConfig> ParsePaddingConfig(absl::string_view str); 67 68 // Parses and returns a Shape::ToString-format string. 69 StatusOr<Shape> ParseShape(absl::string_view str); 70 71 } // namespace xla 72 73 #endif // TENSORFLOW_COMPILER_XLA_SERVICE_HLO_PARSER_H_ 74