ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
SVDSYCL.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #include <sycl/sycl.hpp>
9 
10 #include "cloudViewer/core/Blob.h"
14 #include "oneapi/mkl.hpp"
15 
16 namespace cloudViewer {
17 namespace core {
18 
19 void SVDSYCL(const void* A_data,
20  void* U_data,
21  void* S_data,
22  void* VT_data,
23  int64_t m,
24  int64_t n,
25  Dtype dtype,
26  const Device& device) {
27  using namespace oneapi::mkl;
28  sycl::queue queue = sy::SYCLContext::GetInstance().GetDefaultQueue(device);
30  int64_t lda = m, ldvt = n, ldu = m;
31  int64_t scratchpad_size = lapack::gesvd_scratchpad_size<scalar_t>(
32  queue, jobsvd::vectors, jobsvd::vectors, m, n, lda, ldu, ldvt);
33  // Use blob to ensure cleanup of scratchpad memory.
34  Blob scratchpad(scratchpad_size * sizeof(scalar_t), device);
35  lapack::gesvd(
36  queue, jobsvd::vectors, jobsvd::vectors, m, n,
37  const_cast<scalar_t*>(static_cast<const scalar_t*>(A_data)),
38  lda, static_cast<scalar_t*>(S_data),
39  static_cast<scalar_t*>(U_data), ldu,
40  static_cast<scalar_t*>(VT_data), ldvt,
41  static_cast<scalar_t*>(scratchpad.GetDataPtr()),
42  scratchpad_size)
43  .wait_and_throw();
44  });
45 }
46 
47 } // namespace core
48 } // namespace cloudViewer
#define DISPATCH_LINALG_DTYPE_TO_TEMPLATE(DTYPE,...)
Definition: LinalgUtils.h:23
SYCL queue manager.
void * GetDataPtr()
Definition: Blob.h:75
static SYCLContext & GetInstance()
Get singleton instance.
Definition: SYCLContext.cpp:25
sycl::queue GetDefaultQueue(const Device &device)
Get the default SYCL queue given an CloudViewer device.
Definition: SYCLContext.cpp:43
void SVDSYCL(const void *A_data, void *U_data, void *S_data, void *VT_data, int64_t m, int64_t n, Dtype dtype, const Device &device)
Definition: SVDSYCL.cpp:19
Generic file read and write utility for python interface.