numerics
Loading...
Searching...
No Matches
vector.cpp
Go to the documentation of this file.
1/// @file core/backends/gpu/vector.cpp
2/// @brief GPU (CUDA) backend -- vector 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/vector.hpp"
9#include "../seq/impl.hpp"
10#include <cmath>
11
12namespace num::backends::gpu {
13
15#ifdef NUMERICS_HAS_CUDA
16 cuda::scale(v.gpu_data(), v.size(), alpha);
17#else
19#endif
20}
21
22void axpy(real alpha, const Vector& x, Vector& y) {
23#ifdef NUMERICS_HAS_CUDA
24 cuda::axpy(alpha, x.gpu_data(), y.gpu_data(), x.size());
25#else
27#endif
28}
29
30real dot(const Vector& x, const Vector& y) {
31#ifdef NUMERICS_HAS_CUDA
32 return cuda::dot(x.gpu_data(), y.gpu_data(), x.size());
33#else
34 return num::backends::seq::dot(x, y);
35#endif
36}
37
38real norm(const Vector& x) {
39#ifdef NUMERICS_HAS_CUDA
40 real d = cuda::dot(x.gpu_data(), x.gpu_data(), x.size());
41 return std::sqrt(d);
42#else
44#endif
45}
46
47} // namespace num::backends::gpu
real * gpu_data()
Definition vector.hpp:111
constexpr idx size() const noexcept
Definition vector.hpp:77
CUDA kernel wrappers.
void axpy(real alpha, const Vector &x, Vector &y)
Definition vector.cpp:22
real dot(const Vector &x, const Vector &y)
Definition vector.cpp:30
real norm(const Vector &x)
Definition vector.cpp:38
void scale(Vector &v, real alpha)
Definition vector.cpp:14
real dot(const Vector &x, const Vector &y)
Definition vector.cpp:21
void scale(Vector &v, real alpha)
Definition vector.cpp:9
real norm(const Vector &x)
Definition vector.cpp:27
void axpy(real alpha, const Vector &x, Vector &y)
Definition vector.cpp:17
void scale(real *v, idx n, real alpha)
v = alpha * v
void axpy(real alpha, const real *x, real *y, idx n)
y = alpha*x + y
real dot(const real *x, const real *y, idx n)
dot product
double real
Definition types.hpp:10
constexpr T ipow(T x) noexcept
Compute x^N at compile time via repeated squaring.
Vector operations.