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_XLA_SERVICE_GPU_CHOLESKY_THUNK_H_ 17 #define TENSORFLOW_COMPILER_XLA_SERVICE_GPU_CHOLESKY_THUNK_H_ 18 19 #include "absl/types/optional.h" 20 #include "tensorflow/compiler/xla/service/buffer_assignment.h" 21 #include "tensorflow/compiler/xla/service/gpu/buffer_allocations.h" 22 #include "tensorflow/compiler/xla/service/gpu/cusolver_context.h" 23 #include "tensorflow/compiler/xla/service/gpu/gpu_executable.h" 24 #include "tensorflow/compiler/xla/service/gpu/hlo_execution_profiler.h" 25 #include "tensorflow/compiler/xla/service/gpu/thunk.h" 26 #include "tensorflow/compiler/xla/service/hlo_instruction.h" 27 #include "tensorflow/compiler/xla/types.h" 28 #include "tensorflow/compiler/xla/xla_data.pb.h" 29 #include "tensorflow/core/lib/core/status.h" 30 #include "tensorflow/core/platform/stream_executor_no_cuda.h" 31 #include "tensorflow/core/platform/thread_annotations.h" 32 #include "tensorflow/stream_executor/blas.h" 33 34 namespace xla { 35 namespace gpu { 36 37 // This class stores everything that StreamExecutor needs to launch a Cholesky 38 // decomposition (LAPACK potrf). It is generated by IrEmitter. 39 // 40 // Thread-compatible. 41 class CholeskyThunk : public Thunk { 42 public: 43 static StatusOr<int64> ScratchBufferSize(int64 n); 44 CholeskyThunk(ThunkInfo thunk_info, const CholeskyOptions& options, 45 BufferAllocation::Slice a_buffer, 46 BufferAllocation::Slice workspace_buffer, 47 BufferAllocation::Slice info_buffer, PrimitiveType type, 48 int64 batch_size, int64 n); 49 50 CholeskyThunk(const CholeskyThunk&) = delete; 51 CholeskyThunk& operator=(const CholeskyThunk&) = delete; 52 53 Status ExecuteOnStream(const ExecuteParams& params) override; 54 55 private: 56 se::blas::UpperLower uplo_; 57 58 const BufferAllocation::Slice a_buffer_; 59 const BufferAllocation::Slice workspace_buffer_; 60 const BufferAllocation::Slice info_buffer_; 61 62 const PrimitiveType type_; 63 const int64 batch_size_; 64 const int64 a_batch_stride_; 65 const int64 n_; 66 67 tensorflow::mutex mu_; 68 absl::flat_hash_map<se::Stream*, CusolverContext> contexts_ 69 TF_GUARDED_BY(mu_); 70 }; 71 72 } // namespace gpu 73 } // namespace xla 74 75 #endif // TENSORFLOW_COMPILER_XLA_SERVICE_GPU_CHOLESKY_THUNK_H_ 76