| 68 | } |
| 69 | |
| 70 | void InitCuLinalg() |
| 71 | { |
| 72 | cout << "Initializing cublas and cusparse." << endl; |
| 73 | |
| 74 | Get_CuBlas_Handle(); |
| 75 | Get_CuSparse_Handle(); |
| 76 | |
| 77 | cusparseSetStream(Get_CuSparse_Handle(), ngs_cuda::ngs_cuda_stream); |
| 78 | std::cerr << "[InitCuLinalg] cusparseSetStream bound to ngs_cuda_stream" << std::endl; |
| 79 | |
| 80 | ngs_cuda::CudaGraph::stream_change_callback = [](cudaStream_t s) { |
| 81 | cusparseSetStream(Get_CuSparse_Handle(), s); |
| 82 | }; |
| 83 | |
| 84 | std::cerr << "[InitCuLinalg] callback wired, registering creators..." << std::endl; |
| 85 | BaseVector::RegisterDeviceVectorCreator(typeid(S_BaseVectorPtr<double>), |
| 86 | [] (const BaseVector & vec, bool unified) -> shared_ptr<BaseVector> |
| 87 | { |
| 88 | return make_shared<UnifiedVector>(vec); |
| 89 | }); |
| 90 | BaseVector::RegisterDeviceVectorCreator(typeid(VVector<double>), |
| 91 | [] (const BaseVector & vec, bool unified) -> shared_ptr<BaseVector> |
| 92 | { |
| 93 | return make_shared<UnifiedVector>(vec); |
| 94 | }); |
| 95 | |
| 96 | BaseMatrix::RegisterDeviceMatrixCreator(typeid(SparseMatrix<double>), |
| 97 | [] (const BaseMatrix & mat) -> shared_ptr<BaseMatrix> |
| 98 | { |
| 99 | auto & sparse_mat = dynamic_cast<const SparseMatrix<double>&>(mat); |
| 100 | return make_shared<DevSparseMatrix>(sparse_mat); |
| 101 | }); |
| 102 | |
| 103 | BaseMatrix::RegisterDeviceMatrixCreator(typeid(JacobiPrecond<double>), |
| 104 | [] (const BaseMatrix & mat) -> shared_ptr<BaseMatrix> |
| 105 | { |
| 106 | auto & Jacobimat = dynamic_cast<const JacobiPrecond<double>&>(mat); |
| 107 | auto diagarray = Jacobimat.GetInverse(); |
| 108 | |
| 109 | VVector<double> diag(diagarray.Size()); |
| 110 | auto fv = diag.FVDouble(); |
| 111 | for (size_t i = 0; i < fv.Size(); i++) |
| 112 | fv[i] = diagarray[i]; |
| 113 | |
| 114 | return make_shared<DevDiagonalMatrix>(diag); |
| 115 | }); |
| 116 | |
| 117 | BaseMatrix::RegisterDeviceMatrixCreator(typeid(DiagonalMatrix<double>), |
| 118 | [] (const BaseMatrix & mat) -> shared_ptr<BaseMatrix> |
| 119 | { |
| 120 | auto & diagmat = dynamic_cast<const DiagonalMatrix<double>&>(mat); |
| 121 | |
| 122 | return make_shared<DevDiagonalMatrix>(diagmat.AsVector()); |
| 123 | }); |
| 124 | |
| 125 | BaseMatrix::RegisterDeviceMatrixCreator(typeid(T_ConstEBEMatrix), |
| 126 | [] (const BaseMatrix & mat) -> shared_ptr<BaseMatrix> |
| 127 | { |
no test coverage detected