1// ExecutionPlan / Device / PrecisionPolicy — how and where a computation runs.2#pragma once3#include <string>4#include <vector>5#include <nlohmann/json.hpp>6#include "raid/core/types.hpp"78namespace raid {910struct Device {11 std::string name;12 Backend kind{Backend::cpu};13 u64 memory_bytes{0};14 int compute_units{0}; // CPU cores or GPU cores (if known)15 bool unified_memory{true};16 bool supports_fp64{true}; // false for every Apple GPU (verified 2026-11-02)17 u64 max_buffer_bytes{0};18 std::string details;19 nlohmann::json to_json() const;20};2122struct PrecisionPolicy {23 Precision requested{Precision::fp64};24 /// Maximum reduction length accumulated in FP32 on the GPU before a FP64 CPU combine step.25 usize fp32_chunk_max{4096};26 /// Use compensated (Neumaier) accumulation on GPU partial sums.27 bool compensated{true};28 /// Tolerance (relative) used by auto validation of GPU vs CPU reference.29 f64 validate_rtol{1e-5};30 nlohmann::json to_json() const;31};3233struct ExecutionPlan {34 Backend backend{Backend::automatic};35 PrecisionPolicy precision{};36 bool deterministic{true}; // fixed-order reductions (bitwise reproducible across runs on the same device)37 unsigned threads{0}; // 0 = all38 usize chunk_rows{0}; // 0 = automatic39 u64 max_memory_bytes{0}; // 0 = no explicit bound (device-reported limits still apply)40 bool allow_fallback{true}; // Metal unsupported → CPU41 u64 seed{20261102};42 nlohmann::json to_json() const;43};4445} // namespace raid46