• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_CUSOLVER_CONTEXT_H_
17 #define TENSORFLOW_COMPILER_XLA_SERVICE_GPU_CUSOLVER_CONTEXT_H_
18 
19 #include <complex>
20 
21 #include "cuda/include/cublas_v2.h"
22 #include "cuda/include/cusolverDn.h"
23 #include "tensorflow/compiler/xla/statusor.h"
24 #include "tensorflow/compiler/xla/types.h"
25 #include "tensorflow/compiler/xla/util.h"
26 #include "tensorflow/core/lib/core/status.h"
27 #include "tensorflow/core/platform/stream_executor_no_cuda.h"
28 #include "tensorflow/stream_executor/blas.h"
29 
30 namespace xla {
31 namespace gpu {
32 
33 class CusolverContext {
34  public:
35   static StatusOr<CusolverContext> Create(se::Stream* stream);
36   CusolverContext() = default;
37   ~CusolverContext();
38 
39   CusolverContext(const CusolverContext&) = delete;
40   CusolverContext(CusolverContext&&);
41   CusolverContext& operator=(const CusolverContext&) = delete;
42   CusolverContext& operator=(CusolverContext&&);
43 
stream()44   se::Stream* stream() const { return stream_; }
handle()45   cusolverDnHandle_t handle() const { return handle_; }
46 
47   // Computes the Cholesky factorization A = L * L^T for a single matrix.
48   // Returns Status::OK() if the kernel was launched successfully. See:
49   // http://docs.nvidia.com/cuda/cusolver/#cuds-lt-t-gt-potrf
50   Status Potrf(se::blas::UpperLower uplo, int n, se::DeviceMemory<float> dev_A,
51                int lda, se::DeviceMemory<int> dev_lapack_info,
52                se::DeviceMemory<float> workspace);
53   Status Potrf(se::blas::UpperLower uplo, int n, se::DeviceMemory<double> dev_A,
54                int lda, se::DeviceMemory<int> dev_lapack_info,
55                se::DeviceMemory<double> workspace);
56   Status Potrf(se::blas::UpperLower uplo, int n,
57                se::DeviceMemory<std::complex<float>> dev_A, int lda,
58                se::DeviceMemory<int> dev_lapack_info,
59                se::DeviceMemory<std::complex<float>> workspace);
60   Status Potrf(se::blas::UpperLower uplo, int n,
61                se::DeviceMemory<std::complex<double>> dev_A, int lda,
62                se::DeviceMemory<int> dev_lapack_info,
63                se::DeviceMemory<std::complex<double>> workspace);
64 
65   // Returns the size of the `workspace` required by Potrf, in number of
66   // elements of size T.
67   StatusOr<int64> PotrfBufferSize(se::blas::UpperLower uplo, int n,
68                                   se::DeviceMemory<float> dev_A, int lda);
69   StatusOr<int64> PotrfBufferSize(se::blas::UpperLower uplo, int n,
70                                   se::DeviceMemory<double> dev_A, int lda);
71   StatusOr<int64> PotrfBufferSize(se::blas::UpperLower uplo, int n,
72                                   se::DeviceMemory<std::complex<float>> dev_A,
73                                   int lda);
74   StatusOr<int64> PotrfBufferSize(se::blas::UpperLower uplo, int n,
75                                   se::DeviceMemory<std::complex<double>> dev_A,
76                                   int lda);
77 
78  private:
79   CusolverContext(se::Stream* stream, cusolverDnHandle_t handle);
80 
81   se::Stream* stream_ = nullptr;
82   cusolverDnHandle_t handle_ = nullptr;
83 };
84 
85 }  // namespace gpu
86 }  // namespace xla
87 
88 #endif  // TENSORFLOW_COMPILER_XLA_SERVICE_GPU_CUSOLVER_CONTEXT_H_
89