Open3D (C++ API)  0.12.0
LapackWrapper.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2018 www.open3d.org
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 // ----------------------------------------------------------------------------
26 
27 #pragma once
28 
31 #include "open3d/utility/Console.h"
32 
33 namespace open3d {
34 namespace core {
35 template <typename scalar_t>
36 inline OPEN3D_CPU_LINALG_INT getrf_cpu(int layout,
39  scalar_t* A_data,
41  OPEN3D_CPU_LINALG_INT* ipiv_data) {
42  utility::LogError("Unsupported data type.");
43  return -1;
44 }
45 
46 template <typename scalar_t>
47 inline OPEN3D_CPU_LINALG_INT getri_cpu(int layout,
49  scalar_t* A_data,
51  OPEN3D_CPU_LINALG_INT* ipiv_data) {
52  utility::LogError("Unsupported data type.");
53  return -1;
54 }
55 
56 template <typename scalar_t>
57 inline OPEN3D_CPU_LINALG_INT gesv_cpu(int layout,
60  scalar_t* A_data,
62  OPEN3D_CPU_LINALG_INT* ipiv_data,
63  scalar_t* B_data,
65  utility::LogError("Unsupported data type.");
66  return -1;
67 }
68 
69 template <typename scalar_t>
70 inline OPEN3D_CPU_LINALG_INT gels_cpu(int matrix_layout,
71  char trans,
75  scalar_t* A_data,
77  scalar_t* B_data,
79  utility::LogError("Unsupported data type.");
80  return -1;
81 }
82 
83 template <typename scalar_t>
84 inline OPEN3D_CPU_LINALG_INT gesvd_cpu(int matrix_layout,
85  char jobu,
86  char jobvt,
89  scalar_t* A_data,
91  scalar_t* S_data,
92  scalar_t* U_data,
94  scalar_t* VT_data,
96  scalar_t* superb) {
97  utility::LogError("Unsupported data type.");
98  return -1;
99 }
100 
101 template <>
103  int layout,
106  float* A_data,
108  OPEN3D_CPU_LINALG_INT* ipiv_data) {
109  return LAPACKE_sgetrf(layout, m, n, A_data, lda, ipiv_data);
110 }
111 template <>
113  int layout,
116  double* A_data,
118  OPEN3D_CPU_LINALG_INT* ipiv_data) {
119  return LAPACKE_dgetrf(layout, m, n, A_data, lda, ipiv_data);
120 }
121 
122 template <>
124  int layout,
126  float* A_data,
128  OPEN3D_CPU_LINALG_INT* ipiv_data) {
129  return LAPACKE_sgetri(layout, n, A_data, lda, ipiv_data);
130 }
131 
132 template <>
134  int layout,
136  double* A_data,
138  OPEN3D_CPU_LINALG_INT* ipiv_data) {
139  return LAPACKE_dgetri(layout, n, A_data, lda, ipiv_data);
140 }
141 
142 template <>
146  float* A_data,
148  OPEN3D_CPU_LINALG_INT* ipiv_data,
149  float* B_data,
150  OPEN3D_CPU_LINALG_INT ldb) {
151  return LAPACKE_sgesv(layout, n, m, A_data, lda, ipiv_data, B_data, ldb);
152 }
153 
154 template <>
158  double* A_data,
160  OPEN3D_CPU_LINALG_INT* ipiv_data,
161  double* B_data,
162  OPEN3D_CPU_LINALG_INT ldb) {
163  return LAPACKE_dgesv(layout, n, m, A_data, lda, ipiv_data, B_data, ldb);
164 }
165 
166 template <>
168  char trans,
172  float* A_data,
174  float* B_data,
175  OPEN3D_CPU_LINALG_INT ldb) {
176  return LAPACKE_sgels(layout, trans, m, n, nrhs, A_data, lda, B_data, ldb);
177 }
178 
179 template <>
181  char trans,
185  double* A_data,
187  double* B_data,
188  OPEN3D_CPU_LINALG_INT ldb) {
189  return LAPACKE_dgels(layout, trans, m, n, nrhs, A_data, lda, B_data, ldb);
190 }
191 
192 template <>
194  char jobu,
195  char jobvt,
198  float* A_data,
200  float* S_data,
201  float* U_data,
203  float* VT_data,
205  float* superb) {
206  return LAPACKE_sgesvd(layout, jobu, jobvt, m, n, A_data, lda, S_data,
207  U_data, ldu, VT_data, ldvt, superb);
208 }
209 
210 template <>
212  char jobu,
213  char jobvt,
216  double* A_data,
218  double* S_data,
219  double* U_data,
221  double* VT_data,
223  double* superb) {
224  return LAPACKE_dgesvd(layout, jobu, jobvt, m, n, A_data, lda, S_data,
225  U_data, ldu, VT_data, ldvt, superb);
226 }
227 
228 #ifdef BUILD_CUDA_MODULE
229 template <typename scalar_t>
230 inline cusolverStatus_t getrf_cuda_buffersize(
231  cusolverDnHandle_t handle, int m, int n, int lda, int* len) {
232  utility::LogError("Unsupported data type.");
233  return CUSOLVER_STATUS_INTERNAL_ERROR;
234 }
235 
236 template <typename scalar_t>
237 inline cusolverStatus_t getrf_cuda(cusolverDnHandle_t handle,
238  int m,
239  int n,
240  scalar_t* A_data,
241  int lda,
242  scalar_t* workspace,
243  int* ipiv_data,
244  int* dinfo) {
245  utility::LogError("Unsupported data type.");
246  return CUSOLVER_STATUS_INTERNAL_ERROR;
247 }
248 
249 template <typename scalar_t>
250 inline cusolverStatus_t getrs_cuda(cusolverDnHandle_t handle,
251  cublasOperation_t trans,
252  int n,
253  int nrhs,
254  const scalar_t* A_data,
255  int lda,
256  const int* ipiv_data,
257  scalar_t* B_data,
258  int ldb,
259  int* dinfo) {
260  utility::LogError("Unsupported data type.");
261  return CUSOLVER_STATUS_INTERNAL_ERROR;
262 }
263 
264 template <typename scalar_t>
265 inline cusolverStatus_t geqrf_cuda_buffersize(
266  cusolverDnHandle_t handle, int m, int n, int lda, int* len) {
267  utility::LogError("Unsupported data type.");
268  return CUSOLVER_STATUS_INTERNAL_ERROR;
269 }
270 
271 template <typename scalar_t>
272 inline cusolverStatus_t geqrf_cuda(cusolverDnHandle_t handle,
273  int m,
274  int n,
275  scalar_t* A,
276  int lda,
277  scalar_t* tau,
278  scalar_t* workspace,
279  int len,
280  int* dinfo) {
281  utility::LogError("Unsupported data type.");
282  return CUSOLVER_STATUS_INTERNAL_ERROR;
283 }
284 
285 template <typename scalar_t>
286 inline cusolverStatus_t ormqr_cuda_buffersize(cusolverDnHandle_t handle,
287  cublasSideMode_t side,
288  cublasOperation_t trans,
289  int m,
290  int n,
291  int k,
292  int lda,
293  int ldc,
294  int* len) {
295  utility::LogError("Unsupported data type.");
296  return CUSOLVER_STATUS_INTERNAL_ERROR;
297 }
298 
299 template <typename scalar_t>
300 inline cusolverStatus_t ormqr_cuda(cusolverDnHandle_t handle,
301  cublasSideMode_t side,
302  cublasOperation_t trans,
303  int m,
304  int n,
305  int k,
306  const scalar_t* A,
307  int lda,
308  const scalar_t* tau,
309  scalar_t* C,
310  int ldc,
311  scalar_t* workspace,
312  int len,
313  int* dinfo) {
314  utility::LogError("Unsupported data type.");
315  return CUSOLVER_STATUS_INTERNAL_ERROR;
316 }
317 
318 template <typename scalar_t>
319 inline cusolverStatus_t gesvd_cuda_buffersize(cusolverDnHandle_t handle,
320  int m,
321  int n,
322  int* len) {
323  utility::LogError("Unsupported data type.");
324  return CUSOLVER_STATUS_INTERNAL_ERROR;
325 }
326 
327 template <typename scalar_t>
328 inline cusolverStatus_t gesvd_cuda(cusolverDnHandle_t handle,
329  char jobu,
330  char jobvt,
331  int m,
332  int n,
333  scalar_t* A,
334  int lda,
335  scalar_t* S,
336  scalar_t* U,
337  int ldu,
338  scalar_t* VT,
339  int ldvt,
340  scalar_t* workspace,
341  int len,
342  scalar_t* rwork,
343  int* dinfo) {
344  utility::LogError("Unsupported data type.");
345  return CUSOLVER_STATUS_INTERNAL_ERROR;
346 }
347 
348 template <>
349 inline cusolverStatus_t getrf_cuda_buffersize<float>(
350  cusolverDnHandle_t handle, int m, int n, int lda, int* len) {
351  return cusolverDnSgetrf_bufferSize(handle, m, n, NULL, lda, len);
352 }
353 
354 template <>
355 inline cusolverStatus_t getrf_cuda_buffersize<double>(
356  cusolverDnHandle_t handle, int m, int n, int lda, int* len) {
357  return cusolverDnDgetrf_bufferSize(handle, m, n, NULL, lda, len);
358 }
359 
360 template <>
361 inline cusolverStatus_t getrf_cuda<float>(cusolverDnHandle_t handle,
362  int m,
363  int n,
364  float* A_data,
365  int lda,
366  float* workspace,
367  int* ipiv_data,
368  int* dinfo) {
369  return cusolverDnSgetrf(handle, m, n, A_data, lda, workspace, ipiv_data,
370  dinfo);
371 }
372 
373 template <>
374 inline cusolverStatus_t getrf_cuda<double>(cusolverDnHandle_t handle,
375  int m,
376  int n,
377  double* A_data,
378  int lda,
379  double* workspace,
380  int* ipiv_data,
381  int* dinfo) {
382  return cusolverDnDgetrf(handle, m, n, A_data, lda, workspace, ipiv_data,
383  dinfo);
384 }
385 
386 template <>
387 inline cusolverStatus_t getrs_cuda<float>(cusolverDnHandle_t handle,
388  cublasOperation_t trans,
389  int n,
390  int nrhs,
391  const float* A_data,
392  int lda,
393  const int* ipiv_data,
394  float* B_data,
395  int ldb,
396  int* dinfo) {
397  return cusolverDnSgetrs(handle, trans, n, nrhs, A_data, lda, ipiv_data,
398  B_data, ldb, dinfo);
399 }
400 
401 template <>
402 inline cusolverStatus_t getrs_cuda<double>(cusolverDnHandle_t handle,
403  cublasOperation_t trans,
404  int n,
405  int nrhs,
406  const double* A_data,
407  int lda,
408  const int* ipiv_data,
409  double* B_data,
410  int ldb,
411  int* dinfo) {
412  return cusolverDnDgetrs(handle, trans, n, nrhs, A_data, lda, ipiv_data,
413  B_data, ldb, dinfo);
414 }
415 
416 template <>
417 inline cusolverStatus_t geqrf_cuda_buffersize<float>(
418  cusolverDnHandle_t handle, int m, int n, int lda, int* len) {
419  return cusolverDnSgeqrf_bufferSize(handle, m, n, NULL, lda, len);
420 }
421 
422 template <>
423 inline cusolverStatus_t geqrf_cuda_buffersize<double>(
424  cusolverDnHandle_t handle, int m, int n, int lda, int* len) {
425  return cusolverDnDgeqrf_bufferSize(handle, m, n, NULL, lda, len);
426 }
427 
428 template <>
429 inline cusolverStatus_t geqrf_cuda<float>(cusolverDnHandle_t handle,
430  int m,
431  int n,
432  float* A,
433  int lda,
434  float* tau,
435  float* workspace,
436  int len,
437  int* dinfo) {
438  return cusolverDnSgeqrf(handle, m, n, A, lda, tau, workspace, len, dinfo);
439 }
440 
441 template <>
442 inline cusolverStatus_t geqrf_cuda<double>(cusolverDnHandle_t handle,
443  int m,
444  int n,
445  double* A,
446  int lda,
447  double* tau,
448  double* workspace,
449  int len,
450  int* dinfo) {
451  return cusolverDnDgeqrf(handle, m, n, A, lda, tau, workspace, len, dinfo);
452 }
453 
454 template <>
455 inline cusolverStatus_t ormqr_cuda_buffersize<float>(cusolverDnHandle_t handle,
456  cublasSideMode_t side,
457  cublasOperation_t trans,
458  int m,
459  int n,
460  int k,
461  int lda,
462  int ldc,
463  int* len) {
464  return cusolverDnSormqr_bufferSize(handle, side, trans, m, n, k, NULL, lda,
465  NULL, NULL, ldc, len);
466 }
467 
468 template <>
469 inline cusolverStatus_t ormqr_cuda_buffersize<double>(cusolverDnHandle_t handle,
470  cublasSideMode_t side,
471  cublasOperation_t trans,
472  int m,
473  int n,
474  int k,
475  int lda,
476  int ldc,
477  int* len) {
478  return cusolverDnDormqr_bufferSize(handle, side, trans, m, n, k, NULL, lda,
479  NULL, NULL, ldc, len);
480 }
481 
482 template <>
483 inline cusolverStatus_t ormqr_cuda<float>(cusolverDnHandle_t handle,
484  cublasSideMode_t side,
485  cublasOperation_t trans,
486  int m,
487  int n,
488  int k,
489  const float* A,
490  int lda,
491  const float* tau,
492  float* C,
493  int ldc,
494  float* workspace,
495  int len,
496  int* dinfo) {
497  return cusolverDnSormqr(handle, side, trans, m, n, k, A, lda, tau, C, ldc,
498  workspace, len, dinfo);
499 }
500 
501 template <>
502 inline cusolverStatus_t ormqr_cuda<double>(cusolverDnHandle_t handle,
503  cublasSideMode_t side,
504  cublasOperation_t trans,
505  int m,
506  int n,
507  int k,
508  const double* A,
509  int lda,
510  const double* tau,
511  double* C,
512  int ldc,
513  double* workspace,
514  int len,
515  int* dinfo) {
516  return cusolverDnDormqr(handle, side, trans, m, n, k, A, lda, tau, C, ldc,
517  workspace, len, dinfo);
518 }
519 
520 template <>
521 inline cusolverStatus_t gesvd_cuda_buffersize<float>(cusolverDnHandle_t handle,
522  int m,
523  int n,
524  int* len) {
525  return cusolverDnSgesvd_bufferSize(handle, m, n, len);
526 }
527 
528 template <>
529 inline cusolverStatus_t gesvd_cuda_buffersize<double>(cusolverDnHandle_t handle,
530  int m,
531  int n,
532  int* len) {
533  return cusolverDnDgesvd_bufferSize(handle, m, n, len);
534 }
535 
536 template <>
537 inline cusolverStatus_t gesvd_cuda<float>(cusolverDnHandle_t handle,
538  char jobu,
539  char jobvt,
540  int m,
541  int n,
542  float* A,
543  int lda,
544  float* S,
545  float* U,
546  int ldu,
547  float* VT,
548  int ldvt,
549  float* workspace,
550  int len,
551  float* rwork,
552  int* dinfo) {
553  return cusolverDnSgesvd(handle, jobu, jobvt, m, n, A, lda, S, U, ldu, VT,
554  ldvt, workspace, len, rwork, dinfo);
555 }
556 
557 template <>
558 inline cusolverStatus_t gesvd_cuda<double>(cusolverDnHandle_t handle,
559  char jobu,
560  char jobvt,
561  int m,
562  int n,
563  double* A,
564  int lda,
565  double* S,
566  double* U,
567  int ldu,
568  double* VT,
569  int ldvt,
570  double* workspace,
571  int len,
572  double* rwork,
573  int* dinfo) {
574  return cusolverDnDgesvd(handle, jobu, jobvt, m, n, A, lda, S, U, ldu, VT,
575  ldvt, workspace, len, rwork, dinfo);
576 }
577 
578 #endif
579 } // namespace core
580 } // namespace open3d
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:102
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:167
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:133
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:112
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:193
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:143
void LogError(const char *format, const Args &... args)
Definition: Console.h:176
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:36
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:180
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:155
Definition: PinholeCameraIntrinsic.cpp:35
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:211
#define OPEN3D_CPU_LINALG_INT
Definition: LinalgHeadersCPU.h:45
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:123
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:84
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:70
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:57
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:47