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_GPU_LAYOUT_ASSIGNMENT_H_ 17 #define TENSORFLOW_COMPILER_XLA_SERVICE_GPU_GPU_LAYOUT_ASSIGNMENT_H_ 18 19 #include "tensorflow/compiler/xla/service/computation_layout.h" 20 #include "tensorflow/compiler/xla/service/hlo_instructions.h" 21 #include "tensorflow/compiler/xla/service/layout_assignment.h" 22 #include "tensorflow/core/lib/core/status.h" 23 #include "tensorflow/core/platform/stream_executor_no_cuda.h" 24 25 namespace xla { 26 namespace gpu { 27 28 // GPU-specific layout assignment pass which preassigns layouts to satisfy 29 // layout constraints for operands and results of library calls. 30 class GpuLayoutAssignment : public LayoutAssignment { 31 public: 32 explicit GpuLayoutAssignment( 33 ComputationLayout* entry_computation_layout, 34 se::StreamExecutor* stream_executor, 35 ChannelLayoutConstraints* channel_constraints = nullptr) LayoutAssignment(entry_computation_layout,channel_constraints)36 : LayoutAssignment(entry_computation_layout, channel_constraints), 37 stream_executor_(stream_executor) {} ~GpuLayoutAssignment()38 ~GpuLayoutAssignment() override {} 39 40 protected: 41 Status AddBackendConstraints(LayoutConstraints* constraints) override; 42 43 private: 44 Status AddBackendConstraintsToDnnConvCustomCall( 45 HloCustomCallInstruction* instr, LayoutConstraints* constraints); 46 47 Status SetOperandBatchRowsColsLayout(const HloInstruction* instruction, 48 int64_t operand, 49 absl::Span<const int64_t> batch_dims, 50 absl::Span<const int64_t> row_dims, 51 absl::Span<const int64_t> col_dims); 52 53 Status SetDotOperandLayout(const HloInstruction* instruction, int64_t operand, 54 absl::Span<const int64_t> batch_dims, 55 absl::Span<const int64_t> row_dims, 56 absl::Span<const int64_t> col_dims); 57 58 Status SetDotLayout(const HloInstruction* instruction, 59 LayoutConstraints* constraints); 60 61 se::StreamExecutor* stream_executor_; 62 }; 63 64 } // namespace gpu 65 } // namespace xla 66 67 #endif // TENSORFLOW_COMPILER_XLA_SERVICE_GPU_GPU_LAYOUT_ASSIGNMENT_H_ 68