ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
InverseSYCL.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 InverseSYCL(void* A_data,
20  void* ipiv_data,
21  void* output_data,
22  int64_t n,
23  Dtype dtype,
24  const Device& device) {
25  using namespace oneapi::mkl;
26  sycl::queue queue = sy::SYCLContext::GetInstance().GetDefaultQueue(device);
27  int64_t lda = n;
29  // Use blob to ensure cleanup of scratchpad memory.
30  int64_t scratchpad_size = std::max(
31  lapack::getrf_scratchpad_size<scalar_t>(queue, n, n, lda),
32  lapack::getri_scratchpad_size<scalar_t>(queue, n, lda));
33  core::Blob scratchpad(scratchpad_size * sizeof(scalar_t), device);
34  auto lu_done =
35  lapack::getrf(queue, n, n, static_cast<scalar_t*>(A_data), lda,
36  static_cast<int64_t*>(ipiv_data),
37  static_cast<scalar_t*>(scratchpad.GetDataPtr()),
38  scratchpad_size);
39  lapack::getri(queue, n, static_cast<scalar_t*>(A_data), lda,
40  static_cast<int64_t*>(ipiv_data),
41  static_cast<scalar_t*>(scratchpad.GetDataPtr()),
42  scratchpad_size, {lu_done})
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
int max(int a, int b)
Definition: cutil_math.h:48
void InverseSYCL(void *A_data, void *ipiv_data, void *output_data, int64_t n, Dtype dtype, const Device &device)
Definition: InverseSYCL.cpp:19
Generic file read and write utility for python interface.