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_GPU_STREAM_ASSIGNMENT_H_ 17 #define TENSORFLOW_COMPILER_XLA_SERVICE_GPU_STREAM_ASSIGNMENT_H_ 18 19 #include "absl/container/flat_hash_map.h" 20 #include "tensorflow/compiler/xla/service/hlo_instruction.h" 21 #include "tensorflow/compiler/xla/service/hlo_module.h" 22 23 namespace xla { 24 namespace gpu { 25 26 // This class encapsulates the assignment of GPU streams to each HloInstruction. 27 class StreamAssignment { 28 public: StreamCount()29 int StreamCount() const { return stream_count_; } 30 int StreamNumberForHlo(const HloInstruction& hlo) const; 31 bool HasStreamAssigned(const HloInstruction& hlo) const; 32 // `hlo` needs to outlive this StreamAssignment object. 33 void AssignStreamToHlo(const HloInstruction* hlo, int stream_no); 34 35 private: 36 int stream_count_ = 1; // At least the main stream. 37 absl::flat_hash_map<const HloInstruction*, int> hlo_to_stream_number_; 38 }; 39 40 // Assigns GPU streams to instructions in `module`. 41 std::unique_ptr<StreamAssignment> AssignStreams(const HloModule& module); 42 43 } // namespace gpu 44 } // namespace xla 45 46 #endif // TENSORFLOW_COMPILER_XLA_SERVICE_GPU_STREAM_ASSIGNMENT_H_ 47