MCPcopy Create free account
hub / github.com/ComputationalRobotics/XM-code / DnChol

Function DnChol

XM/include/Solver/densechol.h:10–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8// chol
9template <typename T>
10inline void DnChol(DeviceSolverDnHandle& cusloverdn_handle, DeviceDnTen<T>& A){
11 cusolverDnParams_t params = NULL;
12 size_s M = A.dimensions[0];
13 CHECK_CUSOLVER(cusolverDnCreateParams(&params));
14 size_t workspaceInBytesOnDevice = 0; /* size of workspace */
15 void *d_work = nullptr; /* device workspace */
16 size_t workspaceInBytesOnHost = 0; /* size of workspace */
17 void *h_work = nullptr; /* host workspace */
18
19 // upper is the same as MATLAB DEFAULT
20 // TODO: traits<T>::cuda_data_type is same as what I write in concept.h
21 // allocate workspace
22 CHECK_CUSOLVER(cusolverDnXpotrf_bufferSize(
23 cusloverdn_handle.cusolver_dn_handle, params, CUBLAS_FILL_MODE_UPPER, M, CudaTypeMapper<T>::value, A.vals, M,
24 CudaTypeMapper<T>::value, &workspaceInBytesOnDevice, &workspaceInBytesOnHost));
25
26 CHECK_CUDA(cudaMalloc(reinterpret_cast<void **>(&d_work), workspaceInBytesOnDevice));
27
28 if (0 < workspaceInBytesOnHost) {
29 h_work = reinterpret_cast<void *>(malloc(workspaceInBytesOnHost));
30 if (h_work == nullptr) {
31 throw std::runtime_error("Error: h_work not allocated.");
32 }
33 }
34
35 // Cholesky factorization
36 int *d_info = nullptr; /* error info */
37 CHECK_CUDA(cudaMalloc(reinterpret_cast<void **>(&d_info), sizeof(int)));
38 CHECK_CUSOLVER(cusolverDnXpotrf(
39 cusloverdn_handle.cusolver_dn_handle, params, CUBLAS_FILL_MODE_UPPER, M, CudaTypeMapper<T>::value, A.vals, M,
40 CudaTypeMapper<T>::value, d_work, workspaceInBytesOnDevice, h_work, workspaceInBytesOnHost, d_info));
41
42 // check error
43 int info = 0;
44 CHECK_CUDA(cudaMemcpyAsync(&info, d_info, sizeof(int), cudaMemcpyDeviceToHost));
45 if (0 > info) {
46 std::printf("%d-th parameter is wrong \n", -info);
47 }
48 else{
49 std::printf("Success in DN chol! \n");
50 }
51 CHECK_CUDA(cudaDeviceSynchronize());
52
53}
54
55#endif // DENSECHOL_H

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected