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"
8#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(), A.rows(), A.cols(), B.cols());
16#else
18#endif
19}
20
21void matvec(const Matrix& A, const Vector& x, Vector& y) {
22#ifdef NUMERICS_HAS_CUDA
23 cuda::matvec(A.gpu_data(), x.gpu_data(), y.gpu_data(), A.rows(), A.cols());
24#else
26#endif
27}
28
29} // namespace num::backends::gpu
constexpr idx rows() const noexcept
Definition matrix.hpp:87
constexpr idx cols() const noexcept
Definition matrix.hpp:88
real * gpu_data()
Definition vector.hpp:118
CUDA kernel wrappers.
Dense row-major matrix templated over scalar type T.
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:21
void matmul(const Matrix &A, const Matrix &B, Matrix &C)
Definition matrix.cpp:10
void matvec(const Matrix &A, const Vector &x, Vector &y)
Definition matrix.cpp:20
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)