xref: /aosp_15_r20/external/tensorflow/tensorflow/compiler/xla/service/gpu/triangular_solve_thunk.h (revision b6fb3261f9314811a0f4371741dbb8839866f948)
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_TRIANGULAR_SOLVE_THUNK_H_
17 #define TENSORFLOW_COMPILER_XLA_SERVICE_GPU_TRIANGULAR_SOLVE_THUNK_H_
18 
19 #include <optional>
20 
21 #include "tensorflow/compiler/xla/service/buffer_assignment.h"
22 #include "tensorflow/compiler/xla/service/gpu/buffer_allocations.h"
23 #include "tensorflow/compiler/xla/service/gpu/thunk.h"
24 #include "tensorflow/compiler/xla/service/hlo_instruction.h"
25 #include "tensorflow/compiler/xla/types.h"
26 #include "tensorflow/compiler/xla/xla_data.pb.h"
27 #include "tensorflow/core/lib/core/status.h"
28 #include "tensorflow/core/platform/stream_executor_no_cuda.h"
29 #include "tensorflow/stream_executor/blas.h"
30 #include "tensorflow/stream_executor/gpu/gpu_asm_opts.h"
31 
32 namespace xla {
33 namespace gpu {
34 
35 // This class stores everything that StreamExecutor needs to launch a triangular
36 // solve (BlasTrsm). It is generated by IrEmitter.
37 //
38 // Thread-compatible.
39 class TriangularSolveThunk : public Thunk {
40  public:
41   TriangularSolveThunk(ThunkInfo thunk_info,
42                        const TriangularSolveOptions& options,
43                        se::GpuAsmOpts asm_opts,
44                        const BufferAllocation::Slice& a_buffer,
45                        const BufferAllocation::Slice& b_buffer,
46                        const BufferAllocation::Slice& temp_buffer,
47                        PrimitiveType type, int64_t batch_size, int64_t m,
48                        int64_t n, int64_t a_batch_stride,
49                        int64_t b_batch_stride);
50 
51   TriangularSolveThunk(const TriangularSolveThunk&) = delete;
52   TriangularSolveThunk& operator=(const TriangularSolveThunk&) = delete;
53 
54   Status ExecuteOnStream(const ExecuteParams& params) override;
55 
56  private:
57   se::GpuAsmOpts asm_opts_;
58   const se::blas::UpperLower uplo_;
59   const se::blas::Side side_;
60   const se::blas::Diagonal unit_diagonal_;
61   se::blas::Transpose transpose_a_;
62 
63   const BufferAllocation::Slice a_buffer_;
64   const BufferAllocation::Slice b_buffer_;
65   const BufferAllocation::Slice temp_buffer_;
66 
67   const PrimitiveType type_;
68   const int64_t batch_size_;
69   const int64_t m_;
70   const int64_t n_;
71   const int64_t a_batch_stride_;
72   const int64_t b_batch_stride_;
73 };
74 
75 Status RunTriangulatSolve(se::DeviceMemoryBase a_data,
76                           se::DeviceMemoryBase b_data,
77                           se::DeviceMemoryBase temp_data,
78                           se::GpuAsmOpts asm_opts, se::blas::UpperLower uplo,
79                           se::blas::Side side, se::blas::Diagonal unit_diagonal,
80                           se::blas::Transpose transpose_a, PrimitiveType type,
81                           int64_t batch_size, int64_t m, int64_t n,
82                           int64_t a_batch_stride, int64_t b_batch_stride,
83                           se::Stream* stream);
84 
85 }  // namespace gpu
86 }  // namespace xla
87 
88 #endif  // TENSORFLOW_COMPILER_XLA_SERVICE_GPU_TRIANGULAR_SOLVE_THUNK_H_
89