numerics
Loading...
Searching...
No Matches
matrix.cpp
Go to the documentation of this file.
1/// @file core/backends/gpu/matrix.cpp
2/// @brief GPU (CUDA) backend -- matrix operations
3///
4/// Thin shims that forward to cuda:: kernels (cuda_ops.hpp).
5/// Falls back to sequential when NUMERICS_HAS_CUDA is not defined.
6
7#include "core/matrix.hpp"
9#include "../seq/impl.hpp"
10
11namespace num::backends::gpu {
12
13void matmul(const Matrix& A, const Matrix& B, Matrix& C) {
14#ifdef NUMERICS_HAS_CUDA
15 cuda::matmul(A.gpu_data(), B.gpu_data(), C.gpu_data(),
16 A.rows(), A.cols(), B.cols());
17#else
19#endif
20}
21
22void matvec(const Matrix& A, const Vector& x, Vector& y) {
23#ifdef NUMERICS_HAS_CUDA
24 cuda::matvec(A.gpu_data(), x.gpu_data(), y.gpu_data(),
25 A.rows(), A.cols());
26#else
28#endif
29}
30
31} // namespace num::backends::gpu
real * gpu_data()
Definition vector.hpp:111
Dense row-major matrix with optional GPU storage.
Definition matrix.hpp:12
CUDA kernel wrappers.
Matrix operations.
void matmul(const Matrix &A, const Matrix &B, Matrix &C)
Definition matrix.cpp:13
void matvec(const Matrix &A, const Vector &x, Vector &y)
Definition matrix.cpp:22
void matmul(const Matrix &A, const Matrix &B, Matrix &C)
Definition matrix.cpp:14
void matvec(const Matrix &A, const Vector &x, Vector &y)
Definition matrix.cpp:24
void matmul(const real *A, const real *B, real *C, idx m, idx k, idx n)
C = A * B.
void matvec(const real *A, const real *x, real *y, idx rows, idx cols)
y = A * x (row-major A)
constexpr T ipow(T x) noexcept
Compute x^N at compile time via repeated squaring.