numerics 0.1.0
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
16 B.gpu_data(),
17 C.gpu_data(),
18 A.rows(),
19 A.cols(),
20 B.cols());
21#else
23#endif
24}
25
26void matvec(const Matrix& A, const Vector& x, Vector& y) {
27#ifdef NUMERICS_HAS_CUDA
28 cuda::matvec(A.gpu_data(), x.gpu_data(), y.gpu_data(), A.rows(), A.cols());
29#else
31#endif
32}
33
34} // namespace num::backends::gpu
real * gpu_data()
Definition vector.hpp:118
Dense row-major matrix with optional GPU storage.
Definition matrix.hpp:12
constexpr idx rows() const noexcept
Definition matrix.hpp:24
real * gpu_data()
Definition matrix.hpp:35
constexpr idx cols() const noexcept
Definition matrix.hpp:25
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:26
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)