Open3D (C++ API)  0.18.0
LapackWrapper.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2023 www.open3d.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
12 #include "open3d/utility/Logging.h"
13 
14 namespace open3d {
15 namespace core {
16 template <typename scalar_t>
17 inline OPEN3D_CPU_LINALG_INT getrf_cpu(int layout,
20  scalar_t* A_data,
22  OPEN3D_CPU_LINALG_INT* ipiv_data) {
23  utility::LogError("Unsupported data type.");
24  return -1;
25 }
26 
27 template <typename scalar_t>
28 inline OPEN3D_CPU_LINALG_INT getri_cpu(int layout,
30  scalar_t* A_data,
32  OPEN3D_CPU_LINALG_INT* ipiv_data) {
33  utility::LogError("Unsupported data type.");
34  return -1;
35 }
36 
37 template <typename scalar_t>
38 inline OPEN3D_CPU_LINALG_INT gesv_cpu(int layout,
41  scalar_t* A_data,
43  OPEN3D_CPU_LINALG_INT* ipiv_data,
44  scalar_t* B_data,
46  utility::LogError("Unsupported data type.");
47  return -1;
48 }
49 
50 template <typename scalar_t>
51 inline OPEN3D_CPU_LINALG_INT gels_cpu(int matrix_layout,
52  char trans,
56  scalar_t* A_data,
58  scalar_t* B_data,
60  utility::LogError("Unsupported data type.");
61  return -1;
62 }
63 
64 template <typename scalar_t>
65 inline OPEN3D_CPU_LINALG_INT gesvd_cpu(int matrix_layout,
66  char jobu,
67  char jobvt,
70  scalar_t* A_data,
72  scalar_t* S_data,
73  scalar_t* U_data,
75  scalar_t* VT_data,
77  scalar_t* superb) {
78  utility::LogError("Unsupported data type.");
79  return -1;
80 }
81 
82 template <>
84  int layout,
87  float* A_data,
89  OPEN3D_CPU_LINALG_INT* ipiv_data) {
90  return LAPACKE_sgetrf(layout, m, n, A_data, lda, ipiv_data);
91 }
92 
93 template <>
95  int layout,
98  double* A_data,
100  OPEN3D_CPU_LINALG_INT* ipiv_data) {
101  return LAPACKE_dgetrf(layout, m, n, A_data, lda, ipiv_data);
102 }
103 
104 template <>
106  int layout,
108  float* A_data,
110  OPEN3D_CPU_LINALG_INT* ipiv_data) {
111  return LAPACKE_sgetri(layout, n, A_data, lda, ipiv_data);
112 }
113 
114 template <>
116  int layout,
118  double* A_data,
120  OPEN3D_CPU_LINALG_INT* ipiv_data) {
121  return LAPACKE_dgetri(layout, n, A_data, lda, ipiv_data);
122 }
123 
124 template <>
128  float* A_data,
130  OPEN3D_CPU_LINALG_INT* ipiv_data,
131  float* B_data,
132  OPEN3D_CPU_LINALG_INT ldb) {
133  return LAPACKE_sgesv(layout, n, m, A_data, lda, ipiv_data, B_data, ldb);
134 }
135 
136 template <>
140  double* A_data,
142  OPEN3D_CPU_LINALG_INT* ipiv_data,
143  double* B_data,
144  OPEN3D_CPU_LINALG_INT ldb) {
145  return LAPACKE_dgesv(layout, n, m, A_data, lda, ipiv_data, B_data, ldb);
146 }
147 
148 template <>
150  char trans,
154  float* A_data,
156  float* B_data,
157  OPEN3D_CPU_LINALG_INT ldb) {
158  return LAPACKE_sgels(layout, trans, m, n, nrhs, A_data, lda, B_data, ldb);
159 }
160 
161 template <>
163  char trans,
167  double* A_data,
169  double* B_data,
170  OPEN3D_CPU_LINALG_INT ldb) {
171  return LAPACKE_dgels(layout, trans, m, n, nrhs, A_data, lda, B_data, ldb);
172 }
173 
174 template <>
176  char jobu,
177  char jobvt,
180  float* A_data,
182  float* S_data,
183  float* U_data,
185  float* VT_data,
187  float* superb) {
188  return LAPACKE_sgesvd(layout, jobu, jobvt, m, n, A_data, lda, S_data,
189  U_data, ldu, VT_data, ldvt, superb);
190 }
191 
192 template <>
194  char jobu,
195  char jobvt,
198  double* A_data,
200  double* S_data,
201  double* U_data,
203  double* VT_data,
205  double* superb) {
206  return LAPACKE_dgesvd(layout, jobu, jobvt, m, n, A_data, lda, S_data,
207  U_data, ldu, VT_data, ldvt, superb);
208 }
209 
210 #ifdef BUILD_CUDA_MODULE
211 template <typename scalar_t>
212 inline cusolverStatus_t getrf_cuda_buffersize(
213  cusolverDnHandle_t handle, int m, int n, int lda, int* len) {
214  utility::LogError("Unsupported data type.");
215  return CUSOLVER_STATUS_INTERNAL_ERROR;
216 }
217 
218 template <typename scalar_t>
219 inline cusolverStatus_t getrf_cuda(cusolverDnHandle_t handle,
220  int m,
221  int n,
222  scalar_t* A_data,
223  int lda,
224  scalar_t* workspace,
225  int* ipiv_data,
226  int* dinfo) {
227  utility::LogError("Unsupported data type.");
228  return CUSOLVER_STATUS_INTERNAL_ERROR;
229 }
230 
231 template <typename scalar_t>
232 inline cusolverStatus_t getrs_cuda(cusolverDnHandle_t handle,
233  cublasOperation_t trans,
234  int n,
235  int nrhs,
236  const scalar_t* A_data,
237  int lda,
238  const int* ipiv_data,
239  scalar_t* B_data,
240  int ldb,
241  int* dinfo) {
242  utility::LogError("Unsupported data type.");
243  return CUSOLVER_STATUS_INTERNAL_ERROR;
244 }
245 
246 template <typename scalar_t>
247 inline cusolverStatus_t geqrf_cuda_buffersize(
248  cusolverDnHandle_t handle, int m, int n, int lda, int* len) {
249  utility::LogError("Unsupported data type.");
250  return CUSOLVER_STATUS_INTERNAL_ERROR;
251 }
252 
253 template <typename scalar_t>
254 inline cusolverStatus_t geqrf_cuda(cusolverDnHandle_t handle,
255  int m,
256  int n,
257  scalar_t* A,
258  int lda,
259  scalar_t* tau,
260  scalar_t* workspace,
261  int len,
262  int* dinfo) {
263  utility::LogError("Unsupported data type.");
264  return CUSOLVER_STATUS_INTERNAL_ERROR;
265 }
266 
267 template <typename scalar_t>
268 inline cusolverStatus_t ormqr_cuda_buffersize(cusolverDnHandle_t handle,
269  cublasSideMode_t side,
270  cublasOperation_t trans,
271  int m,
272  int n,
273  int k,
274  int lda,
275  int ldc,
276  int* len) {
277  utility::LogError("Unsupported data type.");
278  return CUSOLVER_STATUS_INTERNAL_ERROR;
279 }
280 
281 template <typename scalar_t>
282 inline cusolverStatus_t ormqr_cuda(cusolverDnHandle_t handle,
283  cublasSideMode_t side,
284  cublasOperation_t trans,
285  int m,
286  int n,
287  int k,
288  const scalar_t* A,
289  int lda,
290  const scalar_t* tau,
291  scalar_t* C,
292  int ldc,
293  scalar_t* workspace,
294  int len,
295  int* dinfo) {
296  utility::LogError("Unsupported data type.");
297  return CUSOLVER_STATUS_INTERNAL_ERROR;
298 }
299 
300 template <typename scalar_t>
301 inline cusolverStatus_t gesvd_cuda_buffersize(cusolverDnHandle_t handle,
302  int m,
303  int n,
304  int* len) {
305  utility::LogError("Unsupported data type.");
306  return CUSOLVER_STATUS_INTERNAL_ERROR;
307 }
308 
309 template <typename scalar_t>
310 inline cusolverStatus_t gesvd_cuda(cusolverDnHandle_t handle,
311  char jobu,
312  char jobvt,
313  int m,
314  int n,
315  scalar_t* A,
316  int lda,
317  scalar_t* S,
318  scalar_t* U,
319  int ldu,
320  scalar_t* VT,
321  int ldvt,
322  scalar_t* workspace,
323  int len,
324  scalar_t* rwork,
325  int* dinfo) {
326  utility::LogError("Unsupported data type.");
327  return CUSOLVER_STATUS_INTERNAL_ERROR;
328 }
329 
330 template <>
331 inline cusolverStatus_t getrf_cuda_buffersize<float>(
332  cusolverDnHandle_t handle, int m, int n, int lda, int* len) {
333  return cusolverDnSgetrf_bufferSize(handle, m, n, NULL, lda, len);
334 }
335 
336 template <>
337 inline cusolverStatus_t getrf_cuda_buffersize<double>(
338  cusolverDnHandle_t handle, int m, int n, int lda, int* len) {
339  return cusolverDnDgetrf_bufferSize(handle, m, n, NULL, lda, len);
340 }
341 
342 template <>
343 inline cusolverStatus_t getrf_cuda<float>(cusolverDnHandle_t handle,
344  int m,
345  int n,
346  float* A_data,
347  int lda,
348  float* workspace,
349  int* ipiv_data,
350  int* dinfo) {
351  return cusolverDnSgetrf(handle, m, n, A_data, lda, workspace, ipiv_data,
352  dinfo);
353 }
354 
355 template <>
356 inline cusolverStatus_t getrf_cuda<double>(cusolverDnHandle_t handle,
357  int m,
358  int n,
359  double* A_data,
360  int lda,
361  double* workspace,
362  int* ipiv_data,
363  int* dinfo) {
364  return cusolverDnDgetrf(handle, m, n, A_data, lda, workspace, ipiv_data,
365  dinfo);
366 }
367 
368 template <>
369 inline cusolverStatus_t getrs_cuda<float>(cusolverDnHandle_t handle,
370  cublasOperation_t trans,
371  int n,
372  int nrhs,
373  const float* A_data,
374  int lda,
375  const int* ipiv_data,
376  float* B_data,
377  int ldb,
378  int* dinfo) {
379  return cusolverDnSgetrs(handle, trans, n, nrhs, A_data, lda, ipiv_data,
380  B_data, ldb, dinfo);
381 }
382 
383 template <>
384 inline cusolverStatus_t getrs_cuda<double>(cusolverDnHandle_t handle,
385  cublasOperation_t trans,
386  int n,
387  int nrhs,
388  const double* A_data,
389  int lda,
390  const int* ipiv_data,
391  double* B_data,
392  int ldb,
393  int* dinfo) {
394  return cusolverDnDgetrs(handle, trans, n, nrhs, A_data, lda, ipiv_data,
395  B_data, ldb, dinfo);
396 }
397 
398 template <>
399 inline cusolverStatus_t geqrf_cuda_buffersize<float>(
400  cusolverDnHandle_t handle, int m, int n, int lda, int* len) {
401  return cusolverDnSgeqrf_bufferSize(handle, m, n, NULL, lda, len);
402 }
403 
404 template <>
405 inline cusolverStatus_t geqrf_cuda_buffersize<double>(
406  cusolverDnHandle_t handle, int m, int n, int lda, int* len) {
407  return cusolverDnDgeqrf_bufferSize(handle, m, n, NULL, lda, len);
408 }
409 
410 template <>
411 inline cusolverStatus_t geqrf_cuda<float>(cusolverDnHandle_t handle,
412  int m,
413  int n,
414  float* A,
415  int lda,
416  float* tau,
417  float* workspace,
418  int len,
419  int* dinfo) {
420  return cusolverDnSgeqrf(handle, m, n, A, lda, tau, workspace, len, dinfo);
421 }
422 
423 template <>
424 inline cusolverStatus_t geqrf_cuda<double>(cusolverDnHandle_t handle,
425  int m,
426  int n,
427  double* A,
428  int lda,
429  double* tau,
430  double* workspace,
431  int len,
432  int* dinfo) {
433  return cusolverDnDgeqrf(handle, m, n, A, lda, tau, workspace, len, dinfo);
434 }
435 
436 template <>
437 inline cusolverStatus_t ormqr_cuda_buffersize<float>(cusolverDnHandle_t handle,
438  cublasSideMode_t side,
439  cublasOperation_t trans,
440  int m,
441  int n,
442  int k,
443  int lda,
444  int ldc,
445  int* len) {
446  return cusolverDnSormqr_bufferSize(handle, side, trans, m, n, k, NULL, lda,
447  NULL, NULL, ldc, len);
448 }
449 
450 template <>
451 inline cusolverStatus_t ormqr_cuda_buffersize<double>(cusolverDnHandle_t handle,
452  cublasSideMode_t side,
453  cublasOperation_t trans,
454  int m,
455  int n,
456  int k,
457  int lda,
458  int ldc,
459  int* len) {
460  return cusolverDnDormqr_bufferSize(handle, side, trans, m, n, k, NULL, lda,
461  NULL, NULL, ldc, len);
462 }
463 
464 template <>
465 inline cusolverStatus_t ormqr_cuda<float>(cusolverDnHandle_t handle,
466  cublasSideMode_t side,
467  cublasOperation_t trans,
468  int m,
469  int n,
470  int k,
471  const float* A,
472  int lda,
473  const float* tau,
474  float* C,
475  int ldc,
476  float* workspace,
477  int len,
478  int* dinfo) {
479  return cusolverDnSormqr(handle, side, trans, m, n, k, A, lda, tau, C, ldc,
480  workspace, len, dinfo);
481 }
482 
483 template <>
484 inline cusolverStatus_t ormqr_cuda<double>(cusolverDnHandle_t handle,
485  cublasSideMode_t side,
486  cublasOperation_t trans,
487  int m,
488  int n,
489  int k,
490  const double* A,
491  int lda,
492  const double* tau,
493  double* C,
494  int ldc,
495  double* workspace,
496  int len,
497  int* dinfo) {
498  return cusolverDnDormqr(handle, side, trans, m, n, k, A, lda, tau, C, ldc,
499  workspace, len, dinfo);
500 }
501 
502 template <>
503 inline cusolverStatus_t gesvd_cuda_buffersize<float>(cusolverDnHandle_t handle,
504  int m,
505  int n,
506  int* len) {
507  return cusolverDnSgesvd_bufferSize(handle, m, n, len);
508 }
509 
510 template <>
511 inline cusolverStatus_t gesvd_cuda_buffersize<double>(cusolverDnHandle_t handle,
512  int m,
513  int n,
514  int* len) {
515  return cusolverDnDgesvd_bufferSize(handle, m, n, len);
516 }
517 
518 template <>
519 inline cusolverStatus_t gesvd_cuda<float>(cusolverDnHandle_t handle,
520  char jobu,
521  char jobvt,
522  int m,
523  int n,
524  float* A,
525  int lda,
526  float* S,
527  float* U,
528  int ldu,
529  float* VT,
530  int ldvt,
531  float* workspace,
532  int len,
533  float* rwork,
534  int* dinfo) {
535  return cusolverDnSgesvd(handle, jobu, jobvt, m, n, A, lda, S, U, ldu, VT,
536  ldvt, workspace, len, rwork, dinfo);
537 }
538 
539 template <>
540 inline cusolverStatus_t gesvd_cuda<double>(cusolverDnHandle_t handle,
541  char jobu,
542  char jobvt,
543  int m,
544  int n,
545  double* A,
546  int lda,
547  double* S,
548  double* U,
549  int ldu,
550  double* VT,
551  int ldvt,
552  double* workspace,
553  int len,
554  double* rwork,
555  int* dinfo) {
556  return cusolverDnDgesvd(handle, jobu, jobvt, m, n, A, lda, S, U, ldu, VT,
557  ldvt, workspace, len, rwork, dinfo);
558 }
559 
560 #endif
561 } // namespace core
562 } // namespace open3d
#define OPEN3D_CPU_LINALG_INT
Definition: LinalgHeadersCPU.h:23
#define LogError(...)
Definition: Logging.h:48
OPEN3D_CPU_LINALG_INT gesvd_cpu< double >(int layout, char jobu, char jobvt, OPEN3D_CPU_LINALG_INT m, OPEN3D_CPU_LINALG_INT n, double *A_data, OPEN3D_CPU_LINALG_INT lda, double *S_data, double *U_data, OPEN3D_CPU_LINALG_INT ldu, double *VT_data, OPEN3D_CPU_LINALG_INT ldvt, double *superb)
Definition: LapackWrapper.h:193
OPEN3D_CPU_LINALG_INT gels_cpu< float >(int layout, char trans, OPEN3D_CPU_LINALG_INT m, OPEN3D_CPU_LINALG_INT n, OPEN3D_CPU_LINALG_INT nrhs, float *A_data, OPEN3D_CPU_LINALG_INT lda, float *B_data, OPEN3D_CPU_LINALG_INT ldb)
Definition: LapackWrapper.h:149
OPEN3D_CPU_LINALG_INT gesv_cpu< double >(int layout, OPEN3D_CPU_LINALG_INT n, OPEN3D_CPU_LINALG_INT m, double *A_data, OPEN3D_CPU_LINALG_INT lda, OPEN3D_CPU_LINALG_INT *ipiv_data, double *B_data, OPEN3D_CPU_LINALG_INT ldb)
Definition: LapackWrapper.h:137
OPEN3D_CPU_LINALG_INT getri_cpu(int layout, OPEN3D_CPU_LINALG_INT n, scalar_t *A_data, OPEN3D_CPU_LINALG_INT lda, OPEN3D_CPU_LINALG_INT *ipiv_data)
Definition: LapackWrapper.h:28
OPEN3D_CPU_LINALG_INT getrf_cpu< double >(int layout, OPEN3D_CPU_LINALG_INT m, OPEN3D_CPU_LINALG_INT n, double *A_data, OPEN3D_CPU_LINALG_INT lda, OPEN3D_CPU_LINALG_INT *ipiv_data)
Definition: LapackWrapper.h:94
OPEN3D_CPU_LINALG_INT gels_cpu< double >(int layout, char trans, OPEN3D_CPU_LINALG_INT m, OPEN3D_CPU_LINALG_INT n, OPEN3D_CPU_LINALG_INT nrhs, double *A_data, OPEN3D_CPU_LINALG_INT lda, double *B_data, OPEN3D_CPU_LINALG_INT ldb)
Definition: LapackWrapper.h:162
OPEN3D_CPU_LINALG_INT gels_cpu(int matrix_layout, char trans, OPEN3D_CPU_LINALG_INT m, OPEN3D_CPU_LINALG_INT n, OPEN3D_CPU_LINALG_INT nrhs, scalar_t *A_data, OPEN3D_CPU_LINALG_INT lda, scalar_t *B_data, OPEN3D_CPU_LINALG_INT ldb)
Definition: LapackWrapper.h:51
OPEN3D_CPU_LINALG_INT getri_cpu< float >(int layout, OPEN3D_CPU_LINALG_INT n, float *A_data, OPEN3D_CPU_LINALG_INT lda, OPEN3D_CPU_LINALG_INT *ipiv_data)
Definition: LapackWrapper.h:105
OPEN3D_CPU_LINALG_INT getrf_cpu(int layout, OPEN3D_CPU_LINALG_INT m, OPEN3D_CPU_LINALG_INT n, scalar_t *A_data, OPEN3D_CPU_LINALG_INT lda, OPEN3D_CPU_LINALG_INT *ipiv_data)
Definition: LapackWrapper.h:17
OPEN3D_CPU_LINALG_INT gesvd_cpu< float >(int layout, char jobu, char jobvt, OPEN3D_CPU_LINALG_INT m, OPEN3D_CPU_LINALG_INT n, float *A_data, OPEN3D_CPU_LINALG_INT lda, float *S_data, float *U_data, OPEN3D_CPU_LINALG_INT ldu, float *VT_data, OPEN3D_CPU_LINALG_INT ldvt, float *superb)
Definition: LapackWrapper.h:175
OPEN3D_CPU_LINALG_INT gesvd_cpu(int matrix_layout, char jobu, char jobvt, OPEN3D_CPU_LINALG_INT m, OPEN3D_CPU_LINALG_INT n, scalar_t *A_data, OPEN3D_CPU_LINALG_INT lda, scalar_t *S_data, scalar_t *U_data, OPEN3D_CPU_LINALG_INT ldu, scalar_t *VT_data, OPEN3D_CPU_LINALG_INT ldvt, scalar_t *superb)
Definition: LapackWrapper.h:65
OPEN3D_CPU_LINALG_INT getri_cpu< double >(int layout, OPEN3D_CPU_LINALG_INT n, double *A_data, OPEN3D_CPU_LINALG_INT lda, OPEN3D_CPU_LINALG_INT *ipiv_data)
Definition: LapackWrapper.h:115
OPEN3D_CPU_LINALG_INT gesv_cpu< float >(int layout, OPEN3D_CPU_LINALG_INT n, OPEN3D_CPU_LINALG_INT m, float *A_data, OPEN3D_CPU_LINALG_INT lda, OPEN3D_CPU_LINALG_INT *ipiv_data, float *B_data, OPEN3D_CPU_LINALG_INT ldb)
Definition: LapackWrapper.h:125
OPEN3D_CPU_LINALG_INT gesv_cpu(int layout, OPEN3D_CPU_LINALG_INT n, OPEN3D_CPU_LINALG_INT m, scalar_t *A_data, OPEN3D_CPU_LINALG_INT lda, OPEN3D_CPU_LINALG_INT *ipiv_data, scalar_t *B_data, OPEN3D_CPU_LINALG_INT ldb)
Definition: LapackWrapper.h:38
OPEN3D_CPU_LINALG_INT getrf_cpu< float >(int layout, OPEN3D_CPU_LINALG_INT m, OPEN3D_CPU_LINALG_INT n, float *A_data, OPEN3D_CPU_LINALG_INT lda, OPEN3D_CPU_LINALG_INT *ipiv_data)
Definition: LapackWrapper.h:83
Definition: PinholeCameraIntrinsic.cpp:16