Loading...
Searching...
No Matches
init.hpp
Go to the documentation of this file.
1#pragma once
2
3/**
4 * GPUExecutionPolicy — GPU implementation of ExecutionPolicy.
5 *
6 * Delegates group-collective vector operations (dot product, norm, axpy) to
7 * GPUBLAS for device-resident data. All pointer arguments must come from
8 * GPUDeviceBuffer (unified memory).
9 *
10 * GPUBLAS is implemented in Phase 1. This file defines the interface and
11 * constructor signature; method bodies will delegate to GPUBLAS once it exists.
12 *
13 * No CUDA headers. No Metal headers. Vendor-neutral.
14 */
15
18
19#include <cstring>
20#include <memory>
21#include <stdexcept>
22
23namespace q3 {
24namespace execution {
25namespace gpu {
26
27/**
28 * Forward declaration — GPUBLAS is defined at:
29 * layer_0_core/math/linear_algebra/gpu/blas/init.hpp
30 */
31namespace blas {
32class GPUBLAS;
33} // namespace blas
34
35class GPUExecutionPolicy : public virtual ExecutionPolicy {
36 public:
37 /**
38 * Construct a GPU execution policy.
39 *
40 * @param device_backend Shared pointer to the GPU device backend.
41 * Must not be null.
42 */
43 explicit GPUExecutionPolicy(std::shared_ptr<device::GPUDeviceBackend> device_backend)
44 : device_backend_(std::move(device_backend)) {
45 if (!device_backend_) {
46 throw std::runtime_error("GPUExecutionPolicy: device_backend must not be null");
47 }
48 }
49
50 /**
51 * Compute the inner product x† · y on GPU-resident data.
52 *
53 * Intentionally unwired: the GPU compute paths (hamiltonian applicator,
54 * subspace manager) call GPUBLAS directly on device buffers instead of
55 * going through this generic policy interface. Throws if reached.
56 */
57 ComplexValue dot_product(int number_of_elements,
58 const ComplexValue* vector_x,
59 const ComplexValue* vector_y) const override {
60 (void)number_of_elements;
61 (void)vector_x;
62 (void)vector_y;
63 throw std::runtime_error("GPUExecutionPolicy::dot_product is not wired — GPU compute "
64 "paths use GPUBLAS directly on device buffers");
65 }
66
67 /**
68 * Scaled vector addition on GPU-resident data: vector_y += scaling_factor * vector_x.
69 *
70 * Intentionally unwired: the GPU compute paths call GPUBLAS directly on
71 * device buffers instead of going through this generic policy interface.
72 * Throws if reached.
73 */
74 void add_scaled_vector(int number_of_elements,
75 ComplexValue scaling_factor,
76 const ComplexValue* vector_x,
77 ComplexValue* vector_y) const override {
78 (void)number_of_elements;
79 (void)scaling_factor;
80 (void)vector_x;
81 (void)vector_y;
82 throw std::runtime_error("GPUExecutionPolicy::add_scaled_vector is not wired — GPU "
83 "compute paths use GPUBLAS directly on device buffers");
84 }
85
86 /**
87 * Euclidean norm on GPU-resident data.
88 *
89 * Intentionally unwired: the GPU compute paths call GPUBLAS directly on
90 * device buffers instead of going through this generic policy interface.
91 * Throws if reached.
92 */
93 Real norm(int number_of_elements, const ComplexValue* vector_x) const override {
94 (void)number_of_elements;
95 (void)vector_x;
96 throw std::runtime_error("GPUExecutionPolicy::norm is not wired — GPU compute "
97 "paths use GPUBLAS directly on device buffers");
98 }
99
100 /**
101 * GPU execution is always single-process (no MPI in this policy).
102 */
103 bool is_root() const override {
104 return true;
105 }
106
107 int group_rank_index() const override {
108 return 0;
109 }
110
111 int group_size() const override {
112 return 1;
113 }
114
115 int number_of_processes() const override {
116 return 1;
117 }
118
119 int global_number_of_elements(int local_number_of_elements) const override {
120 return local_number_of_elements;
121 }
122
123 void reduce_within_group(ComplexValue* /*data*/, int /*number_of_elements*/) const override {}
124
125 void reduce_within_group(Real* /*data*/, int /*number_of_elements*/) const override {}
126
127 void allgather_within_group(const Real* local_data,
128 int local_count,
129 Real* full_data,
130 int /*total_count*/) const override {
131 std::memcpy(full_data, local_data, local_count * sizeof(Real));
132 }
133
134 /**
135 * Access the underlying GPU device backend.
136 */
138 return *device_backend_;
139 }
140
141 protected:
142 std::shared_ptr<device::GPUDeviceBackend> device_backend_;
143};
144
145} // namespace gpu
146} // namespace execution
147} // namespace q3
const device::GPUDeviceBackend & device_backend() const
Definition init.hpp:137
void add_scaled_vector(int number_of_elements, ComplexValue scaling_factor, const ComplexValue *vector_x, ComplexValue *vector_y) const override
Definition init.hpp:74
int group_rank_index() const override
Definition init.hpp:107
bool is_root() const override
Definition init.hpp:103
void reduce_within_group(Real *, int) const override
Definition init.hpp:125
int group_size() const override
Definition init.hpp:111
int number_of_processes() const override
Definition init.hpp:115
void allgather_within_group(const Real *local_data, int local_count, Real *full_data, int) const override
Definition init.hpp:127
ComplexValue dot_product(int number_of_elements, const ComplexValue *vector_x, const ComplexValue *vector_y) const override
Definition init.hpp:57
Real norm(int number_of_elements, const ComplexValue *vector_x) const override
Definition init.hpp:93
void reduce_within_group(ComplexValue *, int) const override
Definition init.hpp:123
int global_number_of_elements(int local_number_of_elements) const override
Definition init.hpp:119
std::shared_ptr< device::GPUDeviceBackend > device_backend_
Definition init.hpp:142
GPUExecutionPolicy(std::shared_ptr< device::GPUDeviceBackend > device_backend)
Definition init.hpp:43
double Real