ViennaLS
Loading...
Searching...
No Matches
lsOxidationBiCGSTABInterface.hpp
Go to the documentation of this file.
1// C++ (g++) interface to the GPU BiCGSTAB solver.
2//
3// This header is safe to include from any .cpp file compiled by g++.
4// It only forward-declares GpuBiCGSTABBuffers (opaque handle) and
5// declares free functions that are implemented in
6// ViennaLS_GPU (lsOxidationBiCGSTABKernels.cu, compiled by nvcc).
7//
8// The actual CUDA kernels live in lsOxidationBiCGSTAB.cuh. That file
9// must never be included from a .cpp compiled by g++ — only from .cu files.
10
11#pragma once
12
13#ifdef VIENNALS_GPU_BICGSTAB
14
15#include <cstddef>
16#include <cstdint>
17
18namespace viennals {
19namespace gpu {
20
21// Sentinel value used in the neighbor-ID array to mark boundary / out-of-bounds
22// faces (must match the constant in lsOxidationBiCGSTAB.cuh).
23static constexpr uint32_t kNoNode = 0xFFFFFFFFu;
24
25// Opaque handle — complete definition is in lsOxidationBiCGSTAB.cuh /
26// lsOxidationBiCGSTABKernels.cu. Consumers hold a raw pointer only.
27struct GpuBiCGSTABBuffers;
28
29// Allocate GPU buffers for a solver with `n` nodes and `nFaces` (2*D) faces.
30// Returns nullptr if CUDA is unavailable.
31GpuBiCGSTABBuffers *allocGpuBuffers(uint32_t n, int nFaces,
32 bool useIlu0Preconditioner);
33
34// Free previously allocated GPU buffers. Safe to call with nullptr.
35void freeGpuBuffers(GpuBiCGSTABBuffers *gpu);
36
37// Human-readable detail for the last GPU wrapper failure on this thread.
38const char *gpuGetLastErrorMessage();
39
40// Is the buffer handle valid (non-null and successfully allocated)?
41bool gpuIsValid(const GpuBiCGSTABBuffers *gpu);
42
43// Upload geometry-fixed neighbor-ID array (face-major, kNoNode = 0xFFFFFFFF).
44// `count` must equal nFaces * n.
45bool gpuUploadNeighborIds(GpuBiCGSTABBuffers *gpu, const uint32_t *nb,
46 std::size_t count);
47
48// Build the CSR sparsity pattern from h_nb (face-major, length nFaces*n),
49// upload to the device, and run CUSPARSE symbolic analysis for ILU(0) and
50// the two triangular solves. Must be called after gpuUploadNeighborIds and
51// before the first gpuUploadSolverArrays / gpuSolveBiCGSTAB call.
52bool gpuSetupCSR(GpuBiCGSTABBuffers *gpu, const uint32_t *h_nb, uint32_t n,
53 int nFaces);
54
55// Upload per-solve arrays (diag, b, faceCoeffs) and re-factorize ILU(0).
56// `diagLen` == n, `coeffLen` == nFaces * n.
57bool gpuUploadSolverArrays(GpuBiCGSTABBuffers *gpu, const double *diag,
58 const double *b, const double *coeff,
59 uint32_t diagLen, std::size_t coeffLen);
60
61// Upload only the RHS vector (d_b). Use when the matrix geometry is already
62// uploaded and only the right-hand side changes (e.g. successive Stokes
63// component solves that share the same stiffness matrix).
64bool gpuUploadRhs(GpuBiCGSTABBuffers *gpu, const double *b, uint32_t n);
65
66// Run GPU BiCGSTAB.
67// x (length n, host): initial guess on entry, solution on exit.
68// outResidual is the raw (unnormalized) max-abs residual on exit.
69// Returns true only when the GPU solve converged and produced finite values.
70bool gpuSolveBiCGSTAB(GpuBiCGSTABBuffers *gpu, double *x, double diagEps,
71 unsigned maxIter, double tolerance,
72 unsigned &outIterations, double &outResidual);
73
74} // namespace gpu
75} // namespace viennals
76
77#endif // VIENNALS_GPU_BICGSTAB
Definition lsAdvect.hpp:41