Loading...
Searching...
No Matches
init.hpp
Go to the documentation of this file.
1#pragma once
2
3/**
4 * GPUDeviceBackend — abstract interface for GPU device management.
5 *
6 * Provides device lifecycle, unified memory allocation/deallocation,
7 * and synchronization. Has no knowledge of BLAS, FFT, or any math
8 * library — those wrappers own their own vendor handles.
9 *
10 * No CUDA headers. No Metal headers. Vendor-specific implementations
11 * live in cuda.hpp/cuda.cpp and metal.hpp/metal.cpp.
12 */
13
14#include <cstddef>
15#include <string>
16
17namespace q3 {
18namespace execution {
19namespace gpu {
20namespace device {
21
23 public:
24 virtual ~GPUDeviceBackend() = default;
25
26 /**
27 * Human-readable name of the GPU device (e.g., "Apple M2 Max", "NVIDIA A100").
28 */
29 virtual std::string device_name() const = 0;
30
31 /**
32 * Total device memory in bytes.
33 */
34 virtual size_t total_memory_bytes() const = 0;
35
36 /**
37 * Whether the device supports native double precision (FP64) computation.
38 *
39 * Returns false for Apple Silicon (Metal has no FP64 compute shaders).
40 * Returns true for CUDA GPUs (all supported compute capabilities).
41 */
42 virtual bool supports_double_precision() const = 0;
43
44 /**
45 * Allocate unified (managed) memory accessible from both host and device.
46 *
47 * On CUDA, this maps to cudaMallocManaged(). On Metal, this maps to
48 * MTLDevice::newBuffer() with MTLResourceStorageModeShared.
49 *
50 * The returned memory is NOT zero-initialized.
51 *
52 * @param size_bytes Number of bytes to allocate.
53 * @return Pointer to the allocated memory.
54 * @throws std::runtime_error If allocation fails.
55 */
56 virtual void* allocate_unified(size_t size_bytes) = 0;
57
58 /**
59 * Deallocate memory previously allocated via allocate_unified().
60 *
61 * @param pointer Pointer returned by allocate_unified(). Must not be null.
62 */
63 virtual void deallocate(void* pointer) = 0;
64
65 /**
66 * Block until all pending GPU operations have completed.
67 *
68 * Must be called before reading GPU-produced results on the host,
69 * and before precision casts or MPI collectives.
70 */
71 virtual void synchronize() = 0;
72};
73
74} // namespace device
75} // namespace gpu
76} // namespace execution
77} // namespace q3
virtual bool supports_double_precision() const =0
virtual size_t total_memory_bytes() const =0
virtual void deallocate(void *pointer)=0
virtual void * allocate_unified(size_t size_bytes)=0
virtual std::string device_name() const =0