18 #ifndef TENSORFLOW_COMPILER_XLA_SERVICE_HLO_MODULE_H_ 19 #define TENSORFLOW_COMPILER_XLA_SERVICE_HLO_MODULE_H_ 26 #include <unordered_map> 29 #include "tensorflow/compiler/xla/iterator_util.h" 30 #include "tensorflow/compiler/xla/service/hlo.pb.h" 33 #include "tensorflow/compiler/xla/service/hlo_module_config.h" 34 #include "tensorflow/compiler/xla/service/name_uniquer.h" 36 #include "tensorflow/compiler/xla/types.h" 37 #include "tensorflow/core/lib/gtl/array_slice.h" 38 #include "tensorflow/core/lib/gtl/iterator_range.h" 39 #include "tensorflow/core/platform/logging.h" 40 #include "tensorflow/core/platform/mutex.h" 56 const HloModuleConfig& config);
63 explicit HloModule(
const string& name,
const HloModuleConfig& config);
68 std::unique_ptr<HloComputation> computation);
72 std::unique_ptr<HloComputation> computation);
84 void ReplaceComputations(
85 const std::unordered_map<HloComputation*, HloComputation*>& replacements);
87 const string& name()
const {
return name_; }
90 std::unique_ptr<HloModule> Clone(
const string& suffix =
"clone")
const;
98 CHECK_NE(
nullptr, entry_computation_);
99 return entry_computation_;
102 CHECK_NE(
nullptr, entry_computation_);
103 return entry_computation_;
106 ComputationLayout* mutable_entry_computation_layout() {
107 return config_.mutable_entry_computation_layout();
110 const ComputationLayout& entry_computation_layout()
const {
111 return config_.entry_computation_layout();
115 return entry_computation_handle_;
125 tensorflow::gtl::iterator_range<UnwrappingIterator<
126 std::vector<std::unique_ptr<HloComputation>>::const_iterator>>
127 computations()
const {
128 return {MakeUnwrappingIterator(computations_.begin()),
129 MakeUnwrappingIterator(computations_.end())};
131 tensorflow::gtl::iterator_range<UnwrappingIterator<
132 std::vector<std::unique_ptr<HloComputation>>::iterator>>
134 return {MakeUnwrappingIterator(computations_.begin()),
135 MakeUnwrappingIterator(computations_.end())};
139 int64 computation_count()
const {
return computations_.size(); }
142 int64 instruction_count()
const;
147 std::list<HloComputation*> MakeComputationPostOrder()
const;
154 const HloModuleConfig& config()
const {
return config_; }
160 string ToString()
const {
return ToString(HloPrintOptions()); }
161 string ToString(
const HloPrintOptions& options)
const;
164 HloModuleProto ToProto()
const;
165 static StatusOr<std::unique_ptr<HloModule>> CreateFromProto(
166 const HloModuleProto& proto,
const HloModuleConfig& module_config,
172 static StatusOr<HloModuleConfig> CreateModuleConfigFromProto(
173 const HloModuleProto& module,
const DebugOptions& debug_options);
182 tensorflow::gtl::ArraySlice<HloInstruction*> instructions_to_outline,
183 const string& outlined_computation_name,
HloComputation* computation);
186 uint64 RandomNew64()
const;
189 NameUniquer& instruction_name_uniquer() {
return instruction_name_uniquer_; }
192 int NewUniqueInstructionId() {
193 int result = next_unique_id_;
200 int NumUniqueInstructionIds()
const {
return next_unique_id_; }
204 int unique_id()
const {
return unique_id_; }
208 std::unique_ptr<HloComputation> computation,
bool is_entry,
209 bool uniquify_names);
212 HloModuleConfig config_;
214 std::vector<std::unique_ptr<HloComputation>> computations_;
220 mutable std::mt19937_64 rng_{42};
221 mutable tensorflow::mutex rng_mutex_;
224 bool has_entry_computation_handle_ =
false;
229 NameUniquer computation_name_uniquer_{
"."};
230 NameUniquer instruction_name_uniquer_{
"."};
231 int next_unique_id_ = 0;
234 static std::atomic<int> next_unique_module_id_;
241 #endif // TENSORFLOW_COMPILER_XLA_SERVICE_HLO_MODULE_H_
Definition: hlo_computation.h:60
Definition: versioned_computation_handle.h:37
std::vector< HloComputation * > MakeNonfusionComputations() const
Definition: hlo_module.cc:474
Definition: hlo_instruction.h:165
namespace for xla
Definition: client_library.cc:26
Definition: hlo_module.h:52